@codemirror/view 6.2.0 → 6.2.1
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 +14 -0
- package/dist/index.cjs +39 -26
- package/dist/index.js +39 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 6.2.1 (2022-08-25)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Don't use the global `document` variable to track focus, since that doesn't work in another window/frame.
|
|
6
|
+
|
|
7
|
+
Fix an issue where key handlers that didn't return true were sometimes called twice for the same keypress.
|
|
8
|
+
|
|
9
|
+
Avoid editing glitches when using deletion keys like ctrl-d on iOS.
|
|
10
|
+
|
|
11
|
+
Properly treat characters from the 'Arabic Presentation Forms-A' Unicode block as right-to-left.
|
|
12
|
+
|
|
13
|
+
Work around a Firefox bug that inserts text at the wrong point for specific cross-line selections.
|
|
14
|
+
|
|
1
15
|
## 6.2.0 (2022-08-05)
|
|
2
16
|
|
|
3
17
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -22,8 +22,8 @@ function getSelection(root) {
|
|
|
22
22
|
function contains(dom, node) {
|
|
23
23
|
return node ? dom == node || dom.contains(node.nodeType != 1 ? node.parentNode : node) : false;
|
|
24
24
|
}
|
|
25
|
-
function deepActiveElement() {
|
|
26
|
-
let elt =
|
|
25
|
+
function deepActiveElement(doc) {
|
|
26
|
+
let elt = doc.activeElement;
|
|
27
27
|
while (elt && elt.shadowRoot)
|
|
28
28
|
elt = elt.shadowRoot.activeElement;
|
|
29
29
|
return elt;
|
|
@@ -762,7 +762,7 @@ class MarkView extends ContentView {
|
|
|
762
762
|
return new MarkView(this.mark, result, length);
|
|
763
763
|
}
|
|
764
764
|
domAtPos(pos) {
|
|
765
|
-
return inlineDOMAtPos(this
|
|
765
|
+
return inlineDOMAtPos(this, pos);
|
|
766
766
|
}
|
|
767
767
|
coordsAt(pos, side) {
|
|
768
768
|
return coordsInChildren(this, pos, side);
|
|
@@ -913,11 +913,14 @@ class CompositionView extends WidgetView {
|
|
|
913
913
|
// offset.
|
|
914
914
|
function scanCompositionTree(pos, side, view, text, enterView, fromText) {
|
|
915
915
|
if (view instanceof MarkView) {
|
|
916
|
-
for (let child
|
|
917
|
-
let
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
916
|
+
for (let child = view.dom.firstChild; child; child = child.nextSibling) {
|
|
917
|
+
let desc = ContentView.get(child);
|
|
918
|
+
if (!desc)
|
|
919
|
+
return fromText(pos, side);
|
|
920
|
+
let hasComp = contains(child, text);
|
|
921
|
+
let len = desc.length + (hasComp ? text.nodeValue.length : 0);
|
|
922
|
+
if (pos < len || pos == len && desc.getSide() <= 0)
|
|
923
|
+
return hasComp ? scanCompositionTree(pos, side, desc, text, enterView, fromText) : enterView(desc, pos, side);
|
|
921
924
|
pos -= len;
|
|
922
925
|
}
|
|
923
926
|
return enterView(view, view.length, -1);
|
|
@@ -1007,8 +1010,8 @@ function inlineSiblingRect(view, side) {
|
|
|
1007
1010
|
}
|
|
1008
1011
|
return undefined;
|
|
1009
1012
|
}
|
|
1010
|
-
function inlineDOMAtPos(
|
|
1011
|
-
let i = 0;
|
|
1013
|
+
function inlineDOMAtPos(parent, pos) {
|
|
1014
|
+
let dom = parent.dom, { children } = parent, i = 0;
|
|
1012
1015
|
for (let off = 0; i < children.length; i++) {
|
|
1013
1016
|
let child = children[i], end = off + child.length;
|
|
1014
1017
|
if (end == off && child.getSide() <= 0)
|
|
@@ -1019,10 +1022,16 @@ function inlineDOMAtPos(dom, children, pos) {
|
|
|
1019
1022
|
break;
|
|
1020
1023
|
off = end;
|
|
1021
1024
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1025
|
+
// if (i) return DOMPos.after(children[i - 1].dom!)
|
|
1026
|
+
for (let j = i; j > 0; j--) {
|
|
1027
|
+
let prev = children[j - 1];
|
|
1028
|
+
if (prev.dom.parentNode == dom)
|
|
1029
|
+
return prev.domAtPos(prev.length);
|
|
1030
|
+
}
|
|
1031
|
+
for (let j = i; j < children.length; j++) {
|
|
1032
|
+
let next = children[j];
|
|
1033
|
+
if (next.dom.parentNode == dom)
|
|
1034
|
+
return next.domAtPos(0);
|
|
1026
1035
|
}
|
|
1027
1036
|
return new DOMPos(dom, 0);
|
|
1028
1037
|
}
|
|
@@ -1431,7 +1440,7 @@ class LineView extends ContentView {
|
|
|
1431
1440
|
this.attrs = combineAttrs({ class: cls }, this.attrs || {});
|
|
1432
1441
|
}
|
|
1433
1442
|
domAtPos(pos) {
|
|
1434
|
-
return inlineDOMAtPos(this
|
|
1443
|
+
return inlineDOMAtPos(this, pos);
|
|
1435
1444
|
}
|
|
1436
1445
|
reuseDOM(node) {
|
|
1437
1446
|
if (node.nodeName == "DIV") {
|
|
@@ -2077,9 +2086,10 @@ function charType(ch) {
|
|
|
2077
2086
|
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
2078
2087
|
0x6ee <= ch && ch <= 0x8ac ? 4 /* AL */ :
|
|
2079
2088
|
0x2000 <= ch && ch <= 0x200b ? 256 /* NI */ :
|
|
2080
|
-
ch
|
|
2089
|
+
0xfb50 <= ch && ch <= 0xfdff ? 4 /* AL */ :
|
|
2090
|
+
ch == 0x200c ? 256 /* NI */ : 1 /* L */;
|
|
2081
2091
|
}
|
|
2082
|
-
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
|
|
2092
|
+
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
|
|
2083
2093
|
/**
|
|
2084
2094
|
Represents a contiguous range of text that has a single direction
|
|
2085
2095
|
(as in left-to-right or right-to-left).
|
|
@@ -3458,9 +3468,10 @@ class InputState {
|
|
|
3458
3468
|
// applyDOMChange, notify key handlers of it and reset to
|
|
3459
3469
|
// the state they produce.
|
|
3460
3470
|
let pending;
|
|
3461
|
-
if (browser.ios &&
|
|
3462
|
-
|
|
3463
|
-
|
|
3471
|
+
if (browser.ios && !event.synthetic && !event.altKey && !event.metaKey &&
|
|
3472
|
+
((pending = PendingKeys.find(key => key.keyCode == event.keyCode)) && !event.ctrlKey ||
|
|
3473
|
+
EmacsyPendingKeys.indexOf(event.key) > -1 && event.ctrlKey && !event.shiftKey)) {
|
|
3474
|
+
this.pendingIOSKey = pending || event;
|
|
3464
3475
|
setTimeout(() => this.flushIOSKey(view), 250);
|
|
3465
3476
|
return true;
|
|
3466
3477
|
}
|
|
@@ -3515,6 +3526,7 @@ const PendingKeys = [
|
|
|
3515
3526
|
{ key: "Enter", keyCode: 13, inputType: "insertParagraph" },
|
|
3516
3527
|
{ key: "Delete", keyCode: 46, inputType: "deleteContentForward" }
|
|
3517
3528
|
];
|
|
3529
|
+
const EmacsyPendingKeys = "dthko";
|
|
3518
3530
|
// Key codes for modifier keys
|
|
3519
3531
|
const modifierCodes = [16, 17, 18, 20, 91, 92, 224, 225];
|
|
3520
3532
|
class MouseSelection {
|
|
@@ -5574,7 +5586,8 @@ class DOMObserver {
|
|
|
5574
5586
|
let { view } = this;
|
|
5575
5587
|
// The Selection object is broken in shadow roots in Safari. See
|
|
5576
5588
|
// https://github.com/codemirror/dev/issues/414
|
|
5577
|
-
let range = browser.safari && view.root.nodeType == 11 &&
|
|
5589
|
+
let range = browser.safari && view.root.nodeType == 11 &&
|
|
5590
|
+
deepActiveElement(this.dom.ownerDocument) == this.dom &&
|
|
5578
5591
|
safariSelectionRangeHack(this.view) || getSelection(view.root);
|
|
5579
5592
|
if (!range || this.selectionRange.eq(range))
|
|
5580
5593
|
return false;
|
|
@@ -5819,7 +5832,7 @@ function safariSelectionRangeHack(view) {
|
|
|
5819
5832
|
found = event.getTargetRanges()[0];
|
|
5820
5833
|
}
|
|
5821
5834
|
view.contentDOM.addEventListener("beforeinput", read, true);
|
|
5822
|
-
|
|
5835
|
+
view.dom.ownerDocument.execCommand("indent");
|
|
5823
5836
|
view.contentDOM.removeEventListener("beforeinput", read, true);
|
|
5824
5837
|
if (!found)
|
|
5825
5838
|
return null;
|
|
@@ -6702,7 +6715,7 @@ class EditorView {
|
|
|
6702
6715
|
// or closing, which leads us to ignore selection changes from the
|
|
6703
6716
|
// context menu because it looks like the editor isn't focused.
|
|
6704
6717
|
// This kludges around that.
|
|
6705
|
-
return (
|
|
6718
|
+
return (this.dom.ownerDocument.hasFocus() || browser.safari && ((_a = this.inputState) === null || _a === void 0 ? void 0 : _a.lastContextMenu) > Date.now() - 3e4) &&
|
|
6706
6719
|
this.root.activeElement == this.contentDOM;
|
|
6707
6720
|
}
|
|
6708
6721
|
/**
|
|
@@ -7117,7 +7130,7 @@ function runHandlers(map, event, view, scope) {
|
|
|
7117
7130
|
}
|
|
7118
7131
|
return false;
|
|
7119
7132
|
};
|
|
7120
|
-
let scopeObj = map[scope], baseName;
|
|
7133
|
+
let scopeObj = map[scope], baseName, shiftName;
|
|
7121
7134
|
if (scopeObj) {
|
|
7122
7135
|
if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
|
|
7123
7136
|
return true;
|
|
@@ -7125,8 +7138,8 @@ function runHandlers(map, event, view, scope) {
|
|
|
7125
7138
|
(baseName = w3cKeyname.base[event.keyCode]) && baseName != name) {
|
|
7126
7139
|
if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
|
|
7127
7140
|
return true;
|
|
7128
|
-
else if (event.shiftKey && w3cKeyname.shift[event.keyCode] != baseName &&
|
|
7129
|
-
runFor(scopeObj[prefix + modifiers(
|
|
7141
|
+
else if (event.shiftKey && (shiftName = w3cKeyname.shift[event.keyCode]) != name && shiftName != baseName &&
|
|
7142
|
+
runFor(scopeObj[prefix + modifiers(shiftName, event, false)]))
|
|
7130
7143
|
return true;
|
|
7131
7144
|
}
|
|
7132
7145
|
else if (isChar && event.shiftKey) {
|
package/dist/index.js
CHANGED
|
@@ -18,8 +18,8 @@ function getSelection(root) {
|
|
|
18
18
|
function contains(dom, node) {
|
|
19
19
|
return node ? dom == node || dom.contains(node.nodeType != 1 ? node.parentNode : node) : false;
|
|
20
20
|
}
|
|
21
|
-
function deepActiveElement() {
|
|
22
|
-
let elt =
|
|
21
|
+
function deepActiveElement(doc) {
|
|
22
|
+
let elt = doc.activeElement;
|
|
23
23
|
while (elt && elt.shadowRoot)
|
|
24
24
|
elt = elt.shadowRoot.activeElement;
|
|
25
25
|
return elt;
|
|
@@ -758,7 +758,7 @@ class MarkView extends ContentView {
|
|
|
758
758
|
return new MarkView(this.mark, result, length);
|
|
759
759
|
}
|
|
760
760
|
domAtPos(pos) {
|
|
761
|
-
return inlineDOMAtPos(this
|
|
761
|
+
return inlineDOMAtPos(this, pos);
|
|
762
762
|
}
|
|
763
763
|
coordsAt(pos, side) {
|
|
764
764
|
return coordsInChildren(this, pos, side);
|
|
@@ -909,11 +909,14 @@ class CompositionView extends WidgetView {
|
|
|
909
909
|
// offset.
|
|
910
910
|
function scanCompositionTree(pos, side, view, text, enterView, fromText) {
|
|
911
911
|
if (view instanceof MarkView) {
|
|
912
|
-
for (let child
|
|
913
|
-
let
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
912
|
+
for (let child = view.dom.firstChild; child; child = child.nextSibling) {
|
|
913
|
+
let desc = ContentView.get(child);
|
|
914
|
+
if (!desc)
|
|
915
|
+
return fromText(pos, side);
|
|
916
|
+
let hasComp = contains(child, text);
|
|
917
|
+
let len = desc.length + (hasComp ? text.nodeValue.length : 0);
|
|
918
|
+
if (pos < len || pos == len && desc.getSide() <= 0)
|
|
919
|
+
return hasComp ? scanCompositionTree(pos, side, desc, text, enterView, fromText) : enterView(desc, pos, side);
|
|
917
920
|
pos -= len;
|
|
918
921
|
}
|
|
919
922
|
return enterView(view, view.length, -1);
|
|
@@ -1003,8 +1006,8 @@ function inlineSiblingRect(view, side) {
|
|
|
1003
1006
|
}
|
|
1004
1007
|
return undefined;
|
|
1005
1008
|
}
|
|
1006
|
-
function inlineDOMAtPos(
|
|
1007
|
-
let i = 0;
|
|
1009
|
+
function inlineDOMAtPos(parent, pos) {
|
|
1010
|
+
let dom = parent.dom, { children } = parent, i = 0;
|
|
1008
1011
|
for (let off = 0; i < children.length; i++) {
|
|
1009
1012
|
let child = children[i], end = off + child.length;
|
|
1010
1013
|
if (end == off && child.getSide() <= 0)
|
|
@@ -1015,10 +1018,16 @@ function inlineDOMAtPos(dom, children, pos) {
|
|
|
1015
1018
|
break;
|
|
1016
1019
|
off = end;
|
|
1017
1020
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1021
|
+
// if (i) return DOMPos.after(children[i - 1].dom!)
|
|
1022
|
+
for (let j = i; j > 0; j--) {
|
|
1023
|
+
let prev = children[j - 1];
|
|
1024
|
+
if (prev.dom.parentNode == dom)
|
|
1025
|
+
return prev.domAtPos(prev.length);
|
|
1026
|
+
}
|
|
1027
|
+
for (let j = i; j < children.length; j++) {
|
|
1028
|
+
let next = children[j];
|
|
1029
|
+
if (next.dom.parentNode == dom)
|
|
1030
|
+
return next.domAtPos(0);
|
|
1022
1031
|
}
|
|
1023
1032
|
return new DOMPos(dom, 0);
|
|
1024
1033
|
}
|
|
@@ -1426,7 +1435,7 @@ class LineView extends ContentView {
|
|
|
1426
1435
|
this.attrs = combineAttrs({ class: cls }, this.attrs || {});
|
|
1427
1436
|
}
|
|
1428
1437
|
domAtPos(pos) {
|
|
1429
|
-
return inlineDOMAtPos(this
|
|
1438
|
+
return inlineDOMAtPos(this, pos);
|
|
1430
1439
|
}
|
|
1431
1440
|
reuseDOM(node) {
|
|
1432
1441
|
if (node.nodeName == "DIV") {
|
|
@@ -2071,9 +2080,10 @@ function charType(ch) {
|
|
|
2071
2080
|
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
2072
2081
|
0x6ee <= ch && ch <= 0x8ac ? 4 /* AL */ :
|
|
2073
2082
|
0x2000 <= ch && ch <= 0x200b ? 256 /* NI */ :
|
|
2074
|
-
ch
|
|
2083
|
+
0xfb50 <= ch && ch <= 0xfdff ? 4 /* AL */ :
|
|
2084
|
+
ch == 0x200c ? 256 /* NI */ : 1 /* L */;
|
|
2075
2085
|
}
|
|
2076
|
-
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
|
|
2086
|
+
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
|
|
2077
2087
|
/**
|
|
2078
2088
|
Represents a contiguous range of text that has a single direction
|
|
2079
2089
|
(as in left-to-right or right-to-left).
|
|
@@ -3452,9 +3462,10 @@ class InputState {
|
|
|
3452
3462
|
// applyDOMChange, notify key handlers of it and reset to
|
|
3453
3463
|
// the state they produce.
|
|
3454
3464
|
let pending;
|
|
3455
|
-
if (browser.ios &&
|
|
3456
|
-
|
|
3457
|
-
|
|
3465
|
+
if (browser.ios && !event.synthetic && !event.altKey && !event.metaKey &&
|
|
3466
|
+
((pending = PendingKeys.find(key => key.keyCode == event.keyCode)) && !event.ctrlKey ||
|
|
3467
|
+
EmacsyPendingKeys.indexOf(event.key) > -1 && event.ctrlKey && !event.shiftKey)) {
|
|
3468
|
+
this.pendingIOSKey = pending || event;
|
|
3458
3469
|
setTimeout(() => this.flushIOSKey(view), 250);
|
|
3459
3470
|
return true;
|
|
3460
3471
|
}
|
|
@@ -3509,6 +3520,7 @@ const PendingKeys = [
|
|
|
3509
3520
|
{ key: "Enter", keyCode: 13, inputType: "insertParagraph" },
|
|
3510
3521
|
{ key: "Delete", keyCode: 46, inputType: "deleteContentForward" }
|
|
3511
3522
|
];
|
|
3523
|
+
const EmacsyPendingKeys = "dthko";
|
|
3512
3524
|
// Key codes for modifier keys
|
|
3513
3525
|
const modifierCodes = [16, 17, 18, 20, 91, 92, 224, 225];
|
|
3514
3526
|
class MouseSelection {
|
|
@@ -5567,7 +5579,8 @@ class DOMObserver {
|
|
|
5567
5579
|
let { view } = this;
|
|
5568
5580
|
// The Selection object is broken in shadow roots in Safari. See
|
|
5569
5581
|
// https://github.com/codemirror/dev/issues/414
|
|
5570
|
-
let range = browser.safari && view.root.nodeType == 11 &&
|
|
5582
|
+
let range = browser.safari && view.root.nodeType == 11 &&
|
|
5583
|
+
deepActiveElement(this.dom.ownerDocument) == this.dom &&
|
|
5571
5584
|
safariSelectionRangeHack(this.view) || getSelection(view.root);
|
|
5572
5585
|
if (!range || this.selectionRange.eq(range))
|
|
5573
5586
|
return false;
|
|
@@ -5812,7 +5825,7 @@ function safariSelectionRangeHack(view) {
|
|
|
5812
5825
|
found = event.getTargetRanges()[0];
|
|
5813
5826
|
}
|
|
5814
5827
|
view.contentDOM.addEventListener("beforeinput", read, true);
|
|
5815
|
-
|
|
5828
|
+
view.dom.ownerDocument.execCommand("indent");
|
|
5816
5829
|
view.contentDOM.removeEventListener("beforeinput", read, true);
|
|
5817
5830
|
if (!found)
|
|
5818
5831
|
return null;
|
|
@@ -6695,7 +6708,7 @@ class EditorView {
|
|
|
6695
6708
|
// or closing, which leads us to ignore selection changes from the
|
|
6696
6709
|
// context menu because it looks like the editor isn't focused.
|
|
6697
6710
|
// This kludges around that.
|
|
6698
|
-
return (
|
|
6711
|
+
return (this.dom.ownerDocument.hasFocus() || browser.safari && ((_a = this.inputState) === null || _a === void 0 ? void 0 : _a.lastContextMenu) > Date.now() - 3e4) &&
|
|
6699
6712
|
this.root.activeElement == this.contentDOM;
|
|
6700
6713
|
}
|
|
6701
6714
|
/**
|
|
@@ -7110,7 +7123,7 @@ function runHandlers(map, event, view, scope) {
|
|
|
7110
7123
|
}
|
|
7111
7124
|
return false;
|
|
7112
7125
|
};
|
|
7113
|
-
let scopeObj = map[scope], baseName;
|
|
7126
|
+
let scopeObj = map[scope], baseName, shiftName;
|
|
7114
7127
|
if (scopeObj) {
|
|
7115
7128
|
if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
|
|
7116
7129
|
return true;
|
|
@@ -7118,8 +7131,8 @@ function runHandlers(map, event, view, scope) {
|
|
|
7118
7131
|
(baseName = base[event.keyCode]) && baseName != name) {
|
|
7119
7132
|
if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
|
|
7120
7133
|
return true;
|
|
7121
|
-
else if (event.shiftKey && shift[event.keyCode] != baseName &&
|
|
7122
|
-
runFor(scopeObj[prefix + modifiers(
|
|
7134
|
+
else if (event.shiftKey && (shiftName = shift[event.keyCode]) != name && shiftName != baseName &&
|
|
7135
|
+
runFor(scopeObj[prefix + modifiers(shiftName, event, false)]))
|
|
7123
7136
|
return true;
|
|
7124
7137
|
}
|
|
7125
7138
|
else if (isChar && event.shiftKey) {
|