@codemirror/view 6.22.3 → 6.23.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 +30 -0
- package/dist/index.cjs +855 -775
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +856 -776
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Text, RangeSet, MapMode, RangeValue,
|
|
1
|
+
import { Text, RangeSet, MapMode, RangeValue, findClusterBreak, EditorSelection, Facet, StateEffect, ChangeSet, findColumn, CharCategory, Annotation, EditorState, Transaction, Prec, codePointAt, codePointSize, combineConfig, StateField, RangeSetBuilder, countColumn } from '@codemirror/state';
|
|
2
2
|
import { StyleModule } from 'style-mod';
|
|
3
3
|
import { keyName, base, shift } from 'w3c-keyname';
|
|
4
4
|
|
|
@@ -869,7 +869,8 @@ class WidgetView extends ContentView {
|
|
|
869
869
|
this.prevWidget.destroy(this.dom);
|
|
870
870
|
this.prevWidget = null;
|
|
871
871
|
this.setDOM(this.widget.toDOM(view));
|
|
872
|
-
this.
|
|
872
|
+
if (!this.widget.editable)
|
|
873
|
+
this.dom.contentEditable = "false";
|
|
873
874
|
}
|
|
874
875
|
}
|
|
875
876
|
getSide() { return this.side; }
|
|
@@ -1292,7 +1293,8 @@ class BlockWidgetView extends ContentView {
|
|
|
1292
1293
|
this.prevWidget.destroy(this.dom);
|
|
1293
1294
|
this.prevWidget = null;
|
|
1294
1295
|
this.setDOM(this.widget.toDOM(view));
|
|
1295
|
-
this.
|
|
1296
|
+
if (!this.widget.editable)
|
|
1297
|
+
this.dom.contentEditable = "false";
|
|
1296
1298
|
}
|
|
1297
1299
|
}
|
|
1298
1300
|
get overrideDOMText() {
|
|
@@ -1397,6 +1399,10 @@ class WidgetType {
|
|
|
1397
1399
|
*/
|
|
1398
1400
|
get isHidden() { return false; }
|
|
1399
1401
|
/**
|
|
1402
|
+
@internal
|
|
1403
|
+
*/
|
|
1404
|
+
get editable() { return false; }
|
|
1405
|
+
/**
|
|
1400
1406
|
This is called when the an instance of the widget is removed
|
|
1401
1407
|
from the editor view.
|
|
1402
1408
|
*/
|
|
@@ -1782,844 +1788,856 @@ class NullWidget extends WidgetType {
|
|
|
1782
1788
|
get isHidden() { return true; }
|
|
1783
1789
|
}
|
|
1784
1790
|
|
|
1785
|
-
const clickAddsSelectionRange = /*@__PURE__*/Facet.define();
|
|
1786
|
-
const dragMovesSelection$1 = /*@__PURE__*/Facet.define();
|
|
1787
|
-
const mouseSelectionStyle = /*@__PURE__*/Facet.define();
|
|
1788
|
-
const exceptionSink = /*@__PURE__*/Facet.define();
|
|
1789
|
-
const updateListener = /*@__PURE__*/Facet.define();
|
|
1790
|
-
const inputHandler = /*@__PURE__*/Facet.define();
|
|
1791
|
-
const focusChangeEffect = /*@__PURE__*/Facet.define();
|
|
1792
|
-
const perLineTextDirection = /*@__PURE__*/Facet.define({
|
|
1793
|
-
combine: values => values.some(x => x)
|
|
1794
|
-
});
|
|
1795
|
-
const nativeSelectionHidden = /*@__PURE__*/Facet.define({
|
|
1796
|
-
combine: values => values.some(x => x)
|
|
1797
|
-
});
|
|
1798
|
-
class ScrollTarget {
|
|
1799
|
-
constructor(range, y = "nearest", x = "nearest", yMargin = 5, xMargin = 5,
|
|
1800
|
-
// This data structure is abused to also store precise scroll
|
|
1801
|
-
// snapshots, instead of a `scrollIntoView` request. When this
|
|
1802
|
-
// flag is `true`, `range` points at a position in the reference
|
|
1803
|
-
// line, `yMargin` holds the difference between the top of that
|
|
1804
|
-
// line and the top of the editor, and `xMargin` holds the
|
|
1805
|
-
// editor's `scrollLeft`.
|
|
1806
|
-
isSnapshot = false) {
|
|
1807
|
-
this.range = range;
|
|
1808
|
-
this.y = y;
|
|
1809
|
-
this.x = x;
|
|
1810
|
-
this.yMargin = yMargin;
|
|
1811
|
-
this.xMargin = xMargin;
|
|
1812
|
-
this.isSnapshot = isSnapshot;
|
|
1813
|
-
}
|
|
1814
|
-
map(changes) {
|
|
1815
|
-
return changes.empty ? this :
|
|
1816
|
-
new ScrollTarget(this.range.map(changes), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
|
|
1817
|
-
}
|
|
1818
|
-
clip(state) {
|
|
1819
|
-
return this.range.to <= state.doc.length ? this :
|
|
1820
|
-
new ScrollTarget(EditorSelection.cursor(state.doc.length), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
const scrollIntoView = /*@__PURE__*/StateEffect.define({ map: (t, ch) => t.map(ch) });
|
|
1824
1791
|
/**
|
|
1825
|
-
|
|
1826
|
-
probably only be used by extension code that allows client code to
|
|
1827
|
-
provide functions, and calls those functions in a context where an
|
|
1828
|
-
exception can't be propagated to calling code in a reasonable way
|
|
1829
|
-
(for example when in an event handler).
|
|
1830
|
-
|
|
1831
|
-
Either calls a handler registered with
|
|
1832
|
-
[`EditorView.exceptionSink`](https://codemirror.net/6/docs/ref/#view.EditorView^exceptionSink),
|
|
1833
|
-
`window.onerror`, if defined, or `console.error` (in which case
|
|
1834
|
-
it'll pass `context`, when given, as first argument).
|
|
1792
|
+
Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).
|
|
1835
1793
|
*/
|
|
1836
|
-
function
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1794
|
+
var Direction = /*@__PURE__*/(function (Direction) {
|
|
1795
|
+
// (These are chosen to match the base levels, in bidi algorithm
|
|
1796
|
+
// terms, of spans in that direction.)
|
|
1797
|
+
/**
|
|
1798
|
+
Left-to-right.
|
|
1799
|
+
*/
|
|
1800
|
+
Direction[Direction["LTR"] = 0] = "LTR";
|
|
1801
|
+
/**
|
|
1802
|
+
Right-to-left.
|
|
1803
|
+
*/
|
|
1804
|
+
Direction[Direction["RTL"] = 1] = "RTL";
|
|
1805
|
+
return Direction})(Direction || (Direction = {}));
|
|
1806
|
+
const LTR = Direction.LTR, RTL = Direction.RTL;
|
|
1807
|
+
// Decode a string with each type encoded as log2(type)
|
|
1808
|
+
function dec(str) {
|
|
1809
|
+
let result = [];
|
|
1810
|
+
for (let i = 0; i < str.length; i++)
|
|
1811
|
+
result.push(1 << +str[i]);
|
|
1812
|
+
return result;
|
|
1846
1813
|
}
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1814
|
+
// Character types for codepoints 0 to 0xf8
|
|
1815
|
+
const LowTypes = /*@__PURE__*/dec("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008");
|
|
1816
|
+
// Character types for codepoints 0x600 to 0x6f9
|
|
1817
|
+
const ArabicTypes = /*@__PURE__*/dec("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333");
|
|
1818
|
+
const Brackets = /*@__PURE__*/Object.create(null), BracketStack = [];
|
|
1819
|
+
// There's a lot more in
|
|
1820
|
+
// https://www.unicode.org/Public/UCD/latest/ucd/BidiBrackets.txt,
|
|
1821
|
+
// which are left out to keep code size down.
|
|
1822
|
+
for (let p of ["()", "[]", "{}"]) {
|
|
1823
|
+
let l = /*@__PURE__*/p.charCodeAt(0), r = /*@__PURE__*/p.charCodeAt(1);
|
|
1824
|
+
Brackets[l] = r;
|
|
1825
|
+
Brackets[r] = -l;
|
|
1826
|
+
}
|
|
1827
|
+
function charType(ch) {
|
|
1828
|
+
return ch <= 0xf7 ? LowTypes[ch] :
|
|
1829
|
+
0x590 <= ch && ch <= 0x5f4 ? 2 /* T.R */ :
|
|
1830
|
+
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
1831
|
+
0x6ee <= ch && ch <= 0x8ac ? 4 /* T.AL */ :
|
|
1832
|
+
0x2000 <= ch && ch <= 0x200c ? 256 /* T.NI */ :
|
|
1833
|
+
0xfb50 <= ch && ch <= 0xfdff ? 4 /* T.AL */ : 1 /* T.L */;
|
|
1834
|
+
}
|
|
1835
|
+
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
|
|
1850
1836
|
/**
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
that happen in the view.
|
|
1837
|
+
Represents a contiguous range of text that has a single direction
|
|
1838
|
+
(as in left-to-right or right-to-left).
|
|
1854
1839
|
*/
|
|
1855
|
-
class
|
|
1856
|
-
constructor(
|
|
1840
|
+
class BidiSpan {
|
|
1857
1841
|
/**
|
|
1858
|
-
|
|
1842
|
+
The direction of this span.
|
|
1859
1843
|
*/
|
|
1860
|
-
|
|
1844
|
+
get dir() { return this.level % 2 ? RTL : LTR; }
|
|
1861
1845
|
/**
|
|
1862
1846
|
@internal
|
|
1863
1847
|
*/
|
|
1864
|
-
|
|
1848
|
+
constructor(
|
|
1865
1849
|
/**
|
|
1866
|
-
|
|
1850
|
+
The start of the span (relative to the start of the line).
|
|
1867
1851
|
*/
|
|
1868
|
-
|
|
1852
|
+
from,
|
|
1869
1853
|
/**
|
|
1870
|
-
|
|
1854
|
+
The end of the span.
|
|
1871
1855
|
*/
|
|
1872
|
-
|
|
1873
|
-
this.id = id;
|
|
1874
|
-
this.create = create;
|
|
1875
|
-
this.domEventHandlers = domEventHandlers;
|
|
1876
|
-
this.domEventObservers = domEventObservers;
|
|
1877
|
-
this.extension = buildExtensions(this);
|
|
1878
|
-
}
|
|
1856
|
+
to,
|
|
1879
1857
|
/**
|
|
1880
|
-
|
|
1881
|
-
|
|
1858
|
+
The ["bidi
|
|
1859
|
+
level"](https://unicode.org/reports/tr9/#Basic_Display_Algorithm)
|
|
1860
|
+
of the span (in this context, 0 means
|
|
1861
|
+
left-to-right, 1 means right-to-left, 2 means left-to-right
|
|
1862
|
+
number inside right-to-left text).
|
|
1882
1863
|
*/
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
if (deco)
|
|
1888
|
-
ext.push(decorations.of(view => {
|
|
1889
|
-
let pluginInst = view.plugin(plugin);
|
|
1890
|
-
return pluginInst ? deco(pluginInst) : Decoration.none;
|
|
1891
|
-
}));
|
|
1892
|
-
if (provide)
|
|
1893
|
-
ext.push(provide(plugin));
|
|
1894
|
-
return ext;
|
|
1895
|
-
});
|
|
1864
|
+
level) {
|
|
1865
|
+
this.from = from;
|
|
1866
|
+
this.to = to;
|
|
1867
|
+
this.level = level;
|
|
1896
1868
|
}
|
|
1897
1869
|
/**
|
|
1898
|
-
|
|
1899
|
-
editor view as argument.
|
|
1870
|
+
@internal
|
|
1900
1871
|
*/
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
this.value = this.spec.create(view);
|
|
1922
|
-
}
|
|
1923
|
-
catch (e) {
|
|
1924
|
-
logException(view.state, e, "CodeMirror plugin crashed");
|
|
1925
|
-
this.deactivate();
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
}
|
|
1929
|
-
else if (this.mustUpdate) {
|
|
1930
|
-
let update = this.mustUpdate;
|
|
1931
|
-
this.mustUpdate = null;
|
|
1932
|
-
if (this.value.update) {
|
|
1933
|
-
try {
|
|
1934
|
-
this.value.update(update);
|
|
1935
|
-
}
|
|
1936
|
-
catch (e) {
|
|
1937
|
-
logException(update.state, e, "CodeMirror plugin crashed");
|
|
1938
|
-
if (this.value.destroy)
|
|
1939
|
-
try {
|
|
1940
|
-
this.value.destroy();
|
|
1941
|
-
}
|
|
1942
|
-
catch (_) { }
|
|
1943
|
-
this.deactivate();
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
return this;
|
|
1948
|
-
}
|
|
1949
|
-
destroy(view) {
|
|
1950
|
-
var _a;
|
|
1951
|
-
if ((_a = this.value) === null || _a === void 0 ? void 0 : _a.destroy) {
|
|
1952
|
-
try {
|
|
1953
|
-
this.value.destroy();
|
|
1954
|
-
}
|
|
1955
|
-
catch (e) {
|
|
1956
|
-
logException(view.state, e, "CodeMirror plugin crashed");
|
|
1872
|
+
side(end, dir) { return (this.dir == dir) == end ? this.to : this.from; }
|
|
1873
|
+
/**
|
|
1874
|
+
@internal
|
|
1875
|
+
*/
|
|
1876
|
+
forward(forward, dir) { return forward == (this.dir == dir); }
|
|
1877
|
+
/**
|
|
1878
|
+
@internal
|
|
1879
|
+
*/
|
|
1880
|
+
static find(order, index, level, assoc) {
|
|
1881
|
+
let maybe = -1;
|
|
1882
|
+
for (let i = 0; i < order.length; i++) {
|
|
1883
|
+
let span = order[i];
|
|
1884
|
+
if (span.from <= index && span.to >= index) {
|
|
1885
|
+
if (span.level == level)
|
|
1886
|
+
return i;
|
|
1887
|
+
// When multiple spans match, if assoc != 0, take the one that
|
|
1888
|
+
// covers that side, otherwise take the one with the minimum
|
|
1889
|
+
// level.
|
|
1890
|
+
if (maybe < 0 || (assoc != 0 ? (assoc < 0 ? span.from < index : span.to > index) : order[maybe].level > span.level))
|
|
1891
|
+
maybe = i;
|
|
1957
1892
|
}
|
|
1958
1893
|
}
|
|
1894
|
+
if (maybe < 0)
|
|
1895
|
+
throw new RangeError("Index out of range");
|
|
1896
|
+
return maybe;
|
|
1959
1897
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1898
|
+
}
|
|
1899
|
+
function isolatesEq(a, b) {
|
|
1900
|
+
if (a.length != b.length)
|
|
1901
|
+
return false;
|
|
1902
|
+
for (let i = 0; i < a.length; i++) {
|
|
1903
|
+
let iA = a[i], iB = b[i];
|
|
1904
|
+
if (iA.from != iB.from || iA.to != iB.to || iA.direction != iB.direction || !isolatesEq(iA.inner, iB.inner))
|
|
1905
|
+
return false;
|
|
1962
1906
|
}
|
|
1907
|
+
return true;
|
|
1963
1908
|
}
|
|
1964
|
-
|
|
1965
|
-
const
|
|
1966
|
-
//
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1909
|
+
// Reused array of character types
|
|
1910
|
+
const types = [];
|
|
1911
|
+
// Fill in the character types (in `types`) from `from` to `to` and
|
|
1912
|
+
// apply W normalization rules.
|
|
1913
|
+
function computeCharTypes(line, rFrom, rTo, isolates, outerType) {
|
|
1914
|
+
for (let iI = 0; iI <= isolates.length; iI++) {
|
|
1915
|
+
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
1916
|
+
let prevType = iI ? 256 /* T.NI */ : outerType;
|
|
1917
|
+
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
|
1918
|
+
// change the type of the NSM to the type of the previous
|
|
1919
|
+
// character. If the NSM is at the start of the level run, it will
|
|
1920
|
+
// get the type of sor.
|
|
1921
|
+
// W2. Search backwards from each instance of a European number
|
|
1922
|
+
// until the first strong type (R, L, AL, or sor) is found. If an
|
|
1923
|
+
// AL is found, change the type of the European number to Arabic
|
|
1924
|
+
// number.
|
|
1925
|
+
// W3. Change all ALs to R.
|
|
1926
|
+
// (Left after this: L, R, EN, AN, ET, CS, NI)
|
|
1927
|
+
for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {
|
|
1928
|
+
let type = charType(line.charCodeAt(i));
|
|
1929
|
+
if (type == 512 /* T.NSM */)
|
|
1930
|
+
type = prev;
|
|
1931
|
+
else if (type == 8 /* T.EN */ && prevStrong == 4 /* T.AL */)
|
|
1932
|
+
type = 16 /* T.AN */;
|
|
1933
|
+
types[i] = type == 4 /* T.AL */ ? 2 /* T.R */ : type;
|
|
1934
|
+
if (type & 7 /* T.Strong */)
|
|
1935
|
+
prevStrong = type;
|
|
1936
|
+
prev = type;
|
|
1937
|
+
}
|
|
1938
|
+
// W5. A sequence of European terminators adjacent to European
|
|
1939
|
+
// numbers changes to all European numbers.
|
|
1940
|
+
// W6. Otherwise, separators and terminators change to Other
|
|
1941
|
+
// Neutral.
|
|
1942
|
+
// W7. Search backwards from each instance of a European number
|
|
1943
|
+
// until the first strong type (R, L, or sor) is found. If an L is
|
|
1944
|
+
// found, then change the type of the European number to L.
|
|
1945
|
+
// (Left after this: L, R, EN+AN, NI)
|
|
1946
|
+
for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {
|
|
1947
|
+
let type = types[i];
|
|
1948
|
+
if (type == 128 /* T.CS */) {
|
|
1949
|
+
if (i < to - 1 && prev == types[i + 1] && (prev & 24 /* T.Num */))
|
|
1950
|
+
type = types[i] = prev;
|
|
1951
|
+
else
|
|
1952
|
+
types[i] = 256 /* T.NI */;
|
|
1953
|
+
}
|
|
1954
|
+
else if (type == 64 /* T.ET */) {
|
|
1955
|
+
let end = i + 1;
|
|
1956
|
+
while (end < to && types[end] == 64 /* T.ET */)
|
|
1957
|
+
end++;
|
|
1958
|
+
let replace = (i && prev == 8 /* T.EN */) || (end < rTo && types[end] == 8 /* T.EN */) ? (prevStrong == 1 /* T.L */ ? 1 /* T.L */ : 8 /* T.EN */) : 256 /* T.NI */;
|
|
1959
|
+
for (let j = i; j < end; j++)
|
|
1960
|
+
types[j] = replace;
|
|
1961
|
+
i = end - 1;
|
|
1962
|
+
}
|
|
1963
|
+
else if (type == 8 /* T.EN */ && prevStrong == 1 /* T.L */) {
|
|
1964
|
+
types[i] = 1 /* T.L */;
|
|
1965
|
+
}
|
|
1966
|
+
prev = type;
|
|
1967
|
+
if (type & 7 /* T.Strong */)
|
|
1968
|
+
prevStrong = type;
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
// Process brackets throughout a run sequence.
|
|
1973
|
+
function processBracketPairs(line, rFrom, rTo, isolates, outerType) {
|
|
1974
|
+
let oppositeType = outerType == 1 /* T.L */ ? 2 /* T.R */ : 1 /* T.L */;
|
|
1975
|
+
for (let iI = 0, sI = 0, context = 0; iI <= isolates.length; iI++) {
|
|
1976
|
+
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
1977
|
+
// N0. Process bracket pairs in an isolating run sequence
|
|
1978
|
+
// sequentially in the logical order of the text positions of the
|
|
1979
|
+
// opening paired brackets using the logic given below. Within this
|
|
1980
|
+
// scope, bidirectional types EN and AN are treated as R.
|
|
1981
|
+
for (let i = from, ch, br, type; i < to; i++) {
|
|
1982
|
+
// Keeps [startIndex, type, strongSeen] triples for each open
|
|
1983
|
+
// bracket on BracketStack.
|
|
1984
|
+
if (br = Brackets[ch = line.charCodeAt(i)]) {
|
|
1985
|
+
if (br < 0) { // Closing bracket
|
|
1986
|
+
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
1987
|
+
if (BracketStack[sJ + 1] == -br) {
|
|
1988
|
+
let flags = BracketStack[sJ + 2];
|
|
1989
|
+
let type = (flags & 2 /* Bracketed.EmbedInside */) ? outerType :
|
|
1990
|
+
!(flags & 4 /* Bracketed.OppositeInside */) ? 0 :
|
|
1991
|
+
(flags & 1 /* Bracketed.OppositeBefore */) ? oppositeType : outerType;
|
|
1992
|
+
if (type)
|
|
1993
|
+
types[i] = types[BracketStack[sJ]] = type;
|
|
1994
|
+
sI = sJ;
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
else if (BracketStack.length == 189 /* Bracketed.MaxDepth */) {
|
|
2000
|
+
break;
|
|
1988
2001
|
}
|
|
1989
2002
|
else {
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2003
|
+
BracketStack[sI++] = i;
|
|
2004
|
+
BracketStack[sI++] = ch;
|
|
2005
|
+
BracketStack[sI++] = context;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
else if ((type = types[i]) == 2 /* T.R */ || type == 1 /* T.L */) {
|
|
2009
|
+
let embed = type == outerType;
|
|
2010
|
+
context = embed ? 0 : 1 /* Bracketed.OppositeBefore */;
|
|
2011
|
+
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
2012
|
+
let cur = BracketStack[sJ + 2];
|
|
2013
|
+
if (cur & 2 /* Bracketed.EmbedInside */)
|
|
2014
|
+
break;
|
|
2015
|
+
if (embed) {
|
|
2016
|
+
BracketStack[sJ + 2] |= 2 /* Bracketed.EmbedInside */;
|
|
2017
|
+
}
|
|
2018
|
+
else {
|
|
2019
|
+
if (cur & 4 /* Bracketed.OppositeInside */)
|
|
2020
|
+
break;
|
|
2021
|
+
BracketStack[sJ + 2] |= 4 /* Bracketed.OppositeInside */;
|
|
2022
|
+
}
|
|
1993
2023
|
}
|
|
1994
2024
|
}
|
|
1995
2025
|
}
|
|
1996
|
-
}
|
|
1997
|
-
return result;
|
|
2026
|
+
}
|
|
1998
2027
|
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
if
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
if (
|
|
2012
|
-
|
|
2028
|
+
function processNeutrals(rFrom, rTo, isolates, outerType) {
|
|
2029
|
+
for (let iI = 0, prev = outerType; iI <= isolates.length; iI++) {
|
|
2030
|
+
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
2031
|
+
// N1. A sequence of neutrals takes the direction of the
|
|
2032
|
+
// surrounding strong text if the text on both sides has the same
|
|
2033
|
+
// direction. European and Arabic numbers act as if they were R in
|
|
2034
|
+
// terms of their influence on neutrals. Start-of-level-run (sor)
|
|
2035
|
+
// and end-of-level-run (eor) are used at level run boundaries.
|
|
2036
|
+
// N2. Any remaining neutrals take the embedding direction.
|
|
2037
|
+
// (Left after this: L, R, EN+AN)
|
|
2038
|
+
for (let i = from; i < to;) {
|
|
2039
|
+
let type = types[i];
|
|
2040
|
+
if (type == 256 /* T.NI */) {
|
|
2041
|
+
let end = i + 1;
|
|
2042
|
+
for (;;) {
|
|
2043
|
+
if (end == to) {
|
|
2044
|
+
if (iI == isolates.length)
|
|
2045
|
+
break;
|
|
2046
|
+
end = isolates[iI++].to;
|
|
2047
|
+
to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
2048
|
+
}
|
|
2049
|
+
else if (types[end] == 256 /* T.NI */) {
|
|
2050
|
+
end++;
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
break;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
let beforeL = prev == 1 /* T.L */;
|
|
2057
|
+
let afterL = (end < rTo ? types[end] : outerType) == 1 /* T.L */;
|
|
2058
|
+
let replace = beforeL == afterL ? (beforeL ? 1 /* T.L */ : 2 /* T.R */) : outerType;
|
|
2059
|
+
for (let j = end, jI = iI, fromJ = jI ? isolates[jI - 1].to : rFrom; j > i;) {
|
|
2060
|
+
if (j == fromJ) {
|
|
2061
|
+
j = isolates[--jI].from;
|
|
2062
|
+
fromJ = jI ? isolates[jI - 1].to : rFrom;
|
|
2063
|
+
}
|
|
2064
|
+
types[--j] = replace;
|
|
2065
|
+
}
|
|
2066
|
+
i = end;
|
|
2067
|
+
}
|
|
2068
|
+
else {
|
|
2069
|
+
prev = type;
|
|
2070
|
+
i++;
|
|
2071
|
+
}
|
|
2013
2072
|
}
|
|
2014
2073
|
}
|
|
2015
|
-
return { left, right, top, bottom };
|
|
2016
2074
|
}
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2075
|
+
// Find the contiguous ranges of character types in a given range, and
|
|
2076
|
+
// emit spans for them. Flip the order of the spans as appropriate
|
|
2077
|
+
// based on the level, and call through to compute the spans for
|
|
2078
|
+
// isolates at the proper point.
|
|
2079
|
+
function emitSpans(line, from, to, level, baseLevel, isolates, order) {
|
|
2080
|
+
let ourType = level % 2 ? 2 /* T.R */ : 1 /* T.L */;
|
|
2081
|
+
if ((level % 2) == (baseLevel % 2)) { // Same dir as base direction, don't flip
|
|
2082
|
+
for (let iCh = from, iI = 0; iCh < to;) {
|
|
2083
|
+
// Scan a section of characters in direction ourType, unless
|
|
2084
|
+
// there's another type of char right after iCh, in which case
|
|
2085
|
+
// we scan a section of other characters (which, if ourType ==
|
|
2086
|
+
// T.L, may contain both T.R and T.AN chars).
|
|
2087
|
+
let sameDir = true, isNum = false;
|
|
2088
|
+
if (iI == isolates.length || iCh < isolates[iI].from) {
|
|
2089
|
+
let next = types[iCh];
|
|
2090
|
+
if (next != ourType) {
|
|
2091
|
+
sameDir = false;
|
|
2092
|
+
isNum = next == 16 /* T.AN */;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
// Holds an array of isolates to pass to a recursive call if we
|
|
2096
|
+
// must recurse (to distinguish T.AN inside an RTL section in
|
|
2097
|
+
// LTR text), null if we can emit directly
|
|
2098
|
+
let recurse = !sameDir && ourType == 1 /* T.L */ ? [] : null;
|
|
2099
|
+
let localLevel = sameDir ? level : level + 1;
|
|
2100
|
+
let iScan = iCh;
|
|
2101
|
+
run: for (;;) {
|
|
2102
|
+
if (iI < isolates.length && iScan == isolates[iI].from) {
|
|
2103
|
+
if (isNum)
|
|
2104
|
+
break run;
|
|
2105
|
+
let iso = isolates[iI];
|
|
2106
|
+
// Scan ahead to verify that there is another char in this dir after the isolate(s)
|
|
2107
|
+
if (!sameDir)
|
|
2108
|
+
for (let upto = iso.to, jI = iI + 1;;) {
|
|
2109
|
+
if (upto == to)
|
|
2110
|
+
break run;
|
|
2111
|
+
if (jI < isolates.length && isolates[jI].from == upto)
|
|
2112
|
+
upto = isolates[jI++].to;
|
|
2113
|
+
else if (types[upto] == ourType)
|
|
2114
|
+
break run;
|
|
2115
|
+
else
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
iI++;
|
|
2119
|
+
if (recurse) {
|
|
2120
|
+
recurse.push(iso);
|
|
2121
|
+
}
|
|
2122
|
+
else {
|
|
2123
|
+
if (iso.from > iCh)
|
|
2124
|
+
order.push(new BidiSpan(iCh, iso.from, localLevel));
|
|
2125
|
+
let dirSwap = (iso.direction == LTR) != !(localLevel % 2);
|
|
2126
|
+
computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);
|
|
2127
|
+
iCh = iso.to;
|
|
2128
|
+
}
|
|
2129
|
+
iScan = iso.to;
|
|
2130
|
+
}
|
|
2131
|
+
else if (iScan == to || (sameDir ? types[iScan] != ourType : types[iScan] == ourType)) {
|
|
2132
|
+
break;
|
|
2133
|
+
}
|
|
2134
|
+
else {
|
|
2135
|
+
iScan++;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
if (recurse)
|
|
2139
|
+
emitSpans(line, iCh, iScan, level + 1, baseLevel, recurse, order);
|
|
2140
|
+
else if (iCh < iScan)
|
|
2141
|
+
order.push(new BidiSpan(iCh, iScan, localLevel));
|
|
2142
|
+
iCh = iScan;
|
|
2038
2143
|
}
|
|
2039
|
-
set.splice(i, 0, me);
|
|
2040
|
-
return set;
|
|
2041
2144
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
let
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2145
|
+
else {
|
|
2146
|
+
// Iterate in reverse to flip the span order. Same code again, but
|
|
2147
|
+
// going from the back of the section to the front
|
|
2148
|
+
for (let iCh = to, iI = isolates.length; iCh > from;) {
|
|
2149
|
+
let sameDir = true, isNum = false;
|
|
2150
|
+
if (!iI || iCh > isolates[iI - 1].to) {
|
|
2151
|
+
let next = types[iCh - 1];
|
|
2152
|
+
if (next != ourType) {
|
|
2153
|
+
sameDir = false;
|
|
2154
|
+
isNum = next == 16 /* T.AN */;
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
let recurse = !sameDir && ourType == 1 /* T.L */ ? [] : null;
|
|
2158
|
+
let localLevel = sameDir ? level : level + 1;
|
|
2159
|
+
let iScan = iCh;
|
|
2160
|
+
run: for (;;) {
|
|
2161
|
+
if (iI && iScan == isolates[iI - 1].to) {
|
|
2162
|
+
if (isNum)
|
|
2163
|
+
break run;
|
|
2164
|
+
let iso = isolates[--iI];
|
|
2165
|
+
// Scan ahead to verify that there is another char in this dir after the isolate(s)
|
|
2166
|
+
if (!sameDir)
|
|
2167
|
+
for (let upto = iso.from, jI = iI;;) {
|
|
2168
|
+
if (upto == from)
|
|
2169
|
+
break run;
|
|
2170
|
+
if (jI && isolates[jI - 1].to == upto)
|
|
2171
|
+
upto = isolates[--jI].from;
|
|
2172
|
+
else if (types[upto - 1] == ourType)
|
|
2173
|
+
break run;
|
|
2174
|
+
else
|
|
2175
|
+
break;
|
|
2176
|
+
}
|
|
2177
|
+
if (recurse) {
|
|
2178
|
+
recurse.push(iso);
|
|
2179
|
+
}
|
|
2180
|
+
else {
|
|
2181
|
+
if (iso.to < iCh)
|
|
2182
|
+
order.push(new BidiSpan(iso.to, iCh, localLevel));
|
|
2183
|
+
let dirSwap = (iso.direction == LTR) != !(localLevel % 2);
|
|
2184
|
+
computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);
|
|
2185
|
+
iCh = iso.from;
|
|
2186
|
+
}
|
|
2187
|
+
iScan = iso.from;
|
|
2188
|
+
}
|
|
2189
|
+
else if (iScan == from || (sameDir ? types[iScan - 1] != ourType : types[iScan - 1] == ourType)) {
|
|
2055
2190
|
break;
|
|
2056
|
-
|
|
2057
|
-
|
|
2191
|
+
}
|
|
2192
|
+
else {
|
|
2193
|
+
iScan--;
|
|
2194
|
+
}
|
|
2058
2195
|
}
|
|
2059
|
-
if (
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2196
|
+
if (recurse)
|
|
2197
|
+
emitSpans(line, iScan, iCh, level + 1, baseLevel, recurse, order);
|
|
2198
|
+
else if (iScan < iCh)
|
|
2199
|
+
order.push(new BidiSpan(iScan, iCh, localLevel));
|
|
2200
|
+
iCh = iScan;
|
|
2064
2201
|
}
|
|
2065
2202
|
}
|
|
2066
2203
|
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
changed in this update.
|
|
2117
|
-
*/
|
|
2118
|
-
get heightChanged() {
|
|
2119
|
-
return (this.flags & 2 /* UpdateFlag.Height */) > 0;
|
|
2120
|
-
}
|
|
2121
|
-
/**
|
|
2122
|
-
Returns true when the document was modified or the size of the
|
|
2123
|
-
editor, or elements within the editor, changed.
|
|
2124
|
-
*/
|
|
2125
|
-
get geometryChanged() {
|
|
2126
|
-
return this.docChanged || (this.flags & (8 /* UpdateFlag.Geometry */ | 2 /* UpdateFlag.Height */)) > 0;
|
|
2204
|
+
function computeSectionOrder(line, level, baseLevel, isolates, from, to, order) {
|
|
2205
|
+
let outerType = (level % 2 ? 2 /* T.R */ : 1 /* T.L */);
|
|
2206
|
+
computeCharTypes(line, from, to, isolates, outerType);
|
|
2207
|
+
processBracketPairs(line, from, to, isolates, outerType);
|
|
2208
|
+
processNeutrals(from, to, isolates, outerType);
|
|
2209
|
+
emitSpans(line, from, to, level, baseLevel, isolates, order);
|
|
2210
|
+
}
|
|
2211
|
+
function computeOrder(line, direction, isolates) {
|
|
2212
|
+
if (!line)
|
|
2213
|
+
return [new BidiSpan(0, 0, direction == RTL ? 1 : 0)];
|
|
2214
|
+
if (direction == LTR && !isolates.length && !BidiRE.test(line))
|
|
2215
|
+
return trivialOrder(line.length);
|
|
2216
|
+
if (isolates.length)
|
|
2217
|
+
while (line.length > types.length)
|
|
2218
|
+
types[types.length] = 256 /* T.NI */; // Make sure types array has no gaps
|
|
2219
|
+
let order = [], level = direction == LTR ? 0 : 1;
|
|
2220
|
+
computeSectionOrder(line, level, level, isolates, 0, line.length, order);
|
|
2221
|
+
return order;
|
|
2222
|
+
}
|
|
2223
|
+
function trivialOrder(length) {
|
|
2224
|
+
return [new BidiSpan(0, length, 0)];
|
|
2225
|
+
}
|
|
2226
|
+
let movedOver = "";
|
|
2227
|
+
// This implementation moves strictly visually, without concern for a
|
|
2228
|
+
// traversal visiting every logical position in the string. It will
|
|
2229
|
+
// still do so for simple input, but situations like multiple isolates
|
|
2230
|
+
// with the same level next to each other, or text going against the
|
|
2231
|
+
// main dir at the end of the line, will make some positions
|
|
2232
|
+
// unreachable with this motion. Each visible cursor position will
|
|
2233
|
+
// correspond to the lower-level bidi span that touches it.
|
|
2234
|
+
//
|
|
2235
|
+
// The alternative would be to solve an order globally for a given
|
|
2236
|
+
// line, making sure that it includes every position, but that would
|
|
2237
|
+
// require associating non-canonical (higher bidi span level)
|
|
2238
|
+
// positions with a given visual position, which is likely to confuse
|
|
2239
|
+
// people. (And would generally be a lot more complicated.)
|
|
2240
|
+
function moveVisually(line, order, dir, start, forward) {
|
|
2241
|
+
var _a;
|
|
2242
|
+
let startIndex = start.head - line.from;
|
|
2243
|
+
let spanI = BidiSpan.find(order, startIndex, (_a = start.bidiLevel) !== null && _a !== void 0 ? _a : -1, start.assoc);
|
|
2244
|
+
let span = order[spanI], spanEnd = span.side(forward, dir);
|
|
2245
|
+
// End of span
|
|
2246
|
+
if (startIndex == spanEnd) {
|
|
2247
|
+
let nextI = spanI += forward ? 1 : -1;
|
|
2248
|
+
if (nextI < 0 || nextI >= order.length)
|
|
2249
|
+
return null;
|
|
2250
|
+
span = order[spanI = nextI];
|
|
2251
|
+
startIndex = span.side(!forward, dir);
|
|
2252
|
+
spanEnd = span.side(forward, dir);
|
|
2127
2253
|
}
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2254
|
+
let nextIndex = findClusterBreak(line.text, startIndex, span.forward(forward, dir));
|
|
2255
|
+
if (nextIndex < span.from || nextIndex > span.to)
|
|
2256
|
+
nextIndex = spanEnd;
|
|
2257
|
+
movedOver = line.text.slice(Math.min(startIndex, nextIndex), Math.max(startIndex, nextIndex));
|
|
2258
|
+
let nextSpan = spanI == (forward ? order.length - 1 : 0) ? null : order[spanI + (forward ? 1 : -1)];
|
|
2259
|
+
if (nextSpan && nextIndex == spanEnd && nextSpan.level + (forward ? 0 : 1) < span.level)
|
|
2260
|
+
return EditorSelection.cursor(nextSpan.side(!forward, dir) + line.from, nextSpan.forward(forward, dir) ? 1 : -1, nextSpan.level);
|
|
2261
|
+
return EditorSelection.cursor(nextIndex + line.from, span.forward(forward, dir) ? -1 : 1, span.level);
|
|
2262
|
+
}
|
|
2263
|
+
function autoDirection(text, from, to) {
|
|
2264
|
+
for (let i = from; i < to; i++) {
|
|
2265
|
+
let type = charType(text.charCodeAt(i));
|
|
2266
|
+
if (type == 1 /* T.L */)
|
|
2267
|
+
return LTR;
|
|
2268
|
+
if (type == 2 /* T.R */ || type == 4 /* T.AL */)
|
|
2269
|
+
return RTL;
|
|
2133
2270
|
}
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2271
|
+
return LTR;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
const clickAddsSelectionRange = /*@__PURE__*/Facet.define();
|
|
2275
|
+
const dragMovesSelection$1 = /*@__PURE__*/Facet.define();
|
|
2276
|
+
const mouseSelectionStyle = /*@__PURE__*/Facet.define();
|
|
2277
|
+
const exceptionSink = /*@__PURE__*/Facet.define();
|
|
2278
|
+
const updateListener = /*@__PURE__*/Facet.define();
|
|
2279
|
+
const inputHandler = /*@__PURE__*/Facet.define();
|
|
2280
|
+
const focusChangeEffect = /*@__PURE__*/Facet.define();
|
|
2281
|
+
const perLineTextDirection = /*@__PURE__*/Facet.define({
|
|
2282
|
+
combine: values => values.some(x => x)
|
|
2283
|
+
});
|
|
2284
|
+
const nativeSelectionHidden = /*@__PURE__*/Facet.define({
|
|
2285
|
+
combine: values => values.some(x => x)
|
|
2286
|
+
});
|
|
2287
|
+
class ScrollTarget {
|
|
2288
|
+
constructor(range, y = "nearest", x = "nearest", yMargin = 5, xMargin = 5,
|
|
2289
|
+
// This data structure is abused to also store precise scroll
|
|
2290
|
+
// snapshots, instead of a `scrollIntoView` request. When this
|
|
2291
|
+
// flag is `true`, `range` points at a position in the reference
|
|
2292
|
+
// line, `yMargin` holds the difference between the top of that
|
|
2293
|
+
// line and the top of the editor, and `xMargin` holds the
|
|
2294
|
+
// editor's `scrollLeft`.
|
|
2295
|
+
isSnapshot = false) {
|
|
2296
|
+
this.range = range;
|
|
2297
|
+
this.y = y;
|
|
2298
|
+
this.x = x;
|
|
2299
|
+
this.yMargin = yMargin;
|
|
2300
|
+
this.xMargin = xMargin;
|
|
2301
|
+
this.isSnapshot = isSnapshot;
|
|
2139
2302
|
}
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2303
|
+
map(changes) {
|
|
2304
|
+
return changes.empty ? this :
|
|
2305
|
+
new ScrollTarget(this.range.map(changes), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
|
|
2306
|
+
}
|
|
2307
|
+
clip(state) {
|
|
2308
|
+
return this.range.to <= state.doc.length ? this :
|
|
2309
|
+
new ScrollTarget(EditorSelection.cursor(state.doc.length), this.y, this.x, this.yMargin, this.xMargin, this.isSnapshot);
|
|
2145
2310
|
}
|
|
2146
|
-
/**
|
|
2147
|
-
@internal
|
|
2148
|
-
*/
|
|
2149
|
-
get empty() { return this.flags == 0 && this.transactions.length == 0; }
|
|
2150
2311
|
}
|
|
2151
|
-
|
|
2312
|
+
const scrollIntoView = /*@__PURE__*/StateEffect.define({ map: (t, ch) => t.map(ch) });
|
|
2152
2313
|
/**
|
|
2153
|
-
|
|
2314
|
+
Log or report an unhandled exception in client code. Should
|
|
2315
|
+
probably only be used by extension code that allows client code to
|
|
2316
|
+
provide functions, and calls those functions in a context where an
|
|
2317
|
+
exception can't be propagated to calling code in a reasonable way
|
|
2318
|
+
(for example when in an event handler).
|
|
2319
|
+
|
|
2320
|
+
Either calls a handler registered with
|
|
2321
|
+
[`EditorView.exceptionSink`](https://codemirror.net/6/docs/ref/#view.EditorView^exceptionSink),
|
|
2322
|
+
`window.onerror`, if defined, or `console.error` (in which case
|
|
2323
|
+
it'll pass `context`, when given, as first argument).
|
|
2154
2324
|
*/
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
Direction[Direction["RTL"] = 1] = "RTL";
|
|
2166
|
-
return Direction})(Direction || (Direction = {}));
|
|
2167
|
-
const LTR = Direction.LTR, RTL = Direction.RTL;
|
|
2168
|
-
// Decode a string with each type encoded as log2(type)
|
|
2169
|
-
function dec(str) {
|
|
2170
|
-
let result = [];
|
|
2171
|
-
for (let i = 0; i < str.length; i++)
|
|
2172
|
-
result.push(1 << +str[i]);
|
|
2173
|
-
return result;
|
|
2174
|
-
}
|
|
2175
|
-
// Character types for codepoints 0 to 0xf8
|
|
2176
|
-
const LowTypes = /*@__PURE__*/dec("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008");
|
|
2177
|
-
// Character types for codepoints 0x600 to 0x6f9
|
|
2178
|
-
const ArabicTypes = /*@__PURE__*/dec("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333");
|
|
2179
|
-
const Brackets = /*@__PURE__*/Object.create(null), BracketStack = [];
|
|
2180
|
-
// There's a lot more in
|
|
2181
|
-
// https://www.unicode.org/Public/UCD/latest/ucd/BidiBrackets.txt,
|
|
2182
|
-
// which are left out to keep code size down.
|
|
2183
|
-
for (let p of ["()", "[]", "{}"]) {
|
|
2184
|
-
let l = /*@__PURE__*/p.charCodeAt(0), r = /*@__PURE__*/p.charCodeAt(1);
|
|
2185
|
-
Brackets[l] = r;
|
|
2186
|
-
Brackets[r] = -l;
|
|
2187
|
-
}
|
|
2188
|
-
function charType(ch) {
|
|
2189
|
-
return ch <= 0xf7 ? LowTypes[ch] :
|
|
2190
|
-
0x590 <= ch && ch <= 0x5f4 ? 2 /* T.R */ :
|
|
2191
|
-
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
2192
|
-
0x6ee <= ch && ch <= 0x8ac ? 4 /* T.AL */ :
|
|
2193
|
-
0x2000 <= ch && ch <= 0x200c ? 256 /* T.NI */ :
|
|
2194
|
-
0xfb50 <= ch && ch <= 0xfdff ? 4 /* T.AL */ : 1 /* T.L */;
|
|
2325
|
+
function logException(state, exception, context) {
|
|
2326
|
+
let handler = state.facet(exceptionSink);
|
|
2327
|
+
if (handler.length)
|
|
2328
|
+
handler[0](exception);
|
|
2329
|
+
else if (window.onerror)
|
|
2330
|
+
window.onerror(String(exception), context, undefined, undefined, exception);
|
|
2331
|
+
else if (context)
|
|
2332
|
+
console.error(context + ":", exception);
|
|
2333
|
+
else
|
|
2334
|
+
console.error(exception);
|
|
2195
2335
|
}
|
|
2196
|
-
const
|
|
2336
|
+
const editable = /*@__PURE__*/Facet.define({ combine: values => values.length ? values[0] : true });
|
|
2337
|
+
let nextPluginID = 0;
|
|
2338
|
+
const viewPlugin = /*@__PURE__*/Facet.define();
|
|
2197
2339
|
/**
|
|
2198
|
-
|
|
2199
|
-
|
|
2340
|
+
View plugins associate stateful values with a view. They can
|
|
2341
|
+
influence the way the content is drawn, and are notified of things
|
|
2342
|
+
that happen in the view.
|
|
2200
2343
|
*/
|
|
2201
|
-
class
|
|
2202
|
-
/**
|
|
2203
|
-
The direction of this span.
|
|
2204
|
-
*/
|
|
2205
|
-
get dir() { return this.level % 2 ? RTL : LTR; }
|
|
2206
|
-
/**
|
|
2207
|
-
@internal
|
|
2208
|
-
*/
|
|
2344
|
+
class ViewPlugin {
|
|
2209
2345
|
constructor(
|
|
2210
2346
|
/**
|
|
2211
|
-
|
|
2212
|
-
*/
|
|
2213
|
-
|
|
2214
|
-
/**
|
|
2215
|
-
|
|
2216
|
-
*/
|
|
2217
|
-
|
|
2218
|
-
/**
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
*/
|
|
2225
|
-
|
|
2226
|
-
this.
|
|
2227
|
-
this.
|
|
2228
|
-
this.
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
return
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
function isolatesEq(a, b) {
|
|
2257
|
-
if (a.length != b.length)
|
|
2258
|
-
return false;
|
|
2259
|
-
for (let i = 0; i < a.length; i++) {
|
|
2260
|
-
let iA = a[i], iB = b[i];
|
|
2261
|
-
if (iA.from != iB.from || iA.to != iB.to || iA.direction != iB.direction || !isolatesEq(iA.inner, iB.inner))
|
|
2262
|
-
return false;
|
|
2263
|
-
}
|
|
2264
|
-
return true;
|
|
2265
|
-
}
|
|
2266
|
-
// Reused array of character types
|
|
2267
|
-
const types = [];
|
|
2268
|
-
// Fill in the character types (in `types`) from `from` to `to` and
|
|
2269
|
-
// apply W normalization rules.
|
|
2270
|
-
function computeCharTypes(line, rFrom, rTo, isolates, outerType) {
|
|
2271
|
-
for (let iI = 0; iI <= isolates.length; iI++) {
|
|
2272
|
-
let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
2273
|
-
let prevType = iI ? 256 /* T.NI */ : outerType;
|
|
2274
|
-
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
|
2275
|
-
// change the type of the NSM to the type of the previous
|
|
2276
|
-
// character. If the NSM is at the start of the level run, it will
|
|
2277
|
-
// get the type of sor.
|
|
2278
|
-
// W2. Search backwards from each instance of a European number
|
|
2279
|
-
// until the first strong type (R, L, AL, or sor) is found. If an
|
|
2280
|
-
// AL is found, change the type of the European number to Arabic
|
|
2281
|
-
// number.
|
|
2282
|
-
// W3. Change all ALs to R.
|
|
2283
|
-
// (Left after this: L, R, EN, AN, ET, CS, NI)
|
|
2284
|
-
for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {
|
|
2285
|
-
let type = charType(line.charCodeAt(i));
|
|
2286
|
-
if (type == 512 /* T.NSM */)
|
|
2287
|
-
type = prev;
|
|
2288
|
-
else if (type == 8 /* T.EN */ && prevStrong == 4 /* T.AL */)
|
|
2289
|
-
type = 16 /* T.AN */;
|
|
2290
|
-
types[i] = type == 4 /* T.AL */ ? 2 /* T.R */ : type;
|
|
2291
|
-
if (type & 7 /* T.Strong */)
|
|
2292
|
-
prevStrong = type;
|
|
2293
|
-
prev = type;
|
|
2294
|
-
}
|
|
2295
|
-
// W5. A sequence of European terminators adjacent to European
|
|
2296
|
-
// numbers changes to all European numbers.
|
|
2297
|
-
// W6. Otherwise, separators and terminators change to Other
|
|
2298
|
-
// Neutral.
|
|
2299
|
-
// W7. Search backwards from each instance of a European number
|
|
2300
|
-
// until the first strong type (R, L, or sor) is found. If an L is
|
|
2301
|
-
// found, then change the type of the European number to L.
|
|
2302
|
-
// (Left after this: L, R, EN+AN, NI)
|
|
2303
|
-
for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {
|
|
2304
|
-
let type = types[i];
|
|
2305
|
-
if (type == 128 /* T.CS */) {
|
|
2306
|
-
if (i < to - 1 && prev == types[i + 1] && (prev & 24 /* T.Num */))
|
|
2307
|
-
type = types[i] = prev;
|
|
2308
|
-
else
|
|
2309
|
-
types[i] = 256 /* T.NI */;
|
|
2310
|
-
}
|
|
2311
|
-
else if (type == 64 /* T.ET */) {
|
|
2312
|
-
let end = i + 1;
|
|
2313
|
-
while (end < to && types[end] == 64 /* T.ET */)
|
|
2314
|
-
end++;
|
|
2315
|
-
let replace = (i && prev == 8 /* T.EN */) || (end < rTo && types[end] == 8 /* T.EN */) ? (prevStrong == 1 /* T.L */ ? 1 /* T.L */ : 8 /* T.EN */) : 256 /* T.NI */;
|
|
2316
|
-
for (let j = i; j < end; j++)
|
|
2317
|
-
types[j] = replace;
|
|
2318
|
-
i = end - 1;
|
|
2319
|
-
}
|
|
2320
|
-
else if (type == 8 /* T.EN */ && prevStrong == 1 /* T.L */) {
|
|
2321
|
-
types[i] = 1 /* T.L */;
|
|
2322
|
-
}
|
|
2323
|
-
prev = type;
|
|
2324
|
-
if (type & 7 /* T.Strong */)
|
|
2325
|
-
prevStrong = type;
|
|
2326
|
-
}
|
|
2347
|
+
@internal
|
|
2348
|
+
*/
|
|
2349
|
+
id,
|
|
2350
|
+
/**
|
|
2351
|
+
@internal
|
|
2352
|
+
*/
|
|
2353
|
+
create,
|
|
2354
|
+
/**
|
|
2355
|
+
@internal
|
|
2356
|
+
*/
|
|
2357
|
+
domEventHandlers,
|
|
2358
|
+
/**
|
|
2359
|
+
@internal
|
|
2360
|
+
*/
|
|
2361
|
+
domEventObservers, buildExtensions) {
|
|
2362
|
+
this.id = id;
|
|
2363
|
+
this.create = create;
|
|
2364
|
+
this.domEventHandlers = domEventHandlers;
|
|
2365
|
+
this.domEventObservers = domEventObservers;
|
|
2366
|
+
this.extension = buildExtensions(this);
|
|
2367
|
+
}
|
|
2368
|
+
/**
|
|
2369
|
+
Define a plugin from a constructor function that creates the
|
|
2370
|
+
plugin's value, given an editor view.
|
|
2371
|
+
*/
|
|
2372
|
+
static define(create, spec) {
|
|
2373
|
+
const { eventHandlers, eventObservers, provide, decorations: deco } = spec || {};
|
|
2374
|
+
return new ViewPlugin(nextPluginID++, create, eventHandlers, eventObservers, plugin => {
|
|
2375
|
+
let ext = [viewPlugin.of(plugin)];
|
|
2376
|
+
if (deco)
|
|
2377
|
+
ext.push(decorations.of(view => {
|
|
2378
|
+
let pluginInst = view.plugin(plugin);
|
|
2379
|
+
return pluginInst ? deco(pluginInst) : Decoration.none;
|
|
2380
|
+
}));
|
|
2381
|
+
if (provide)
|
|
2382
|
+
ext.push(provide(plugin));
|
|
2383
|
+
return ext;
|
|
2384
|
+
});
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
Create a plugin for a class whose constructor takes a single
|
|
2388
|
+
editor view as argument.
|
|
2389
|
+
*/
|
|
2390
|
+
static fromClass(cls, spec) {
|
|
2391
|
+
return ViewPlugin.define(view => new cls(view), spec);
|
|
2327
2392
|
}
|
|
2328
2393
|
}
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
//
|
|
2335
|
-
//
|
|
2336
|
-
|
|
2337
|
-
//
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
let type = (flags & 2 /* Bracketed.EmbedInside */) ? outerType :
|
|
2347
|
-
!(flags & 4 /* Bracketed.OppositeInside */) ? 0 :
|
|
2348
|
-
(flags & 1 /* Bracketed.OppositeBefore */) ? oppositeType : outerType;
|
|
2349
|
-
if (type)
|
|
2350
|
-
types[i] = types[BracketStack[sJ]] = type;
|
|
2351
|
-
sI = sJ;
|
|
2352
|
-
break;
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
}
|
|
2356
|
-
else if (BracketStack.length == 189 /* Bracketed.MaxDepth */) {
|
|
2357
|
-
break;
|
|
2394
|
+
class PluginInstance {
|
|
2395
|
+
constructor(spec) {
|
|
2396
|
+
this.spec = spec;
|
|
2397
|
+
// When starting an update, all plugins have this field set to the
|
|
2398
|
+
// update object, indicating they need to be updated. When finished
|
|
2399
|
+
// updating, it is set to `false`. Retrieving a plugin that needs to
|
|
2400
|
+
// be updated with `view.plugin` forces an eager update.
|
|
2401
|
+
this.mustUpdate = null;
|
|
2402
|
+
// This is null when the plugin is initially created, but
|
|
2403
|
+
// initialized on the first update.
|
|
2404
|
+
this.value = null;
|
|
2405
|
+
}
|
|
2406
|
+
update(view) {
|
|
2407
|
+
if (!this.value) {
|
|
2408
|
+
if (this.spec) {
|
|
2409
|
+
try {
|
|
2410
|
+
this.value = this.spec.create(view);
|
|
2358
2411
|
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
BracketStack[sI++] = context;
|
|
2412
|
+
catch (e) {
|
|
2413
|
+
logException(view.state, e, "CodeMirror plugin crashed");
|
|
2414
|
+
this.deactivate();
|
|
2363
2415
|
}
|
|
2364
2416
|
}
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2417
|
+
}
|
|
2418
|
+
else if (this.mustUpdate) {
|
|
2419
|
+
let update = this.mustUpdate;
|
|
2420
|
+
this.mustUpdate = null;
|
|
2421
|
+
if (this.value.update) {
|
|
2422
|
+
try {
|
|
2423
|
+
this.value.update(update);
|
|
2424
|
+
}
|
|
2425
|
+
catch (e) {
|
|
2426
|
+
logException(update.state, e, "CodeMirror plugin crashed");
|
|
2427
|
+
if (this.value.destroy)
|
|
2428
|
+
try {
|
|
2429
|
+
this.value.destroy();
|
|
2430
|
+
}
|
|
2431
|
+
catch (_) { }
|
|
2432
|
+
this.deactivate();
|
|
2380
2433
|
}
|
|
2381
2434
|
}
|
|
2382
2435
|
}
|
|
2436
|
+
return this;
|
|
2383
2437
|
}
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
// surrounding strong text if the text on both sides has the same
|
|
2390
|
-
// direction. European and Arabic numbers act as if they were R in
|
|
2391
|
-
// terms of their influence on neutrals. Start-of-level-run (sor)
|
|
2392
|
-
// and end-of-level-run (eor) are used at level run boundaries.
|
|
2393
|
-
// N2. Any remaining neutrals take the embedding direction.
|
|
2394
|
-
// (Left after this: L, R, EN+AN)
|
|
2395
|
-
for (let i = from; i < to;) {
|
|
2396
|
-
let type = types[i];
|
|
2397
|
-
if (type == 256 /* T.NI */) {
|
|
2398
|
-
let end = i + 1;
|
|
2399
|
-
for (;;) {
|
|
2400
|
-
if (end == to) {
|
|
2401
|
-
if (iI == isolates.length)
|
|
2402
|
-
break;
|
|
2403
|
-
end = isolates[iI++].to;
|
|
2404
|
-
to = iI < isolates.length ? isolates[iI].from : rTo;
|
|
2405
|
-
}
|
|
2406
|
-
else if (types[end] == 256 /* T.NI */) {
|
|
2407
|
-
end++;
|
|
2408
|
-
}
|
|
2409
|
-
else {
|
|
2410
|
-
break;
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
let beforeL = prev == 1 /* T.L */;
|
|
2414
|
-
let afterL = (end < rTo ? types[end] : outerType) == 1 /* T.L */;
|
|
2415
|
-
let replace = beforeL == afterL ? (beforeL ? 1 /* T.L */ : 2 /* T.R */) : outerType;
|
|
2416
|
-
for (let j = end, jI = iI, fromJ = jI ? isolates[jI - 1].to : rFrom; j > i;) {
|
|
2417
|
-
if (j == fromJ) {
|
|
2418
|
-
j = isolates[--jI].from;
|
|
2419
|
-
fromJ = jI ? isolates[jI - 1].to : rFrom;
|
|
2420
|
-
}
|
|
2421
|
-
types[--j] = replace;
|
|
2422
|
-
}
|
|
2423
|
-
i = end;
|
|
2438
|
+
destroy(view) {
|
|
2439
|
+
var _a;
|
|
2440
|
+
if ((_a = this.value) === null || _a === void 0 ? void 0 : _a.destroy) {
|
|
2441
|
+
try {
|
|
2442
|
+
this.value.destroy();
|
|
2424
2443
|
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
i++;
|
|
2444
|
+
catch (e) {
|
|
2445
|
+
logException(view.state, e, "CodeMirror plugin crashed");
|
|
2428
2446
|
}
|
|
2429
2447
|
}
|
|
2430
2448
|
}
|
|
2449
|
+
deactivate() {
|
|
2450
|
+
this.spec = this.value = null;
|
|
2451
|
+
}
|
|
2431
2452
|
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
//
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
run: for (;;) {
|
|
2459
|
-
if (iI < isolates.length && iScan == isolates[iI].from) {
|
|
2460
|
-
if (isNum)
|
|
2461
|
-
break run;
|
|
2462
|
-
let iso = isolates[iI];
|
|
2463
|
-
// Scan ahead to verify that there is another char in this dir after the isolate(s)
|
|
2464
|
-
if (!sameDir)
|
|
2465
|
-
for (let upto = iso.to, jI = iI + 1;;) {
|
|
2466
|
-
if (upto == to)
|
|
2467
|
-
break run;
|
|
2468
|
-
if (jI < isolates.length && isolates[jI].from == upto)
|
|
2469
|
-
upto = isolates[jI++].to;
|
|
2470
|
-
else if (types[upto] == ourType)
|
|
2471
|
-
break run;
|
|
2472
|
-
else
|
|
2473
|
-
break;
|
|
2474
|
-
}
|
|
2475
|
-
iI++;
|
|
2476
|
-
if (recurse) {
|
|
2477
|
-
recurse.push(iso);
|
|
2478
|
-
}
|
|
2479
|
-
else {
|
|
2480
|
-
if (iso.from > iCh)
|
|
2481
|
-
order.push(new BidiSpan(iCh, iso.from, localLevel));
|
|
2482
|
-
let dirSwap = (iso.direction == LTR) != !(localLevel % 2);
|
|
2483
|
-
computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);
|
|
2484
|
-
iCh = iso.to;
|
|
2485
|
-
}
|
|
2486
|
-
iScan = iso.to;
|
|
2487
|
-
}
|
|
2488
|
-
else if (iScan == to || (sameDir ? types[iScan] != ourType : types[iScan] == ourType)) {
|
|
2489
|
-
break;
|
|
2453
|
+
const editorAttributes = /*@__PURE__*/Facet.define();
|
|
2454
|
+
const contentAttributes = /*@__PURE__*/Facet.define();
|
|
2455
|
+
// Provide decorations
|
|
2456
|
+
const decorations = /*@__PURE__*/Facet.define();
|
|
2457
|
+
const outerDecorations = /*@__PURE__*/Facet.define();
|
|
2458
|
+
const atomicRanges = /*@__PURE__*/Facet.define();
|
|
2459
|
+
const bidiIsolatedRanges = /*@__PURE__*/Facet.define();
|
|
2460
|
+
function getIsolatedRanges(view, line) {
|
|
2461
|
+
let isolates = view.state.facet(bidiIsolatedRanges);
|
|
2462
|
+
if (!isolates.length)
|
|
2463
|
+
return isolates;
|
|
2464
|
+
let sets = isolates.map(i => i instanceof Function ? i(view) : i);
|
|
2465
|
+
let result = [];
|
|
2466
|
+
RangeSet.spans(sets, line.from, line.to, {
|
|
2467
|
+
point() { },
|
|
2468
|
+
span(fromDoc, toDoc, active, open) {
|
|
2469
|
+
let from = fromDoc - line.from, to = toDoc - line.from;
|
|
2470
|
+
let level = result;
|
|
2471
|
+
for (let i = active.length - 1; i >= 0; i--, open--) {
|
|
2472
|
+
let direction = active[i].spec.bidiIsolate, update;
|
|
2473
|
+
if (direction == null)
|
|
2474
|
+
direction = autoDirection(line.text, from, to);
|
|
2475
|
+
if (open > 0 && level.length &&
|
|
2476
|
+
(update = level[level.length - 1]).to == from && update.direction == direction) {
|
|
2477
|
+
update.to = to;
|
|
2478
|
+
level = update.inner;
|
|
2490
2479
|
}
|
|
2491
2480
|
else {
|
|
2492
|
-
|
|
2481
|
+
let add = { from, to, direction, inner: [] };
|
|
2482
|
+
level.push(add);
|
|
2483
|
+
level = add.inner;
|
|
2493
2484
|
}
|
|
2494
2485
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2486
|
+
}
|
|
2487
|
+
});
|
|
2488
|
+
return result;
|
|
2489
|
+
}
|
|
2490
|
+
const scrollMargins = /*@__PURE__*/Facet.define();
|
|
2491
|
+
function getScrollMargins(view) {
|
|
2492
|
+
let left = 0, right = 0, top = 0, bottom = 0;
|
|
2493
|
+
for (let source of view.state.facet(scrollMargins)) {
|
|
2494
|
+
let m = source(view);
|
|
2495
|
+
if (m) {
|
|
2496
|
+
if (m.left != null)
|
|
2497
|
+
left = Math.max(left, m.left);
|
|
2498
|
+
if (m.right != null)
|
|
2499
|
+
right = Math.max(right, m.right);
|
|
2500
|
+
if (m.top != null)
|
|
2501
|
+
top = Math.max(top, m.top);
|
|
2502
|
+
if (m.bottom != null)
|
|
2503
|
+
bottom = Math.max(bottom, m.bottom);
|
|
2500
2504
|
}
|
|
2501
2505
|
}
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
iCh = iso.from;
|
|
2543
|
-
}
|
|
2544
|
-
iScan = iso.from;
|
|
2545
|
-
}
|
|
2546
|
-
else if (iScan == from || (sameDir ? types[iScan - 1] != ourType : types[iScan - 1] == ourType)) {
|
|
2506
|
+
return { left, right, top, bottom };
|
|
2507
|
+
}
|
|
2508
|
+
const styleModule = /*@__PURE__*/Facet.define();
|
|
2509
|
+
class ChangedRange {
|
|
2510
|
+
constructor(fromA, toA, fromB, toB) {
|
|
2511
|
+
this.fromA = fromA;
|
|
2512
|
+
this.toA = toA;
|
|
2513
|
+
this.fromB = fromB;
|
|
2514
|
+
this.toB = toB;
|
|
2515
|
+
}
|
|
2516
|
+
join(other) {
|
|
2517
|
+
return new ChangedRange(Math.min(this.fromA, other.fromA), Math.max(this.toA, other.toA), Math.min(this.fromB, other.fromB), Math.max(this.toB, other.toB));
|
|
2518
|
+
}
|
|
2519
|
+
addToSet(set) {
|
|
2520
|
+
let i = set.length, me = this;
|
|
2521
|
+
for (; i > 0; i--) {
|
|
2522
|
+
let range = set[i - 1];
|
|
2523
|
+
if (range.fromA > me.toA)
|
|
2524
|
+
continue;
|
|
2525
|
+
if (range.toA < me.fromA)
|
|
2526
|
+
break;
|
|
2527
|
+
me = me.join(range);
|
|
2528
|
+
set.splice(i - 1, 1);
|
|
2529
|
+
}
|
|
2530
|
+
set.splice(i, 0, me);
|
|
2531
|
+
return set;
|
|
2532
|
+
}
|
|
2533
|
+
static extendWithRanges(diff, ranges) {
|
|
2534
|
+
if (ranges.length == 0)
|
|
2535
|
+
return diff;
|
|
2536
|
+
let result = [];
|
|
2537
|
+
for (let dI = 0, rI = 0, posA = 0, posB = 0;; dI++) {
|
|
2538
|
+
let next = dI == diff.length ? null : diff[dI], off = posA - posB;
|
|
2539
|
+
let end = next ? next.fromB : 1e9;
|
|
2540
|
+
while (rI < ranges.length && ranges[rI] < end) {
|
|
2541
|
+
let from = ranges[rI], to = ranges[rI + 1];
|
|
2542
|
+
let fromB = Math.max(posB, from), toB = Math.min(end, to);
|
|
2543
|
+
if (fromB <= toB)
|
|
2544
|
+
new ChangedRange(fromB + off, toB + off, fromB, toB).addToSet(result);
|
|
2545
|
+
if (to > end)
|
|
2547
2546
|
break;
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
iScan--;
|
|
2551
|
-
}
|
|
2547
|
+
else
|
|
2548
|
+
rI += 2;
|
|
2552
2549
|
}
|
|
2553
|
-
if (
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2550
|
+
if (!next)
|
|
2551
|
+
return result;
|
|
2552
|
+
new ChangedRange(next.fromA, next.toA, next.fromB, next.toB).addToSet(result);
|
|
2553
|
+
posA = next.toA;
|
|
2554
|
+
posB = next.toB;
|
|
2558
2555
|
}
|
|
2559
2556
|
}
|
|
2560
2557
|
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
}
|
|
2558
|
+
/**
|
|
2559
|
+
View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given instances of this
|
|
2560
|
+
class, which describe what happened, whenever the view is updated.
|
|
2561
|
+
*/
|
|
2562
|
+
class ViewUpdate {
|
|
2563
|
+
constructor(
|
|
2564
|
+
/**
|
|
2565
|
+
The editor view that the update is associated with.
|
|
2566
|
+
*/
|
|
2567
|
+
view,
|
|
2568
|
+
/**
|
|
2569
|
+
The new editor state.
|
|
2570
|
+
*/
|
|
2571
|
+
state,
|
|
2572
|
+
/**
|
|
2573
|
+
The transactions involved in the update. May be empty.
|
|
2574
|
+
*/
|
|
2575
|
+
transactions) {
|
|
2576
|
+
this.view = view;
|
|
2577
|
+
this.state = state;
|
|
2578
|
+
this.transactions = transactions;
|
|
2579
|
+
/**
|
|
2580
|
+
@internal
|
|
2581
|
+
*/
|
|
2582
|
+
this.flags = 0;
|
|
2583
|
+
this.startState = view.state;
|
|
2584
|
+
this.changes = ChangeSet.empty(this.startState.doc.length);
|
|
2585
|
+
for (let tr of transactions)
|
|
2586
|
+
this.changes = this.changes.compose(tr.changes);
|
|
2587
|
+
let changedRanges = [];
|
|
2588
|
+
this.changes.iterChangedRanges((fromA, toA, fromB, toB) => changedRanges.push(new ChangedRange(fromA, toA, fromB, toB)));
|
|
2589
|
+
this.changedRanges = changedRanges;
|
|
2594
2590
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
startIndex = last.side(true, dir);
|
|
2601
|
-
spanI = order.length - 1;
|
|
2602
|
-
}
|
|
2603
|
-
}
|
|
2604
|
-
if (spanI < 0)
|
|
2605
|
-
spanI = BidiSpan.find(order, startIndex, (_a = start.bidiLevel) !== null && _a !== void 0 ? _a : -1, start.assoc);
|
|
2606
|
-
let span = order[spanI];
|
|
2607
|
-
// End of span. (But not end of line--that was checked for above.)
|
|
2608
|
-
if (startIndex == span.side(forward, dir)) {
|
|
2609
|
-
span = order[spanI += forward ? 1 : -1];
|
|
2610
|
-
startIndex = span.side(!forward, dir);
|
|
2591
|
+
/**
|
|
2592
|
+
@internal
|
|
2593
|
+
*/
|
|
2594
|
+
static create(view, state, transactions) {
|
|
2595
|
+
return new ViewUpdate(view, state, transactions);
|
|
2611
2596
|
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2597
|
+
/**
|
|
2598
|
+
Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
|
|
2599
|
+
[visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
|
|
2600
|
+
update.
|
|
2601
|
+
*/
|
|
2602
|
+
get viewportChanged() {
|
|
2603
|
+
return (this.flags & 4 /* UpdateFlag.Viewport */) > 0;
|
|
2604
|
+
}
|
|
2605
|
+
/**
|
|
2606
|
+
Indicates whether the height of a block element in the editor
|
|
2607
|
+
changed in this update.
|
|
2608
|
+
*/
|
|
2609
|
+
get heightChanged() {
|
|
2610
|
+
return (this.flags & 2 /* UpdateFlag.Height */) > 0;
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2613
|
+
Returns true when the document was modified or the size of the
|
|
2614
|
+
editor, or elements within the editor, changed.
|
|
2615
|
+
*/
|
|
2616
|
+
get geometryChanged() {
|
|
2617
|
+
return this.docChanged || (this.flags & (8 /* UpdateFlag.Geometry */ | 2 /* UpdateFlag.Height */)) > 0;
|
|
2618
|
+
}
|
|
2619
|
+
/**
|
|
2620
|
+
True when this update indicates a focus change.
|
|
2621
|
+
*/
|
|
2622
|
+
get focusChanged() {
|
|
2623
|
+
return (this.flags & 1 /* UpdateFlag.Focus */) > 0;
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
Whether the document changed in this update.
|
|
2627
|
+
*/
|
|
2628
|
+
get docChanged() {
|
|
2629
|
+
return !this.changes.empty;
|
|
2630
|
+
}
|
|
2631
|
+
/**
|
|
2632
|
+
Whether the selection was explicitly set in this update.
|
|
2633
|
+
*/
|
|
2634
|
+
get selectionSet() {
|
|
2635
|
+
return this.transactions.some(tr => tr.selection);
|
|
2636
|
+
}
|
|
2637
|
+
/**
|
|
2638
|
+
@internal
|
|
2639
|
+
*/
|
|
2640
|
+
get empty() { return this.flags == 0 && this.transactions.length == 0; }
|
|
2623
2641
|
}
|
|
2624
2642
|
|
|
2625
2643
|
class DocView extends ContentView {
|
|
@@ -2829,9 +2847,8 @@ class DocView extends ContentView {
|
|
|
2829
2847
|
}
|
|
2830
2848
|
let domSel = this.view.observer.selectionRange;
|
|
2831
2849
|
// If the selection is already here, or in an equivalent position, don't touch it
|
|
2832
|
-
if (force || !domSel.focusNode ||
|
|
2833
|
-
!isEquivalentPosition(
|
|
2834
|
-
!isEquivalentPosition(head.node, head.offset, domSel.focusNode, domSel.focusOffset)) {
|
|
2850
|
+
if (force || !domSel.focusNode || (!isEquivalentPosition(anchor.node, anchor.offset, domSel.anchorNode, domSel.anchorOffset) ||
|
|
2851
|
+
!isEquivalentPosition(head.node, head.offset, domSel.focusNode, domSel.focusOffset)) && !this.suppressWidgetCursorChange(domSel, main)) {
|
|
2835
2852
|
this.view.observer.ignore(() => {
|
|
2836
2853
|
// Chrome Android will hide the virtual keyboard when tapping
|
|
2837
2854
|
// inside an uneditable node, and not bring it back when we
|
|
@@ -2892,6 +2909,14 @@ class DocView extends ContentView {
|
|
|
2892
2909
|
this.impreciseAnchor = anchor.precise ? null : new DOMPos(domSel.anchorNode, domSel.anchorOffset);
|
|
2893
2910
|
this.impreciseHead = head.precise ? null : new DOMPos(domSel.focusNode, domSel.focusOffset);
|
|
2894
2911
|
}
|
|
2912
|
+
// If a zero-length widget is inserted next to the cursor during
|
|
2913
|
+
// composition, avoid moving it across it and disrupting the
|
|
2914
|
+
// composition.
|
|
2915
|
+
suppressWidgetCursorChange(sel, cursor) {
|
|
2916
|
+
return this.hasComposition && cursor.empty &&
|
|
2917
|
+
isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset) &&
|
|
2918
|
+
this.posFromDOM(sel.focusNode, sel.focusOffset) == cursor.head;
|
|
2919
|
+
}
|
|
2895
2920
|
enforceCursorAssoc() {
|
|
2896
2921
|
if (this.hasComposition)
|
|
2897
2922
|
return;
|
|
@@ -3100,6 +3125,16 @@ class DocView extends ContentView {
|
|
|
3100
3125
|
let dynamic = this.dynamicDecorationMap[i] = typeof d == "function";
|
|
3101
3126
|
return dynamic ? d(this.view) : d;
|
|
3102
3127
|
});
|
|
3128
|
+
let dynamicOuter = false, outerDeco = this.view.state.facet(outerDecorations).map((d, i) => {
|
|
3129
|
+
let dynamic = typeof d == "function";
|
|
3130
|
+
if (dynamic)
|
|
3131
|
+
dynamicOuter = true;
|
|
3132
|
+
return dynamic ? d(this.view) : d;
|
|
3133
|
+
});
|
|
3134
|
+
if (outerDeco.length) {
|
|
3135
|
+
this.dynamicDecorationMap[allDeco.length] = dynamicOuter;
|
|
3136
|
+
allDeco.push(RangeSet.join(outerDeco));
|
|
3137
|
+
}
|
|
3103
3138
|
for (let i = allDeco.length; i < allDeco.length + 3; i++)
|
|
3104
3139
|
this.dynamicDecorationMap[i] = false;
|
|
3105
3140
|
return this.decorations = [
|
|
@@ -3143,6 +3178,7 @@ class BlockGapWidget extends WidgetType {
|
|
|
3143
3178
|
}
|
|
3144
3179
|
toDOM() {
|
|
3145
3180
|
let elt = document.createElement("div");
|
|
3181
|
+
elt.className = "cm-gap";
|
|
3146
3182
|
this.updateDOM(elt);
|
|
3147
3183
|
return elt;
|
|
3148
3184
|
}
|
|
@@ -3151,6 +3187,7 @@ class BlockGapWidget extends WidgetType {
|
|
|
3151
3187
|
elt.style.height = this.height + "px";
|
|
3152
3188
|
return true;
|
|
3153
3189
|
}
|
|
3190
|
+
get editable() { return true; }
|
|
3154
3191
|
get estimatedHeight() { return this.height; }
|
|
3155
3192
|
}
|
|
3156
3193
|
function findCompositionNode(view, headPos) {
|
|
@@ -3547,7 +3584,7 @@ function moveByChar(view, start, forward, by) {
|
|
|
3547
3584
|
char = "\n";
|
|
3548
3585
|
line = view.state.doc.line(line.number + (forward ? 1 : -1));
|
|
3549
3586
|
spans = view.bidiSpans(line);
|
|
3550
|
-
next =
|
|
3587
|
+
next = view.visualLineSide(line, !forward);
|
|
3551
3588
|
}
|
|
3552
3589
|
if (!check) {
|
|
3553
3590
|
if (!by)
|
|
@@ -3952,8 +3989,7 @@ class MouseSelection {
|
|
|
3952
3989
|
}
|
|
3953
3990
|
select(event) {
|
|
3954
3991
|
let { view } = this, selection = this.skipAtoms(this.style.get(event, this.extend, this.multiple));
|
|
3955
|
-
if (this.mustSelect || !selection.eq(view.state.selection)
|
|
3956
|
-
selection.main.assoc != view.state.selection.main.assoc && this.dragging === false)
|
|
3992
|
+
if (this.mustSelect || !selection.eq(view.state.selection, this.dragging === false))
|
|
3957
3993
|
this.view.dispatch({
|
|
3958
3994
|
selection,
|
|
3959
3995
|
userEvent: "select.pointer"
|
|
@@ -5881,6 +5917,9 @@ const baseTheme$1 = /*@__PURE__*/buildTheme("." + baseThemeID, {
|
|
|
5881
5917
|
"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor": {
|
|
5882
5918
|
display: "block"
|
|
5883
5919
|
},
|
|
5920
|
+
".cm-iso": {
|
|
5921
|
+
unicodeBidi: "isolate"
|
|
5922
|
+
},
|
|
5884
5923
|
".cm-announced": {
|
|
5885
5924
|
position: "fixed",
|
|
5886
5925
|
top: "-10000px"
|
|
@@ -6164,6 +6203,16 @@ class DOMChange {
|
|
|
6164
6203
|
!contains(view.contentDOM, domSel.anchorNode)
|
|
6165
6204
|
? view.state.selection.main.anchor
|
|
6166
6205
|
: view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset);
|
|
6206
|
+
// iOS will refuse to select the block gaps when doing select-all
|
|
6207
|
+
let vp = view.viewport;
|
|
6208
|
+
if (browser.ios && view.state.selection.main.empty && head != anchor &&
|
|
6209
|
+
(vp.from > 0 || vp.to < view.state.doc.length)) {
|
|
6210
|
+
let offFrom = vp.from - Math.min(head, anchor), offTo = vp.to - Math.max(head, anchor);
|
|
6211
|
+
if ((offFrom == 0 || offFrom == 1) && (offTo == 0 || offTo == -1)) {
|
|
6212
|
+
head = 0;
|
|
6213
|
+
anchor = view.state.doc.length;
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6167
6216
|
this.newSel = EditorSelection.single(anchor, head);
|
|
6168
6217
|
}
|
|
6169
6218
|
}
|
|
@@ -7453,6 +7502,17 @@ class EditorView {
|
|
|
7453
7502
|
return skipAtoms(this, start, moveByChar(this, start, forward, initial => byGroup(this, start.head, initial)));
|
|
7454
7503
|
}
|
|
7455
7504
|
/**
|
|
7505
|
+
Get the cursor position visually at the start or end of a line.
|
|
7506
|
+
Note that this may differ from the _logical_ position at its
|
|
7507
|
+
start or end (which is simply at `line.from`/`line.to`) if text
|
|
7508
|
+
at the start or end goes against the line's base text direction.
|
|
7509
|
+
*/
|
|
7510
|
+
visualLineSide(line, end) {
|
|
7511
|
+
let order = this.bidiSpans(line), dir = this.textDirectionAt(line.from);
|
|
7512
|
+
let span = order[end ? order.length - 1 : 0];
|
|
7513
|
+
return EditorSelection.cursor(span.side(end, dir) + line.from, span.forward(!end, dir) ? 1 : -1);
|
|
7514
|
+
}
|
|
7515
|
+
/**
|
|
7456
7516
|
Move to the next line boundary in the given direction. If
|
|
7457
7517
|
`includeWrap` is true, line wrapping is on, and there is a
|
|
7458
7518
|
further wrap point on the current line, the wrap point will be
|
|
@@ -7584,11 +7644,11 @@ class EditorView {
|
|
|
7584
7644
|
let dir = this.textDirectionAt(line.from), isolates;
|
|
7585
7645
|
for (let entry of this.bidiCache) {
|
|
7586
7646
|
if (entry.from == line.from && entry.dir == dir &&
|
|
7587
|
-
(entry.fresh || isolatesEq(entry.isolates, isolates = getIsolatedRanges(this, line
|
|
7647
|
+
(entry.fresh || isolatesEq(entry.isolates, isolates = getIsolatedRanges(this, line))))
|
|
7588
7648
|
return entry.order;
|
|
7589
7649
|
}
|
|
7590
7650
|
if (!isolates)
|
|
7591
|
-
isolates = getIsolatedRanges(this, line
|
|
7651
|
+
isolates = getIsolatedRanges(this, line);
|
|
7592
7652
|
let order = computeOrder(line.text, dir, isolates);
|
|
7593
7653
|
this.bidiCache.push(new CachedOrder(line.from, line.to, dir, isolates, true, order));
|
|
7594
7654
|
return order;
|
|
@@ -7833,6 +7893,16 @@ containing the decorations to
|
|
|
7833
7893
|
*/
|
|
7834
7894
|
EditorView.decorations = decorations;
|
|
7835
7895
|
/**
|
|
7896
|
+
Facet that works much like
|
|
7897
|
+
[`decorations`](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), but puts its
|
|
7898
|
+
inputs at the very bottom of the precedence stack, meaning mark
|
|
7899
|
+
decorations provided here will only be split by other, partially
|
|
7900
|
+
overlapping \`outerDecorations\` ranges, and wrap around all
|
|
7901
|
+
regular decorations. Use this for mark elements that should, as
|
|
7902
|
+
much as possible, remain in one piece.
|
|
7903
|
+
*/
|
|
7904
|
+
EditorView.outerDecorations = outerDecorations;
|
|
7905
|
+
/**
|
|
7836
7906
|
Used to provide ranges that should be treated as atoms as far as
|
|
7837
7907
|
cursor motion is concerned. This causes methods like
|
|
7838
7908
|
[`moveByChar`](https://codemirror.net/6/docs/ref/#view.EditorView.moveByChar) and
|
|
@@ -9104,9 +9174,10 @@ function crosshairCursor(options = {}) {
|
|
|
9104
9174
|
|
|
9105
9175
|
const Outside = "-10000px";
|
|
9106
9176
|
class TooltipViewManager {
|
|
9107
|
-
constructor(view, facet, createTooltipView) {
|
|
9177
|
+
constructor(view, facet, createTooltipView, removeTooltipView) {
|
|
9108
9178
|
this.facet = facet;
|
|
9109
9179
|
this.createTooltipView = createTooltipView;
|
|
9180
|
+
this.removeTooltipView = removeTooltipView;
|
|
9110
9181
|
this.input = view.state.facet(facet);
|
|
9111
9182
|
this.tooltips = this.input.filter(t => t);
|
|
9112
9183
|
this.tooltipViews = this.tooltips.map(createTooltipView);
|
|
@@ -9146,7 +9217,7 @@ class TooltipViewManager {
|
|
|
9146
9217
|
}
|
|
9147
9218
|
for (let t of this.tooltipViews)
|
|
9148
9219
|
if (tooltipViews.indexOf(t) < 0) {
|
|
9149
|
-
|
|
9220
|
+
this.removeTooltipView(t);
|
|
9150
9221
|
(_a = t.destroy) === null || _a === void 0 ? void 0 : _a.call(t);
|
|
9151
9222
|
}
|
|
9152
9223
|
if (above) {
|
|
@@ -9194,7 +9265,13 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
9194
9265
|
this.classes = view.themeClasses;
|
|
9195
9266
|
this.createContainer();
|
|
9196
9267
|
this.measureReq = { read: this.readMeasure.bind(this), write: this.writeMeasure.bind(this), key: this };
|
|
9197
|
-
this.
|
|
9268
|
+
this.resizeObserver = typeof ResizeObserver == "function" ? new ResizeObserver(() => this.measureSoon()) : null;
|
|
9269
|
+
this.manager = new TooltipViewManager(view, showTooltip, t => this.createTooltip(t), t => {
|
|
9270
|
+
if (this.resizeObserver)
|
|
9271
|
+
this.resizeObserver.unobserve(t.dom);
|
|
9272
|
+
t.dom.remove();
|
|
9273
|
+
});
|
|
9274
|
+
this.above = this.manager.tooltips.map(t => !!t.above);
|
|
9198
9275
|
this.intersectionObserver = typeof IntersectionObserver == "function" ? new IntersectionObserver(entries => {
|
|
9199
9276
|
if (Date.now() > this.lastTransaction - 50 &&
|
|
9200
9277
|
entries.length > 0 && entries[entries.length - 1].intersectionRatio < 1)
|
|
@@ -9272,10 +9349,12 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
9272
9349
|
this.container.appendChild(tooltipView.dom);
|
|
9273
9350
|
if (tooltipView.mount)
|
|
9274
9351
|
tooltipView.mount(this.view);
|
|
9352
|
+
if (this.resizeObserver)
|
|
9353
|
+
this.resizeObserver.observe(tooltipView.dom);
|
|
9275
9354
|
return tooltipView;
|
|
9276
9355
|
}
|
|
9277
9356
|
destroy() {
|
|
9278
|
-
var _a, _b;
|
|
9357
|
+
var _a, _b, _c;
|
|
9279
9358
|
this.view.win.removeEventListener("resize", this.measureSoon);
|
|
9280
9359
|
for (let tooltipView of this.manager.tooltipViews) {
|
|
9281
9360
|
tooltipView.dom.remove();
|
|
@@ -9283,7 +9362,8 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
9283
9362
|
}
|
|
9284
9363
|
if (this.parent)
|
|
9285
9364
|
this.container.remove();
|
|
9286
|
-
(_b = this.
|
|
9365
|
+
(_b = this.resizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
9366
|
+
(_c = this.intersectionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
9287
9367
|
clearTimeout(this.measureTimeout);
|
|
9288
9368
|
}
|
|
9289
9369
|
readMeasure() {
|
|
@@ -9497,7 +9577,7 @@ class HoverTooltipHost {
|
|
|
9497
9577
|
this.mounted = false;
|
|
9498
9578
|
this.dom = document.createElement("div");
|
|
9499
9579
|
this.dom.classList.add("cm-tooltip-hover");
|
|
9500
|
-
this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t));
|
|
9580
|
+
this.manager = new TooltipViewManager(view, showHoverTooltip, t => this.createHostedView(t), t => t.dom.remove());
|
|
9501
9581
|
}
|
|
9502
9582
|
createHostedView(tooltip) {
|
|
9503
9583
|
let hostedView = tooltip.create(this.view);
|