-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add option for line-wrapping to prevent horizontal scrolling #20
base: main
Are you sure you want to change the base?
Conversation
src/code-view/internal.tsx
Outdated
<td className={styles["line-number"]} aria-hidden={true}> | ||
<Box color="text-status-inactive" fontSize="body-m"> | ||
{index + 1} | ||
</Box> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the markup here breaks selection feature. Line numbers get added into selection.
For the reference you can check how it works on Github
Screen.Recording.2024-02-25.at.16.11.35.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah that's a good catch, thanks. Added some CSS that should fix this.
src/code-view/internal.tsx
Outdated
@@ -2,71 +2,84 @@ | |||
// SPDX-License-Identifier: Apache-2.0 | |||
import { useCurrentMode } from "@cloudscape-design/component-toolkit/internal"; | |||
import Box from "@cloudscape-design/components/box"; | |||
import { TextHighlightRules } from "ace-code/src/mode/text_highlight_rules"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
The original idea of this component to remove ace dependency from the bundle when syntax highlight is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed something to go from string
to ReactElement
for non-highlighted code, for this draft/POC I used the texthighlight rules from Ace for that because it's quick to grab. I can write a simple function within this repo to do the same thing before merging if we decide this approach for line-wrapping looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info. Let's ensure it gets removed at the final stage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it and replaced it with a function defined in the PR.
I'm looking at this PR.
|
I've went ahead and pushed a commit to tackle the initial two. I am looking into the last one now. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 348 381 +33
Branches 31 30 -1
=========================================
+ Hits 348 381 +33 ☔ View full report in Codecov by Sentry. |
I've fixed the code indentation by setting |
<pre | ||
ref={preRef} | ||
<div className={styles["scroll-container"]}> | ||
<table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary for this to be semantically a table? or is this more just to get table layout, in which case could we do that purely with CSS? (thinking about a11y, and whether it makes sense for this to be announced as a "table")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The primary reason for choosing a table here is to align line numbers with their corresponding lines of code, now that we are introducing line-wrapping. Let us consult with A11Y to double-check.
Description
Builds on top of #15.
When using code-view with lines longer than the width of the component, currently horizontal scroll bars are shown. This causes potential accessibility problems:
This adds a
lineWrapping
property to the API which, if set totrue
, makes the component line-wrap long lines to keep them within the view without scrolling.Visual regression tests in the PR actions are failing because this PR makes visual changes.
Related links, issue #, if available: n/a
How has this been tested?
lineWrapping
isfalse
,undefined
ortrue
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.