-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
DOM: Render selection color instead of cell bg #4673
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ export class DomRendererRowFactory { | |
let oldExt = 0; | ||
let oldLinkHover: number | boolean = false; | ||
let oldSpacing = 0; | ||
let oldIsInSelection: boolean = false; | ||
let spacing = 0; | ||
const classes: string[] = []; | ||
|
||
|
@@ -154,16 +155,24 @@ export class DomRendererRowFactory { | |
/** | ||
* chars can only be merged on existing span if: | ||
* - existing span only contains mergeable chars (cellAmount != 0) | ||
* - fg/bg/ul did not change | ||
* - char not part of a selection | ||
* - bg did not change (or both are in selection) | ||
* - fg did not change (or both are in selection and selection fg is set) | ||
* - ext did not change | ||
* - underline from hover state did not change | ||
* - cell content renders to same letter-spacing | ||
* - cell is not cursor | ||
*/ | ||
if ( | ||
cellAmount | ||
&& cell.bg === oldBg && cell.fg === oldFg && cell.extended.ext === oldExt | ||
&& !isInSelection | ||
&& ( | ||
(isInSelection && oldIsInSelection) | ||
|| (!isInSelection && cell.bg === oldBg) | ||
) | ||
&& ( | ||
(isInSelection && oldIsInSelection && colors.selectionForeground) | ||
|| (!(isInSelection && oldIsInSelection && colors.selectionForeground) && cell.fg === oldFg) | ||
) | ||
&& cell.extended.ext === oldExt | ||
&& isLinkHover === oldLinkHover | ||
&& spacing === oldSpacing | ||
&& !isCursorCell | ||
|
@@ -194,6 +203,7 @@ export class DomRendererRowFactory { | |
oldExt = cell.extended.ext; | ||
oldLinkHover = isLinkHover; | ||
oldSpacing = spacing; | ||
oldIsInSelection = isInSelection; | ||
|
||
if (isJoined) { | ||
// The DOM renderer colors the background of the cursor but for ligatures all cells are | ||
|
@@ -328,22 +338,26 @@ export class DomRendererRowFactory { | |
isTop = d.options.layer === 'top'; | ||
}); | ||
|
||
// Apply selection foreground if applicable | ||
if (!isTop) { | ||
if (colors.selectionForeground && isInSelection) { | ||
// Apply selection | ||
if (!isTop && isInSelection) { | ||
// If in the selection, force the element to be above the selection to improve contrast and | ||
// support opaque selections. The applies background is not actually needed here as | ||
// selection is drawn in a seperate container, the main purpose of this to ensuring minimum | ||
// contrast ratio | ||
bgOverride = this._coreBrowserService.isFocused ? colors.selectionBackgroundOpaque : colors.selectionInactiveBackgroundOpaque; | ||
bg = bgOverride.rgba >> 8 & 0xFFFFFF; | ||
bgColorMode = Attributes.CM_RGB; | ||
// Since an opaque selection is being rendered, the selection pretends to be a decoration to | ||
// ensure text is drawn above the selection. | ||
isTop = true; | ||
// Apply selection foreground if applicable | ||
if (colors.selectionForeground) { | ||
fgColorMode = Attributes.CM_RGB; | ||
fg = colors.selectionForeground.rgba >> 8 & 0xFFFFFF; | ||
fgOverride = colors.selectionForeground; | ||
} | ||
} | ||
|
||
// If in the selection, force the element to be above the selection to improve contrast and | ||
// support opaque selections | ||
if (isInSelection) { | ||
bgOverride = this._coreBrowserService.isFocused ? colors.selectionBackgroundOpaque : colors.selectionInactiveBackgroundOpaque; | ||
isTop = true; | ||
} | ||
|
||
// If it's a top decoration, render above the selection | ||
if (isTop) { | ||
classes.push('xterm-decoration-top'); | ||
|
@@ -417,7 +431,7 @@ export class DomRendererRowFactory { | |
} | ||
|
||
// exclude conditions for cell merging - never merge these | ||
if (!isCursorCell && !isInSelection && !isJoined && !isDecorated) { | ||
if (!isCursorCell && !isJoined && !isDecorated && isInSelection === oldIsInSelection) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, if I lazily hacked Now your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you're right this does nothing 🙈 We may just be able to remove that condition completely then as this seemed to work well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
cellAmount++; | ||
} else { | ||
charElement.textContent = text; | ||
|
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.
Hmm this looks quite complicated - I guess you have tested it, so I assume it good as it is (though I wonder if it could be simplified). Which selection state tried you to cover here, which was not by the old conditions?
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.
Before we would just never merge cells if it was a selection which is easy but that means select all would all be the old slow rendering.
Outside of pulling things into named variables or expanding the comment I'm not sure how to simplify this, these cases are described in the comment above:
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.
Yes very true. Btw the same applies to
isDecorated
. Yeah, I kinda skipped dealing with inner works of selections and decorations, as it is more on the rare side of things. But indeed, you can actually feel the difference in responsiveness when selecting the full viewport and try to scroll then - so its good you address that.