дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 18:17:15 +02:00
Selecting all text and typing left an extra empty line at the end: always for files without a final newline, and for files with one when the browser took more than 50 ms to apply the edit (the intermittent e2e/cornerInset.spec.ts failure). @codemirror/view 6.44's DOMReader read a line break after the only remaining line because its stale tile still had breakAfter set. The patch applies CodeMirror's upstream fix (view commit 45438ff87c), which only adds the break when content follows, until a release includes it. Co-authored-by: audichuang <[email protected]>
211 рядки
9.9 KiB
Diff
211 рядки
9.9 KiB
Diff
diff --git a/dist/index.cjs b/dist/index.cjs
|
|
index a16387f46d565aa3716de5650757b6d593683207..bd3ac08401a9b42e54a25511047212f29d5035ec 100644
|
|
--- a/dist/index.cjs
|
|
+++ b/dist/index.cjs
|
|
@@ -4131,7 +4131,7 @@ class DOMReader {
|
|
if (tile && !tile.parent)
|
|
break;
|
|
this.findPointAtEnd(cur);
|
|
- if (tile ? tile.breakAfter : isBlockElement(cur) && !isEmptyToEnd(cur, end)) {
|
|
+ if ((tile ? tile.breakAfter : isBlockElement(cur)) && !isEmptyToEnd(cur, end)) {
|
|
this.lineBreak();
|
|
}
|
|
}
|
|
@@ -4886,6 +4886,15 @@ class MouseSelection {
|
|
this.mustSelect = mustSelect;
|
|
this.scrollSpeed = { x: 0, y: 0 };
|
|
this.scrolling = -1;
|
|
+ this.moveFrame = -1;
|
|
+ this.pendingMove = false;
|
|
+ this.finishFrame = () => {
|
|
+ this.moveFrame = -1;
|
|
+ if (this.pendingMove) {
|
|
+ this.pendingMove = false;
|
|
+ this.move(this.lastEvent);
|
|
+ }
|
|
+ };
|
|
this.lastEvent = startEvent;
|
|
this.scrollParents = scrollableParents(view.contentDOM);
|
|
this.atoms = view.state.facet(atomicRanges).map(f => f(view));
|
|
@@ -4907,7 +4916,15 @@ class MouseSelection {
|
|
return this.destroy();
|
|
if (this.dragging || this.dragging == null && dist(this.startEvent, event) < 10)
|
|
return;
|
|
- this.select(this.lastEvent = event);
|
|
+ // Track the first move immediately. Of the moves arriving before the next
|
|
+ // paint, only the most recent needs hit testing, selection and autoscroll.
|
|
+ this.lastEvent = event;
|
|
+ if (this.moveFrame >= 0) {
|
|
+ this.pendingMove = true;
|
|
+ return;
|
|
+ }
|
|
+ this.moveFrame = this.view.win.requestAnimationFrame(this.finishFrame);
|
|
+ this.select(event);
|
|
let sx = 0, sy = 0;
|
|
let left = 0, top = 0, right = this.view.win.innerWidth, bottom = this.view.win.innerHeight;
|
|
if (this.scrollParents.x)
|
|
@@ -4926,13 +4943,15 @@ class MouseSelection {
|
|
this.setScrollSpeed(sx, sy);
|
|
}
|
|
up(event) {
|
|
- if (this.dragging == null)
|
|
+ if (this.dragging == null || this.pendingMove && !this.dragging)
|
|
this.select(this.lastEvent);
|
|
if (!this.dragging)
|
|
event.preventDefault();
|
|
this.destroy();
|
|
}
|
|
destroy() {
|
|
+ if (this.moveFrame >= 0)
|
|
+ this.view.win.cancelAnimationFrame(this.moveFrame);
|
|
this.setScrollSpeed(0, 0);
|
|
let doc = this.view.contentDOM.ownerDocument;
|
|
doc.removeEventListener("mousemove", this.move);
|
|
@@ -6699,6 +6718,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;
|
|
@@ -6735,11 +6762,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;
|
|
@@ -9840,7 +9866,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 66dd7d59910ead8521b4f287baa4d51b0ae2632b..49c6bdca9514132f27e84e992540996eea95114d 100644
|
|
--- a/dist/index.js
|
|
+++ b/dist/index.js
|
|
@@ -4127,7 +4127,7 @@ class DOMReader {
|
|
if (tile && !tile.parent)
|
|
break;
|
|
this.findPointAtEnd(cur);
|
|
- if (tile ? tile.breakAfter : isBlockElement(cur) && !isEmptyToEnd(cur, end)) {
|
|
+ if ((tile ? tile.breakAfter : isBlockElement(cur)) && !isEmptyToEnd(cur, end)) {
|
|
this.lineBreak();
|
|
}
|
|
}
|
|
@@ -4882,6 +4882,15 @@ class MouseSelection {
|
|
this.mustSelect = mustSelect;
|
|
this.scrollSpeed = { x: 0, y: 0 };
|
|
this.scrolling = -1;
|
|
+ this.moveFrame = -1;
|
|
+ this.pendingMove = false;
|
|
+ this.finishFrame = () => {
|
|
+ this.moveFrame = -1;
|
|
+ if (this.pendingMove) {
|
|
+ this.pendingMove = false;
|
|
+ this.move(this.lastEvent);
|
|
+ }
|
|
+ };
|
|
this.lastEvent = startEvent;
|
|
this.scrollParents = scrollableParents(view.contentDOM);
|
|
this.atoms = view.state.facet(atomicRanges).map(f => f(view));
|
|
@@ -4903,7 +4912,15 @@ class MouseSelection {
|
|
return this.destroy();
|
|
if (this.dragging || this.dragging == null && dist(this.startEvent, event) < 10)
|
|
return;
|
|
- this.select(this.lastEvent = event);
|
|
+ // Track the first move immediately. Of the moves arriving before the next
|
|
+ // paint, only the most recent needs hit testing, selection and autoscroll.
|
|
+ this.lastEvent = event;
|
|
+ if (this.moveFrame >= 0) {
|
|
+ this.pendingMove = true;
|
|
+ return;
|
|
+ }
|
|
+ this.moveFrame = this.view.win.requestAnimationFrame(this.finishFrame);
|
|
+ this.select(event);
|
|
let sx = 0, sy = 0;
|
|
let left = 0, top = 0, right = this.view.win.innerWidth, bottom = this.view.win.innerHeight;
|
|
if (this.scrollParents.x)
|
|
@@ -4922,13 +4939,15 @@ class MouseSelection {
|
|
this.setScrollSpeed(sx, sy);
|
|
}
|
|
up(event) {
|
|
- if (this.dragging == null)
|
|
+ if (this.dragging == null || this.pendingMove && !this.dragging)
|
|
this.select(this.lastEvent);
|
|
if (!this.dragging)
|
|
event.preventDefault();
|
|
this.destroy();
|
|
}
|
|
destroy() {
|
|
+ if (this.moveFrame >= 0)
|
|
+ this.view.win.cancelAnimationFrame(this.moveFrame);
|
|
this.setScrollSpeed(0, 0);
|
|
let doc = this.view.contentDOM.ownerDocument;
|
|
doc.removeEventListener("mousemove", this.move);
|
|
@@ -6694,6 +6713,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;
|
|
@@ -6730,11 +6757,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;
|
|
@@ -9835,7 +9861,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"
|
|
}
|
|
} : {}
|