Файли
openidea/patches/@codemirror__view.patch
T
audichuang ac5e4b7259 perf(editor): keep long lines rendered when a selection scrolls into view (#6677)
Extending a selection with Shift+Down over long unwrapped lines got slower with every selected line: while scrolling the head into view, CodeMirror placed each long line's rendered part by the target's fraction of that line (1 above the target, negative below it), so every long line above the caret was redrawn from its end and back. The @codemirror/view patch now centres every unwrapped line's line gaps on the target's x, taken from the target's own line; wrapped lines are unchanged.

Adds selectLongLinesSql/Txt perf scenarios, SQL to the in-memory backend's languages, and a jsdom test for the line gaps.

Refs #4658

Co-authored-by: audichuang <[email protected]>
2026-11-28 21:11:32 +08:00

93 рядки
4.8 KiB
Diff

diff --git a/dist/index.cjs b/dist/index.cjs
index b20aa9d..cf4dbc0 100644
--- a/dist/index.cjs
+++ b/dist/index.cjs
@@ -6568,6 +6568,14 @@ class ViewState {
}
gaps.push(gap);
};
+ let head = this.scrollTarget ? this.scrollTarget.range.head : -1, targetX = null;
+ if (head >= 0 && !wrapping) {
+ // Unwrapped lines all centre on the target's x, taken from the target's own line (long or not). The
+ // target's fraction of another line is 1 above it and negative below it, so every long line above
+ // the caret was drawn from its end, then back after the scroll.
+ let line = this.state.doc.lineAt(head), structure = lineStructure(line.from, line.to, this.stateDeco);
+ targetX = (structure.total ? findFraction(structure, head) * structure.total : 0) * this.heightOracle.charWidth;
+ }
let checkLine = (line) => {
if (line.length < doubleMargin || line.type != exports.BlockType.Text)
return;
@@ -6604,11 +6612,10 @@ class ViewState {
}
let pxLeft = this.pixelViewport.left + horizOffset, pxRight = this.pixelViewport.right + horizOffset;
let left, right;
- if (target != null) {
- let targetFrac = findFraction(structure, target);
- let spaceFrac = ((pxRight - pxLeft) / 2 + marginWidth) / totalWidth;
- left = targetFrac - spaceFrac;
- right = targetFrac + spaceFrac;
+ if (targetX != null) {
+ let space = (pxRight - pxLeft) / 2 + marginWidth;
+ left = (targetX - space) / totalWidth;
+ right = (targetX + space) / totalWidth;
}
else {
left = (pxLeft - marginWidth) / totalWidth;
@@ -9675,7 +9682,9 @@ const hideNativeSelection = state.Prec.highest(EditorView.theme({
"& :focus": {
caretColor: "initial !important",
...drawMainRange ? {
- "&::selection, & ::selection": {
+ // Not `& ::selection` too: a pseudo-class with a universal descendant restyles the
+ // whole subtree of every element that gains or loses focus.
+ "&::selection": {
backgroundColor: "Highlight !important"
}
} : {}
diff --git a/dist/index.js b/dist/index.js
index 216f754..c09c479 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -6563,6 +6563,14 @@ class ViewState {
}
gaps.push(gap);
};
+ let head = this.scrollTarget ? this.scrollTarget.range.head : -1, targetX = null;
+ if (head >= 0 && !wrapping) {
+ // Unwrapped lines all centre on the target's x, taken from the target's own line (long or not). The
+ // target's fraction of another line is 1 above it and negative below it, so every long line above
+ // the caret was drawn from its end, then back after the scroll.
+ let line = this.state.doc.lineAt(head), structure = lineStructure(line.from, line.to, this.stateDeco);
+ targetX = (structure.total ? findFraction(structure, head) * structure.total : 0) * this.heightOracle.charWidth;
+ }
let checkLine = (line) => {
if (line.length < doubleMargin || line.type != BlockType.Text)
return;
@@ -6599,11 +6607,10 @@ class ViewState {
}
let pxLeft = this.pixelViewport.left + horizOffset, pxRight = this.pixelViewport.right + horizOffset;
let left, right;
- if (target != null) {
- let targetFrac = findFraction(structure, target);
- let spaceFrac = ((pxRight - pxLeft) / 2 + marginWidth) / totalWidth;
- left = targetFrac - spaceFrac;
- right = targetFrac + spaceFrac;
+ if (targetX != null) {
+ let space = (pxRight - pxLeft) / 2 + marginWidth;
+ left = (targetX - space) / totalWidth;
+ right = (targetX + space) / totalWidth;
}
else {
left = (pxLeft - marginWidth) / totalWidth;
@@ -9670,7 +9677,9 @@ const hideNativeSelection = /*@__PURE__*/Prec.highest(/*@__PURE__*/EditorView.th
"& :focus": {
caretColor: "initial !important",
...drawMainRange ? {
- "&::selection, & ::selection": {
+ // Not `& ::selection` too: a pseudo-class with a universal descendant restyles the
+ // whole subtree of every element that gains or loses focus.
+ "&::selection": {
backgroundColor: "Highlight !important"
}
} : {}