@codemirror/view 6.39.10 → 6.39.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +17 -9
- package/dist/index.js +17 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -3674,11 +3674,8 @@ function moveVertically(view, start, forward, distance) {
|
|
|
3674
3674
|
}
|
|
3675
3675
|
let resolvedGoal = rect.left + goal;
|
|
3676
3676
|
let dist = distance !== null && distance !== void 0 ? distance : (view.viewState.heightOracle.textHeight >> 1);
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
|
|
3680
|
-
return state.EditorSelection.cursor(pos.pos, pos.assoc, undefined, goal);
|
|
3681
|
-
}
|
|
3677
|
+
let pos = posAtCoords(view, { x: resolvedGoal, y: startY + dist * dir }, false, dir);
|
|
3678
|
+
return state.EditorSelection.cursor(pos.pos, pos.assoc, undefined, goal);
|
|
3682
3679
|
}
|
|
3683
3680
|
function skipAtomicRanges(atoms, pos, bias) {
|
|
3684
3681
|
for (;;) {
|
|
@@ -4088,7 +4085,7 @@ function applyDOMChange(view, domChange) {
|
|
|
4088
4085
|
insert: state.Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder)) };
|
|
4089
4086
|
}
|
|
4090
4087
|
}
|
|
4091
|
-
else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel
|
|
4088
|
+
else if (newSel && (!view.hasFocus && view.state.facet(editable) || sameSelPos(newSel, sel))) {
|
|
4092
4089
|
newSel = null;
|
|
4093
4090
|
}
|
|
4094
4091
|
if (!change && !newSel)
|
|
@@ -4140,7 +4137,7 @@ function applyDOMChange(view, domChange) {
|
|
|
4140
4137
|
if (change) {
|
|
4141
4138
|
return applyDOMChangeInner(view, change, newSel, lastKey);
|
|
4142
4139
|
}
|
|
4143
|
-
else if (newSel && !newSel
|
|
4140
|
+
else if (newSel && !sameSelPos(newSel, sel)) {
|
|
4144
4141
|
let scrollIntoView = false, userEvent = "select";
|
|
4145
4142
|
if (view.inputState.lastSelectionTime > Date.now() - 50) {
|
|
4146
4143
|
if (view.inputState.lastSelectionOrigin == "select")
|
|
@@ -4311,6 +4308,9 @@ function selectionFromPoints(points, base) {
|
|
|
4311
4308
|
let anchor = points[0].pos, head = points.length == 2 ? points[1].pos : anchor;
|
|
4312
4309
|
return anchor > -1 && head > -1 ? state.EditorSelection.single(anchor + base, head + base) : null;
|
|
4313
4310
|
}
|
|
4311
|
+
function sameSelPos(selection, range) {
|
|
4312
|
+
return range.head == selection.main.head && range.anchor == selection.main.anchor;
|
|
4313
|
+
}
|
|
4314
4314
|
|
|
4315
4315
|
class InputState {
|
|
4316
4316
|
setSelectionOrigin(origin) {
|
|
@@ -4993,6 +4993,14 @@ function copiedRange(state) {
|
|
|
4993
4993
|
}
|
|
4994
4994
|
let lastLinewiseCopy = null;
|
|
4995
4995
|
handlers.copy = handlers.cut = (view, event) => {
|
|
4996
|
+
// If the DOM selection is outside this editor, don't intercept.
|
|
4997
|
+
// This happens when a parent editor (like ProseMirror) selects content that
|
|
4998
|
+
// spans multiple elements including this CodeMirror. The copy event may
|
|
4999
|
+
// bubble through CodeMirror (e.g. when CodeMirror is the first or the last
|
|
5000
|
+
// element in the selection), but we should let the parent handle it.
|
|
5001
|
+
let domSel = getSelection(view.root);
|
|
5002
|
+
if (domSel && !hasSelection(view.contentDOM, domSel))
|
|
5003
|
+
return false;
|
|
4996
5004
|
let { text, ranges, linewise } = copiedRange(view.state);
|
|
4997
5005
|
if (!text && !linewise)
|
|
4998
5006
|
return false;
|
|
@@ -7226,7 +7234,7 @@ class DOMObserver {
|
|
|
7226
7234
|
let handled = applyDOMChange(this.view, domChange);
|
|
7227
7235
|
// The view wasn't updated but DOM/selection changes were seen. Reset the view.
|
|
7228
7236
|
if (this.view.state == startState &&
|
|
7229
|
-
(domChange.domChanged || domChange.newSel && !
|
|
7237
|
+
(domChange.domChanged || domChange.newSel && !sameSelPos(this.view.state.selection, domChange.newSel.main)))
|
|
7230
7238
|
this.view.update([]);
|
|
7231
7239
|
return handled;
|
|
7232
7240
|
}
|
|
@@ -7390,7 +7398,7 @@ class EditContextManager {
|
|
|
7390
7398
|
// Edit contexts sometimes fire empty changes
|
|
7391
7399
|
if (!diff) {
|
|
7392
7400
|
let newSel = state.EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd));
|
|
7393
|
-
if (!newSel
|
|
7401
|
+
if (!sameSelPos(newSel, main))
|
|
7394
7402
|
view.dispatch({ selection: newSel, userEvent: "select" });
|
|
7395
7403
|
return;
|
|
7396
7404
|
}
|
package/dist/index.js
CHANGED
|
@@ -3670,11 +3670,8 @@ function moveVertically(view, start, forward, distance) {
|
|
|
3670
3670
|
}
|
|
3671
3671
|
let resolvedGoal = rect.left + goal;
|
|
3672
3672
|
let dist = distance !== null && distance !== void 0 ? distance : (view.viewState.heightOracle.textHeight >> 1);
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
|
|
3676
|
-
return EditorSelection.cursor(pos.pos, pos.assoc, undefined, goal);
|
|
3677
|
-
}
|
|
3673
|
+
let pos = posAtCoords(view, { x: resolvedGoal, y: startY + dist * dir }, false, dir);
|
|
3674
|
+
return EditorSelection.cursor(pos.pos, pos.assoc, undefined, goal);
|
|
3678
3675
|
}
|
|
3679
3676
|
function skipAtomicRanges(atoms, pos, bias) {
|
|
3680
3677
|
for (;;) {
|
|
@@ -4084,7 +4081,7 @@ function applyDOMChange(view, domChange) {
|
|
|
4084
4081
|
insert: Text.of(domChange.text.slice(diff.from, diff.toB).split(LineBreakPlaceholder)) };
|
|
4085
4082
|
}
|
|
4086
4083
|
}
|
|
4087
|
-
else if (newSel && (!view.hasFocus && view.state.facet(editable) || newSel
|
|
4084
|
+
else if (newSel && (!view.hasFocus && view.state.facet(editable) || sameSelPos(newSel, sel))) {
|
|
4088
4085
|
newSel = null;
|
|
4089
4086
|
}
|
|
4090
4087
|
if (!change && !newSel)
|
|
@@ -4136,7 +4133,7 @@ function applyDOMChange(view, domChange) {
|
|
|
4136
4133
|
if (change) {
|
|
4137
4134
|
return applyDOMChangeInner(view, change, newSel, lastKey);
|
|
4138
4135
|
}
|
|
4139
|
-
else if (newSel && !newSel
|
|
4136
|
+
else if (newSel && !sameSelPos(newSel, sel)) {
|
|
4140
4137
|
let scrollIntoView = false, userEvent = "select";
|
|
4141
4138
|
if (view.inputState.lastSelectionTime > Date.now() - 50) {
|
|
4142
4139
|
if (view.inputState.lastSelectionOrigin == "select")
|
|
@@ -4307,6 +4304,9 @@ function selectionFromPoints(points, base) {
|
|
|
4307
4304
|
let anchor = points[0].pos, head = points.length == 2 ? points[1].pos : anchor;
|
|
4308
4305
|
return anchor > -1 && head > -1 ? EditorSelection.single(anchor + base, head + base) : null;
|
|
4309
4306
|
}
|
|
4307
|
+
function sameSelPos(selection, range) {
|
|
4308
|
+
return range.head == selection.main.head && range.anchor == selection.main.anchor;
|
|
4309
|
+
}
|
|
4310
4310
|
|
|
4311
4311
|
class InputState {
|
|
4312
4312
|
setSelectionOrigin(origin) {
|
|
@@ -4989,6 +4989,14 @@ function copiedRange(state) {
|
|
|
4989
4989
|
}
|
|
4990
4990
|
let lastLinewiseCopy = null;
|
|
4991
4991
|
handlers.copy = handlers.cut = (view, event) => {
|
|
4992
|
+
// If the DOM selection is outside this editor, don't intercept.
|
|
4993
|
+
// This happens when a parent editor (like ProseMirror) selects content that
|
|
4994
|
+
// spans multiple elements including this CodeMirror. The copy event may
|
|
4995
|
+
// bubble through CodeMirror (e.g. when CodeMirror is the first or the last
|
|
4996
|
+
// element in the selection), but we should let the parent handle it.
|
|
4997
|
+
let domSel = getSelection(view.root);
|
|
4998
|
+
if (domSel && !hasSelection(view.contentDOM, domSel))
|
|
4999
|
+
return false;
|
|
4992
5000
|
let { text, ranges, linewise } = copiedRange(view.state);
|
|
4993
5001
|
if (!text && !linewise)
|
|
4994
5002
|
return false;
|
|
@@ -7221,7 +7229,7 @@ class DOMObserver {
|
|
|
7221
7229
|
let handled = applyDOMChange(this.view, domChange);
|
|
7222
7230
|
// The view wasn't updated but DOM/selection changes were seen. Reset the view.
|
|
7223
7231
|
if (this.view.state == startState &&
|
|
7224
|
-
(domChange.domChanged || domChange.newSel && !
|
|
7232
|
+
(domChange.domChanged || domChange.newSel && !sameSelPos(this.view.state.selection, domChange.newSel.main)))
|
|
7225
7233
|
this.view.update([]);
|
|
7226
7234
|
return handled;
|
|
7227
7235
|
}
|
|
@@ -7385,7 +7393,7 @@ class EditContextManager {
|
|
|
7385
7393
|
// Edit contexts sometimes fire empty changes
|
|
7386
7394
|
if (!diff) {
|
|
7387
7395
|
let newSel = EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd));
|
|
7388
|
-
if (!newSel
|
|
7396
|
+
if (!sameSelPos(newSel, main))
|
|
7389
7397
|
view.dispatch({ selection: newSel, userEvent: "select" });
|
|
7390
7398
|
return;
|
|
7391
7399
|
}
|