-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Add 'selection' option to render whitespace #77533
Conversation
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.
🎉 Nice work! You've done all the right changes, there are 3 things I would change:
- stay away from
undefined
(personal preference) - don't use
Range
because that contains line numbers and create a new class that only contains the data the render line code needs - remove the inner loop in the render whitespace (the one where using
.some(...)
)
Thanks for the great feedback! 👍 I’ve added a |
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.
👍 Really nice! I just found one little bug! Please merge once you cover that!
for (let charIndex = fauxIndentLength; charIndex < len; charIndex++) { | ||
const chCode = lineContent.charCodeAt(charIndex); | ||
|
||
if (currentSelection && charIndex > currentSelection.endOffset) { |
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.
Here the check should be charIndex >= currentSelection.endOffset
. Reverse-engineered steps to observe a bug:
- have some text
*
(<space>
,*
,<space>
). - create 3 multiple cursors before the first space, before the
*
and before the second space. - press shift+right
- the whitespace is not painted in the second
<space>
due to this check.
This case could serve as a good unit test.
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.
Nice catch! I added a test for this
@@ -540,6 +603,11 @@ function _applyRenderWhitespace(lineContent: string, len: number, continuesWithW | |||
isInWhitespace = false; | |||
} | |||
|
|||
// If rendering whitespace on selection, check that the charIndex falls within a selection | |||
if (isInWhitespace && selections) { | |||
isInWhitespace = !!currentSelection && currentSelection.startOffset <= charIndex && currentSelection.endOffset > charIndex; |
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.
nitpick: small style inconsistency, use here currentSelection && ...
instead of !!currentSelection && ...
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.
removing the !!
causes a typescript error since isInWhitespace
should be a boolean, so will leave as is
Found a tiny bug with multi cursor, looks like related to how the selection boundaries are validated
Indentations are all whitespaces. Put a cursor before when the end of the first cursor meets the beginning of the second cursor, the last whitespace is not rendered. |
It's already merged. I'll create a new issue. |
@rebornix Nice find! Seems to be an existing problem unrelated to this change |
#1477
Since whitespace is rendered as part of the line content and not on the selection layer, and since render line already responds to selection changes in some cases, the change I made is to view line rendering. Now, if the setting is on, any selections that are on the line are part of the line data for rendering. When applying whitespace, it checks the selections to see if the whitespace character is part of that range or not.