@codemirror/view 6.11.3 → 6.13.0
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 +24 -0
- package/dist/index.cjs +270 -214
- package/dist/index.d.cts +1969 -0
- package/dist/index.d.ts +24 -7
- package/dist/index.js +271 -215
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory, Annotation,
|
|
1
|
+
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory, Annotation, Prec, Transaction, 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
|
|
|
@@ -331,7 +331,7 @@ class ContentView {
|
|
|
331
331
|
constructor() {
|
|
332
332
|
this.parent = null;
|
|
333
333
|
this.dom = null;
|
|
334
|
-
this.dirty = 2 /*
|
|
334
|
+
this.dirty = 2 /* Node */;
|
|
335
335
|
}
|
|
336
336
|
get overrideDOMText() { return null; }
|
|
337
337
|
get posAtStart() {
|
|
@@ -353,7 +353,7 @@ class ContentView {
|
|
|
353
353
|
return this.posBefore(view) + view.length;
|
|
354
354
|
}
|
|
355
355
|
sync(view, track) {
|
|
356
|
-
if (this.dirty & 2 /*
|
|
356
|
+
if (this.dirty & 2 /* Node */) {
|
|
357
357
|
let parent = this.dom;
|
|
358
358
|
let prev = null, next;
|
|
359
359
|
for (let child of this.children) {
|
|
@@ -364,7 +364,7 @@ class ContentView {
|
|
|
364
364
|
child.reuseDOM(next);
|
|
365
365
|
}
|
|
366
366
|
child.sync(view, track);
|
|
367
|
-
child.dirty = 0 /*
|
|
367
|
+
child.dirty = 0 /* Not */;
|
|
368
368
|
}
|
|
369
369
|
next = prev ? prev.nextSibling : parent.firstChild;
|
|
370
370
|
if (track && !track.written && track.node == parent && next != child.dom)
|
|
@@ -384,11 +384,11 @@ class ContentView {
|
|
|
384
384
|
while (next)
|
|
385
385
|
next = rm$1(next);
|
|
386
386
|
}
|
|
387
|
-
else if (this.dirty & 1 /*
|
|
387
|
+
else if (this.dirty & 1 /* Child */) {
|
|
388
388
|
for (let child of this.children)
|
|
389
389
|
if (child.dirty) {
|
|
390
390
|
child.sync(view, track);
|
|
391
|
-
child.dirty = 0 /*
|
|
391
|
+
child.dirty = 0 /* Not */;
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
}
|
|
@@ -453,16 +453,16 @@ class ContentView {
|
|
|
453
453
|
endDOM: toI < this.children.length && toI >= 0 ? this.children[toI].dom : null };
|
|
454
454
|
}
|
|
455
455
|
markDirty(andParent = false) {
|
|
456
|
-
this.dirty |= 2 /*
|
|
456
|
+
this.dirty |= 2 /* Node */;
|
|
457
457
|
this.markParentsDirty(andParent);
|
|
458
458
|
}
|
|
459
459
|
markParentsDirty(childList) {
|
|
460
460
|
for (let parent = this.parent; parent; parent = parent.parent) {
|
|
461
461
|
if (childList)
|
|
462
|
-
parent.dirty |= 2 /*
|
|
463
|
-
if (parent.dirty & 1 /*
|
|
462
|
+
parent.dirty |= 2 /* Node */;
|
|
463
|
+
if (parent.dirty & 1 /* Child */)
|
|
464
464
|
return;
|
|
465
|
-
parent.dirty |= 1 /*
|
|
465
|
+
parent.dirty |= 1 /* Child */;
|
|
466
466
|
childList = false;
|
|
467
467
|
}
|
|
468
468
|
}
|
|
@@ -741,13 +741,13 @@ class MarkView extends ContentView {
|
|
|
741
741
|
reuseDOM(node) {
|
|
742
742
|
if (node.nodeName == this.mark.tagName.toUpperCase()) {
|
|
743
743
|
this.setDOM(node);
|
|
744
|
-
this.dirty |= 4 /*
|
|
744
|
+
this.dirty |= 4 /* Attrs */ | 2 /* Node */;
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
747
|
sync(view, track) {
|
|
748
748
|
if (!this.dom)
|
|
749
749
|
this.setDOM(this.setAttrs(document.createElement(this.mark.tagName)));
|
|
750
|
-
else if (this.dirty & 4 /*
|
|
750
|
+
else if (this.dirty & 4 /* Attrs */)
|
|
751
751
|
this.setAttrs(this.dom);
|
|
752
752
|
super.sync(view, track);
|
|
753
753
|
}
|
|
@@ -887,12 +887,13 @@ class WidgetView extends ContentView {
|
|
|
887
887
|
let rects = this.dom.getClientRects(), rect = null;
|
|
888
888
|
if (!rects.length)
|
|
889
889
|
return null;
|
|
890
|
-
|
|
890
|
+
let fromBack = this.side ? this.side < 0 : pos > 0;
|
|
891
|
+
for (let i = fromBack ? rects.length - 1 : 0;; i += (fromBack ? -1 : 1)) {
|
|
891
892
|
rect = rects[i];
|
|
892
893
|
if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom)
|
|
893
894
|
break;
|
|
894
895
|
}
|
|
895
|
-
return this.length ? rect : flattenRect(rect,
|
|
896
|
+
return this.length ? rect : flattenRect(rect, !fromBack);
|
|
896
897
|
}
|
|
897
898
|
get isEditable() { return false; }
|
|
898
899
|
get isWidget() { return true; }
|
|
@@ -1212,6 +1213,13 @@ class WidgetType {
|
|
|
1212
1213
|
*/
|
|
1213
1214
|
get estimatedHeight() { return -1; }
|
|
1214
1215
|
/**
|
|
1216
|
+
For inline widgets that are displayed inline (as opposed to
|
|
1217
|
+
`inline-block`) and introduce line breaks (through `<br>` tags
|
|
1218
|
+
or textual newlines), this must indicate the amount of line
|
|
1219
|
+
breaks they introduce. Defaults to 0.
|
|
1220
|
+
*/
|
|
1221
|
+
get lineBreaks() { return 0; }
|
|
1222
|
+
/**
|
|
1215
1223
|
Can be used to configure which kinds of events inside the widget
|
|
1216
1224
|
should be ignored by the editor. The default is to ignore all
|
|
1217
1225
|
events.
|
|
@@ -1313,8 +1321,8 @@ class Decoration extends RangeValue {
|
|
|
1313
1321
|
given position.
|
|
1314
1322
|
*/
|
|
1315
1323
|
static widget(spec) {
|
|
1316
|
-
let side = spec.side || 0, block = !!spec.block;
|
|
1317
|
-
side += block ? (side > 0 ? 300000000 /*
|
|
1324
|
+
let side = Math.max(-10000, Math.min(10000, spec.side || 0)), block = !!spec.block;
|
|
1325
|
+
side += block ? (side > 0 ? 300000000 /* BlockAfter */ : -400000000 /* BlockBefore */) : (side > 0 ? 100000000 /* InlineAfter */ : -100000000 /* InlineBefore */);
|
|
1318
1326
|
return new PointDecoration(spec, side, side, block, spec.widget || null, false);
|
|
1319
1327
|
}
|
|
1320
1328
|
/**
|
|
@@ -1324,13 +1332,13 @@ class Decoration extends RangeValue {
|
|
|
1324
1332
|
static replace(spec) {
|
|
1325
1333
|
let block = !!spec.block, startSide, endSide;
|
|
1326
1334
|
if (spec.isBlockGap) {
|
|
1327
|
-
startSide = -500000000 /*
|
|
1328
|
-
endSide = 400000000 /*
|
|
1335
|
+
startSide = -500000000 /* GapStart */;
|
|
1336
|
+
endSide = 400000000 /* GapEnd */;
|
|
1329
1337
|
}
|
|
1330
1338
|
else {
|
|
1331
1339
|
let { start, end } = getInclusive(spec, block);
|
|
1332
|
-
startSide = (start ? (block ? -300000000 /*
|
|
1333
|
-
endSide = (end ? (block ? 200000000 /*
|
|
1340
|
+
startSide = (start ? (block ? -300000000 /* BlockIncStart */ : -1 /* InlineIncStart */) : 500000000 /* NonIncStart */) - 1;
|
|
1341
|
+
endSide = (end ? (block ? 200000000 /* BlockIncEnd */ : 1 /* InlineIncEnd */) : -600000000 /* NonIncEnd */) + 1;
|
|
1334
1342
|
}
|
|
1335
1343
|
return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
|
|
1336
1344
|
}
|
|
@@ -1361,7 +1369,7 @@ Decoration.none = RangeSet.empty;
|
|
|
1361
1369
|
class MarkDecoration extends Decoration {
|
|
1362
1370
|
constructor(spec) {
|
|
1363
1371
|
let { start, end } = getInclusive(spec);
|
|
1364
|
-
super(start ? -1 /*
|
|
1372
|
+
super(start ? -1 /* InlineIncStart */ : 500000000 /* NonIncStart */, end ? 1 /* InlineIncEnd */ : -600000000 /* NonIncEnd */, null, spec);
|
|
1365
1373
|
this.tagName = spec.tagName || "span";
|
|
1366
1374
|
this.class = spec.class || "";
|
|
1367
1375
|
this.attrs = spec.attributes || null;
|
|
@@ -1382,7 +1390,7 @@ class MarkDecoration extends Decoration {
|
|
|
1382
1390
|
MarkDecoration.prototype.point = false;
|
|
1383
1391
|
class LineDecoration extends Decoration {
|
|
1384
1392
|
constructor(spec) {
|
|
1385
|
-
super(-200000000 /*
|
|
1393
|
+
super(-200000000 /* Line */, -200000000 /* Line */, null, spec);
|
|
1386
1394
|
}
|
|
1387
1395
|
eq(other) {
|
|
1388
1396
|
return other instanceof LineDecoration &&
|
|
@@ -1409,7 +1417,9 @@ class PointDecoration extends Decoration {
|
|
|
1409
1417
|
return this.startSide < this.endSide ? BlockType.WidgetRange
|
|
1410
1418
|
: this.startSide <= 0 ? BlockType.WidgetBefore : BlockType.WidgetAfter;
|
|
1411
1419
|
}
|
|
1412
|
-
get heightRelevant() {
|
|
1420
|
+
get heightRelevant() {
|
|
1421
|
+
return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0);
|
|
1422
|
+
}
|
|
1413
1423
|
eq(other) {
|
|
1414
1424
|
return other instanceof PointDecoration &&
|
|
1415
1425
|
widgetsEq(this.widget, other.widget) &&
|
|
@@ -1521,7 +1531,7 @@ class LineView extends ContentView {
|
|
|
1521
1531
|
reuseDOM(node) {
|
|
1522
1532
|
if (node.nodeName == "DIV") {
|
|
1523
1533
|
this.setDOM(node);
|
|
1524
|
-
this.dirty |= 4 /*
|
|
1534
|
+
this.dirty |= 4 /* Attrs */ | 2 /* Node */;
|
|
1525
1535
|
}
|
|
1526
1536
|
}
|
|
1527
1537
|
sync(view, track) {
|
|
@@ -1531,7 +1541,7 @@ class LineView extends ContentView {
|
|
|
1531
1541
|
this.dom.className = "cm-line";
|
|
1532
1542
|
this.prevAttrs = this.attrs ? null : undefined;
|
|
1533
1543
|
}
|
|
1534
|
-
else if (this.dirty & 4 /*
|
|
1544
|
+
else if (this.dirty & 4 /* Attrs */) {
|
|
1535
1545
|
clearAttributes(this.dom);
|
|
1536
1546
|
this.dom.className = "cm-line";
|
|
1537
1547
|
this.prevAttrs = this.attrs ? null : undefined;
|
|
@@ -1679,7 +1689,7 @@ class ContentBuilder {
|
|
|
1679
1689
|
this.content = [];
|
|
1680
1690
|
this.curLine = null;
|
|
1681
1691
|
this.breakAtStart = 0;
|
|
1682
|
-
this.pendingBuffer = 0 /*
|
|
1692
|
+
this.pendingBuffer = 0 /* No */;
|
|
1683
1693
|
this.bufferMarks = [];
|
|
1684
1694
|
// Set to false directly after a widget that covers the position after it
|
|
1685
1695
|
this.atCursorPos = true;
|
|
@@ -1706,7 +1716,7 @@ class ContentBuilder {
|
|
|
1706
1716
|
flushBuffer(active = this.bufferMarks) {
|
|
1707
1717
|
if (this.pendingBuffer) {
|
|
1708
1718
|
this.curLine.append(wrapMarks(new WidgetBufferView(-1), active), active.length);
|
|
1709
|
-
this.pendingBuffer = 0 /*
|
|
1719
|
+
this.pendingBuffer = 0 /* No */;
|
|
1710
1720
|
}
|
|
1711
1721
|
}
|
|
1712
1722
|
addBlockWidget(view) {
|
|
@@ -1718,7 +1728,7 @@ class ContentBuilder {
|
|
|
1718
1728
|
if (this.pendingBuffer && openEnd <= this.bufferMarks.length)
|
|
1719
1729
|
this.flushBuffer();
|
|
1720
1730
|
else
|
|
1721
|
-
this.pendingBuffer = 0 /*
|
|
1731
|
+
this.pendingBuffer = 0 /* No */;
|
|
1722
1732
|
if (!this.posCovered())
|
|
1723
1733
|
this.getLine();
|
|
1724
1734
|
}
|
|
@@ -1747,7 +1757,7 @@ class ContentBuilder {
|
|
|
1747
1757
|
this.textOff = 0;
|
|
1748
1758
|
}
|
|
1749
1759
|
}
|
|
1750
|
-
let take = Math.min(this.text.length - this.textOff, length, 512 /*
|
|
1760
|
+
let take = Math.min(this.text.length - this.textOff, length, 512 /* Chunk */);
|
|
1751
1761
|
this.flushBuffer(active.slice(active.length - openStart));
|
|
1752
1762
|
this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
|
|
1753
1763
|
this.atCursorPos = true;
|
|
@@ -1783,8 +1793,8 @@ class ContentBuilder {
|
|
|
1783
1793
|
(from < to || deco.startSide > 0);
|
|
1784
1794
|
let cursorAfter = !view.isEditable && (from < to || openStart > active.length || deco.startSide <= 0);
|
|
1785
1795
|
let line = this.getLine();
|
|
1786
|
-
if (this.pendingBuffer == 2 /*
|
|
1787
|
-
this.pendingBuffer = 0 /*
|
|
1796
|
+
if (this.pendingBuffer == 2 /* IfCursor */ && !cursorBefore && !view.isEditable)
|
|
1797
|
+
this.pendingBuffer = 0 /* No */;
|
|
1788
1798
|
this.flushBuffer(active);
|
|
1789
1799
|
if (cursorBefore) {
|
|
1790
1800
|
line.append(wrapMarks(new WidgetBufferView(1), active), openStart);
|
|
@@ -1792,7 +1802,7 @@ class ContentBuilder {
|
|
|
1792
1802
|
}
|
|
1793
1803
|
line.append(wrapMarks(view, active), openStart);
|
|
1794
1804
|
this.atCursorPos = cursorAfter;
|
|
1795
|
-
this.pendingBuffer = !cursorAfter ? 0 /*
|
|
1805
|
+
this.pendingBuffer = !cursorAfter ? 0 /* No */ : from < to || openStart > active.length ? 1 /* Yes */ : 2 /* IfCursor */;
|
|
1796
1806
|
if (this.pendingBuffer)
|
|
1797
1807
|
this.bufferMarks = active.slice();
|
|
1798
1808
|
}
|
|
@@ -2119,27 +2129,27 @@ class ViewUpdate {
|
|
|
2119
2129
|
update.
|
|
2120
2130
|
*/
|
|
2121
2131
|
get viewportChanged() {
|
|
2122
|
-
return (this.flags & 4 /*
|
|
2132
|
+
return (this.flags & 4 /* Viewport */) > 0;
|
|
2123
2133
|
}
|
|
2124
2134
|
/**
|
|
2125
2135
|
Indicates whether the height of a block element in the editor
|
|
2126
2136
|
changed in this update.
|
|
2127
2137
|
*/
|
|
2128
2138
|
get heightChanged() {
|
|
2129
|
-
return (this.flags & 2 /*
|
|
2139
|
+
return (this.flags & 2 /* Height */) > 0;
|
|
2130
2140
|
}
|
|
2131
2141
|
/**
|
|
2132
2142
|
Returns true when the document was modified or the size of the
|
|
2133
2143
|
editor, or elements within the editor, changed.
|
|
2134
2144
|
*/
|
|
2135
2145
|
get geometryChanged() {
|
|
2136
|
-
return this.docChanged || (this.flags & (8 /*
|
|
2146
|
+
return this.docChanged || (this.flags & (8 /* Geometry */ | 2 /* Height */)) > 0;
|
|
2137
2147
|
}
|
|
2138
2148
|
/**
|
|
2139
2149
|
True when this update indicates a focus change.
|
|
2140
2150
|
*/
|
|
2141
2151
|
get focusChanged() {
|
|
2142
|
-
return (this.flags & 1 /*
|
|
2152
|
+
return (this.flags & 1 /* Focus */) > 0;
|
|
2143
2153
|
}
|
|
2144
2154
|
/**
|
|
2145
2155
|
Whether the document changed in this update.
|
|
@@ -2197,12 +2207,12 @@ for (let p of ["()", "[]", "{}"]) {
|
|
|
2197
2207
|
}
|
|
2198
2208
|
function charType(ch) {
|
|
2199
2209
|
return ch <= 0xf7 ? LowTypes[ch] :
|
|
2200
|
-
0x590 <= ch && ch <= 0x5f4 ? 2 /*
|
|
2210
|
+
0x590 <= ch && ch <= 0x5f4 ? 2 /* R */ :
|
|
2201
2211
|
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
2202
|
-
0x6ee <= ch && ch <= 0x8ac ? 4 /*
|
|
2203
|
-
0x2000 <= ch && ch <= 0x200b ? 256 /*
|
|
2204
|
-
0xfb50 <= ch && ch <= 0xfdff ? 4 /*
|
|
2205
|
-
ch == 0x200c ? 256 /*
|
|
2212
|
+
0x6ee <= ch && ch <= 0x8ac ? 4 /* AL */ :
|
|
2213
|
+
0x2000 <= ch && ch <= 0x200b ? 256 /* NI */ :
|
|
2214
|
+
0xfb50 <= ch && ch <= 0xfdff ? 4 /* AL */ :
|
|
2215
|
+
ch == 0x200c ? 256 /* NI */ : 1 /* L */;
|
|
2206
2216
|
}
|
|
2207
2217
|
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
|
|
2208
2218
|
/**
|
|
@@ -2267,8 +2277,8 @@ class BidiSpan {
|
|
|
2267
2277
|
// Reused array of character types
|
|
2268
2278
|
const types = [];
|
|
2269
2279
|
function computeOrder(line, direction) {
|
|
2270
|
-
let len = line.length, outerType = direction == LTR ? 1 /*
|
|
2271
|
-
if (!line || outerType == 1 /*
|
|
2280
|
+
let len = line.length, outerType = direction == LTR ? 1 /* L */ : 2 /* R */, oppositeType = direction == LTR ? 2 /* R */ : 1 /* L */;
|
|
2281
|
+
if (!line || outerType == 1 /* L */ && !BidiRE.test(line))
|
|
2272
2282
|
return trivialOrder(len);
|
|
2273
2283
|
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
|
2274
2284
|
// change the type of the NSM to the type of the previous
|
|
@@ -2282,12 +2292,12 @@ function computeOrder(line, direction) {
|
|
|
2282
2292
|
// (Left after this: L, R, EN, AN, ET, CS, NI)
|
|
2283
2293
|
for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
|
|
2284
2294
|
let type = charType(line.charCodeAt(i));
|
|
2285
|
-
if (type == 512 /*
|
|
2295
|
+
if (type == 512 /* NSM */)
|
|
2286
2296
|
type = prev;
|
|
2287
|
-
else if (type == 8 /*
|
|
2288
|
-
type = 16 /*
|
|
2289
|
-
types[i] = type == 4 /*
|
|
2290
|
-
if (type & 7 /*
|
|
2297
|
+
else if (type == 8 /* EN */ && prevStrong == 4 /* AL */)
|
|
2298
|
+
type = 16 /* AN */;
|
|
2299
|
+
types[i] = type == 4 /* AL */ ? 2 /* R */ : type;
|
|
2300
|
+
if (type & 7 /* Strong */)
|
|
2291
2301
|
prevStrong = type;
|
|
2292
2302
|
prev = type;
|
|
2293
2303
|
}
|
|
@@ -2301,26 +2311,26 @@ function computeOrder(line, direction) {
|
|
|
2301
2311
|
// (Left after this: L, R, EN+AN, NI)
|
|
2302
2312
|
for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
|
|
2303
2313
|
let type = types[i];
|
|
2304
|
-
if (type == 128 /*
|
|
2305
|
-
if (i < len - 1 && prev == types[i + 1] && (prev & 24 /*
|
|
2314
|
+
if (type == 128 /* CS */) {
|
|
2315
|
+
if (i < len - 1 && prev == types[i + 1] && (prev & 24 /* Num */))
|
|
2306
2316
|
type = types[i] = prev;
|
|
2307
2317
|
else
|
|
2308
|
-
types[i] = 256 /*
|
|
2318
|
+
types[i] = 256 /* NI */;
|
|
2309
2319
|
}
|
|
2310
|
-
else if (type == 64 /*
|
|
2320
|
+
else if (type == 64 /* ET */) {
|
|
2311
2321
|
let end = i + 1;
|
|
2312
|
-
while (end < len && types[end] == 64 /*
|
|
2322
|
+
while (end < len && types[end] == 64 /* ET */)
|
|
2313
2323
|
end++;
|
|
2314
|
-
let replace = (i && prev == 8 /*
|
|
2324
|
+
let replace = (i && prev == 8 /* EN */) || (end < len && types[end] == 8 /* EN */) ? (prevStrong == 1 /* L */ ? 1 /* L */ : 8 /* EN */) : 256 /* NI */;
|
|
2315
2325
|
for (let j = i; j < end; j++)
|
|
2316
2326
|
types[j] = replace;
|
|
2317
2327
|
i = end - 1;
|
|
2318
2328
|
}
|
|
2319
|
-
else if (type == 8 /*
|
|
2320
|
-
types[i] = 1 /*
|
|
2329
|
+
else if (type == 8 /* EN */ && prevStrong == 1 /* L */) {
|
|
2330
|
+
types[i] = 1 /* L */;
|
|
2321
2331
|
}
|
|
2322
2332
|
prev = type;
|
|
2323
|
-
if (type & 7 /*
|
|
2333
|
+
if (type & 7 /* Strong */)
|
|
2324
2334
|
prevStrong = type;
|
|
2325
2335
|
}
|
|
2326
2336
|
// N0. Process bracket pairs in an isolating run sequence
|
|
@@ -2335,9 +2345,9 @@ function computeOrder(line, direction) {
|
|
|
2335
2345
|
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
2336
2346
|
if (BracketStack[sJ + 1] == -br) {
|
|
2337
2347
|
let flags = BracketStack[sJ + 2];
|
|
2338
|
-
let type = (flags & 2 /*
|
|
2339
|
-
!(flags & 4 /*
|
|
2340
|
-
(flags & 1 /*
|
|
2348
|
+
let type = (flags & 2 /* EmbedInside */) ? outerType :
|
|
2349
|
+
!(flags & 4 /* OppositeInside */) ? 0 :
|
|
2350
|
+
(flags & 1 /* OppositeBefore */) ? oppositeType : outerType;
|
|
2341
2351
|
if (type)
|
|
2342
2352
|
types[i] = types[BracketStack[sJ]] = type;
|
|
2343
2353
|
sI = sJ;
|
|
@@ -2345,7 +2355,7 @@ function computeOrder(line, direction) {
|
|
|
2345
2355
|
}
|
|
2346
2356
|
}
|
|
2347
2357
|
}
|
|
2348
|
-
else if (BracketStack.length == 189 /*
|
|
2358
|
+
else if (BracketStack.length == 189 /* MaxDepth */) {
|
|
2349
2359
|
break;
|
|
2350
2360
|
}
|
|
2351
2361
|
else {
|
|
@@ -2354,20 +2364,20 @@ function computeOrder(line, direction) {
|
|
|
2354
2364
|
BracketStack[sI++] = context;
|
|
2355
2365
|
}
|
|
2356
2366
|
}
|
|
2357
|
-
else if ((type = types[i]) == 2 /*
|
|
2367
|
+
else if ((type = types[i]) == 2 /* R */ || type == 1 /* L */) {
|
|
2358
2368
|
let embed = type == outerType;
|
|
2359
|
-
context = embed ? 0 : 1 /*
|
|
2369
|
+
context = embed ? 0 : 1 /* OppositeBefore */;
|
|
2360
2370
|
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
2361
2371
|
let cur = BracketStack[sJ + 2];
|
|
2362
|
-
if (cur & 2 /*
|
|
2372
|
+
if (cur & 2 /* EmbedInside */)
|
|
2363
2373
|
break;
|
|
2364
2374
|
if (embed) {
|
|
2365
|
-
BracketStack[sJ + 2] |= 2 /*
|
|
2375
|
+
BracketStack[sJ + 2] |= 2 /* EmbedInside */;
|
|
2366
2376
|
}
|
|
2367
2377
|
else {
|
|
2368
|
-
if (cur & 4 /*
|
|
2378
|
+
if (cur & 4 /* OppositeInside */)
|
|
2369
2379
|
break;
|
|
2370
|
-
BracketStack[sJ + 2] |= 4 /*
|
|
2380
|
+
BracketStack[sJ + 2] |= 4 /* OppositeInside */;
|
|
2371
2381
|
}
|
|
2372
2382
|
}
|
|
2373
2383
|
}
|
|
@@ -2380,13 +2390,13 @@ function computeOrder(line, direction) {
|
|
|
2380
2390
|
// N2. Any remaining neutrals take the embedding direction.
|
|
2381
2391
|
// (Left after this: L, R, EN+AN)
|
|
2382
2392
|
for (let i = 0; i < len; i++) {
|
|
2383
|
-
if (types[i] == 256 /*
|
|
2393
|
+
if (types[i] == 256 /* NI */) {
|
|
2384
2394
|
let end = i + 1;
|
|
2385
|
-
while (end < len && types[end] == 256 /*
|
|
2395
|
+
while (end < len && types[end] == 256 /* NI */)
|
|
2386
2396
|
end++;
|
|
2387
|
-
let beforeL = (i ? types[i - 1] : outerType) == 1 /*
|
|
2388
|
-
let afterL = (end < len ? types[end] : outerType) == 1 /*
|
|
2389
|
-
let replace = beforeL == afterL ? (beforeL ? 1 /*
|
|
2397
|
+
let beforeL = (i ? types[i - 1] : outerType) == 1 /* L */;
|
|
2398
|
+
let afterL = (end < len ? types[end] : outerType) == 1 /* L */;
|
|
2399
|
+
let replace = beforeL == afterL ? (beforeL ? 1 /* L */ : 2 /* R */) : outerType;
|
|
2390
2400
|
for (let j = i; j < end; j++)
|
|
2391
2401
|
types[j] = replace;
|
|
2392
2402
|
i = end - 1;
|
|
@@ -2398,15 +2408,15 @@ function computeOrder(line, direction) {
|
|
|
2398
2408
|
// explicit embedding into account, we can build up the order on
|
|
2399
2409
|
// the fly, without following the level-based algorithm.
|
|
2400
2410
|
let order = [];
|
|
2401
|
-
if (outerType == 1 /*
|
|
2411
|
+
if (outerType == 1 /* L */) {
|
|
2402
2412
|
for (let i = 0; i < len;) {
|
|
2403
|
-
let start = i, rtl = types[i++] != 1 /*
|
|
2404
|
-
while (i < len && rtl == (types[i] != 1 /*
|
|
2413
|
+
let start = i, rtl = types[i++] != 1 /* L */;
|
|
2414
|
+
while (i < len && rtl == (types[i] != 1 /* L */))
|
|
2405
2415
|
i++;
|
|
2406
2416
|
if (rtl) {
|
|
2407
2417
|
for (let j = i; j > start;) {
|
|
2408
|
-
let end = j, l = types[--j] != 2 /*
|
|
2409
|
-
while (j > start && l == (types[j - 1] != 2 /*
|
|
2418
|
+
let end = j, l = types[--j] != 2 /* R */;
|
|
2419
|
+
while (j > start && l == (types[j - 1] != 2 /* R */))
|
|
2410
2420
|
j--;
|
|
2411
2421
|
order.push(new BidiSpan(j, end, l ? 2 : 1));
|
|
2412
2422
|
}
|
|
@@ -2418,8 +2428,8 @@ function computeOrder(line, direction) {
|
|
|
2418
2428
|
}
|
|
2419
2429
|
else {
|
|
2420
2430
|
for (let i = 0; i < len;) {
|
|
2421
|
-
let start = i, rtl = types[i++] == 2 /*
|
|
2422
|
-
while (i < len && rtl == (types[i] == 2 /*
|
|
2431
|
+
let start = i, rtl = types[i++] == 2 /* R */;
|
|
2432
|
+
while (i < len && rtl == (types[i] == 2 /* R */))
|
|
2423
2433
|
i++;
|
|
2424
2434
|
order.push(new BidiSpan(start, i, rtl ? 1 : 2));
|
|
2425
2435
|
}
|
|
@@ -2476,7 +2486,6 @@ class DOMReader {
|
|
|
2476
2486
|
constructor(points, state) {
|
|
2477
2487
|
this.points = points;
|
|
2478
2488
|
this.text = "";
|
|
2479
|
-
console.log("make reader");
|
|
2480
2489
|
this.lineSeparator = state.facet(EditorState.lineSeparator);
|
|
2481
2490
|
}
|
|
2482
2491
|
append(text) {
|
|
@@ -2611,10 +2620,7 @@ class DocView extends ContentView {
|
|
|
2611
2620
|
this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0);
|
|
2612
2621
|
}
|
|
2613
2622
|
get length() { return this.view.state.doc.length; }
|
|
2614
|
-
// Update the document view to a given state.
|
|
2615
|
-
// used as a hint to compute a new viewport that includes that
|
|
2616
|
-
// position, if we know the editor is going to scroll that position
|
|
2617
|
-
// into view.
|
|
2623
|
+
// Update the document view to a given state.
|
|
2618
2624
|
update(update) {
|
|
2619
2625
|
let changedRanges = update.changedRanges;
|
|
2620
2626
|
if (this.minWidth > 0 && changedRanges.length) {
|
|
@@ -2641,7 +2647,7 @@ class DocView extends ContentView {
|
|
|
2641
2647
|
let prevDeco = this.decorations, deco = this.updateDeco();
|
|
2642
2648
|
let decoDiff = findChangedDeco(prevDeco, deco, update.changes);
|
|
2643
2649
|
changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff);
|
|
2644
|
-
if (this.dirty == 0 /*
|
|
2650
|
+
if (this.dirty == 0 /* Not */ && changedRanges.length == 0) {
|
|
2645
2651
|
return false;
|
|
2646
2652
|
}
|
|
2647
2653
|
else {
|
|
@@ -2670,7 +2676,7 @@ class DocView extends ContentView {
|
|
|
2670
2676
|
// to detect that situation.
|
|
2671
2677
|
let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : undefined;
|
|
2672
2678
|
this.sync(this.view, track);
|
|
2673
|
-
this.dirty = 0 /*
|
|
2679
|
+
this.dirty = 0 /* Not */;
|
|
2674
2680
|
if (track && (track.written || observer.selectionRange.focusNode != track.node))
|
|
2675
2681
|
this.forceSelection = true;
|
|
2676
2682
|
this.dom.style.height = "";
|
|
@@ -2739,10 +2745,10 @@ class DocView extends ContentView {
|
|
|
2739
2745
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=1612076
|
|
2740
2746
|
if (browser.gecko) {
|
|
2741
2747
|
let nextTo = nextToUneditable(anchor.node, anchor.offset);
|
|
2742
|
-
if (nextTo && nextTo != (1 /*
|
|
2743
|
-
let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /*
|
|
2748
|
+
if (nextTo && nextTo != (1 /* Before */ | 2 /* After */)) {
|
|
2749
|
+
let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /* Before */ ? 1 : -1);
|
|
2744
2750
|
if (text)
|
|
2745
|
-
anchor = new DOMPos(text, nextTo == 1 /*
|
|
2751
|
+
anchor = new DOMPos(text, nextTo == 1 /* Before */ ? 0 : text.nodeValue.length);
|
|
2746
2752
|
}
|
|
2747
2753
|
}
|
|
2748
2754
|
rawSel.collapse(anchor.node, anchor.offset);
|
|
@@ -3023,8 +3029,12 @@ function computeCompositionDeco(view, changes) {
|
|
|
3023
3029
|
return Decoration.none;
|
|
3024
3030
|
let { from, to, node, text: textNode } = surrounding;
|
|
3025
3031
|
let newFrom = changes.mapPos(from, 1), newTo = Math.max(newFrom, changes.mapPos(to, -1));
|
|
3026
|
-
let { state } = view,
|
|
3027
|
-
|
|
3032
|
+
let { state } = view, reader = new DOMReader([], state);
|
|
3033
|
+
if (node.nodeType == 3)
|
|
3034
|
+
reader.readTextNode(node);
|
|
3035
|
+
else
|
|
3036
|
+
reader.readRange(node.firstChild, null);
|
|
3037
|
+
let { text } = reader;
|
|
3028
3038
|
if (text.indexOf(LineBreakPlaceholder) > -1)
|
|
3029
3039
|
return Decoration.none; // Don't try to preserve multi-line compositions
|
|
3030
3040
|
if (newTo - newFrom < text.length) {
|
|
@@ -3088,8 +3098,8 @@ function nearbyTextNode(startNode, startOffset, side) {
|
|
|
3088
3098
|
function nextToUneditable(node, offset) {
|
|
3089
3099
|
if (node.nodeType != 1)
|
|
3090
3100
|
return 0;
|
|
3091
|
-
return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /*
|
|
3092
|
-
(offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /*
|
|
3101
|
+
return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /* Before */ : 0) |
|
|
3102
|
+
(offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /* After */ : 0);
|
|
3093
3103
|
}
|
|
3094
3104
|
class DecorationComparator$1 {
|
|
3095
3105
|
constructor() {
|
|
@@ -3371,9 +3381,18 @@ function isSuspiciousChromeCaretResult(node, offset, x) {
|
|
|
3371
3381
|
: textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
|
|
3372
3382
|
return x - rect.left > 5;
|
|
3373
3383
|
}
|
|
3384
|
+
function blockAt(view, pos) {
|
|
3385
|
+
let line = view.lineBlockAt(pos);
|
|
3386
|
+
if (Array.isArray(line.type))
|
|
3387
|
+
for (let l of line.type) {
|
|
3388
|
+
if (l.to > pos || l.to == pos && (l.to == line.to || l.type == BlockType.Text))
|
|
3389
|
+
return l;
|
|
3390
|
+
}
|
|
3391
|
+
return line;
|
|
3392
|
+
}
|
|
3374
3393
|
function moveToLineBoundary(view, start, forward, includeWrap) {
|
|
3375
|
-
let line = view
|
|
3376
|
-
let coords = !includeWrap || !view.lineWrapping ? null
|
|
3394
|
+
let line = blockAt(view, start.head);
|
|
3395
|
+
let coords = !includeWrap || line.type != BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null
|
|
3377
3396
|
: view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
|
|
3378
3397
|
if (coords) {
|
|
3379
3398
|
let editorRect = view.dom.getBoundingClientRect();
|
|
@@ -3383,9 +3402,7 @@ function moveToLineBoundary(view, start, forward, includeWrap) {
|
|
|
3383
3402
|
if (pos != null)
|
|
3384
3403
|
return EditorSelection.cursor(pos, forward ? -1 : 1);
|
|
3385
3404
|
}
|
|
3386
|
-
|
|
3387
|
-
let end = lineView ? (forward ? lineView.posAtEnd : lineView.posAtStart) : (forward ? line.to : line.from);
|
|
3388
|
-
return EditorSelection.cursor(end, forward ? -1 : 1);
|
|
3405
|
+
return EditorSelection.cursor(forward ? line.to : line.from, forward ? -1 : 1);
|
|
3389
3406
|
}
|
|
3390
3407
|
function moveByChar(view, start, forward, by) {
|
|
3391
3408
|
let line = view.state.doc.lineAt(start.head), spans = view.bidiSpans(line);
|
|
@@ -4374,34 +4391,25 @@ class BlockInfo {
|
|
|
4374
4391
|
*/
|
|
4375
4392
|
height,
|
|
4376
4393
|
/**
|
|
4377
|
-
@internal
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
@internal
|
|
4394
|
+
@internal Weird packed field that holds an array of children
|
|
4395
|
+
for composite blocks, a decoration for block widgets, and a
|
|
4396
|
+
number indicating the amount of widget-create line breaks for
|
|
4397
|
+
text blocks.
|
|
4382
4398
|
*/
|
|
4383
|
-
|
|
4399
|
+
_content) {
|
|
4384
4400
|
this.from = from;
|
|
4385
4401
|
this.length = length;
|
|
4386
4402
|
this.top = top;
|
|
4387
4403
|
this.height = height;
|
|
4388
|
-
this.
|
|
4389
|
-
this.deco = deco;
|
|
4404
|
+
this._content = _content;
|
|
4390
4405
|
}
|
|
4391
4406
|
/**
|
|
4392
4407
|
The type of element this is. When querying lines, this may be
|
|
4393
4408
|
an array of all the blocks that make up the line.
|
|
4394
4409
|
*/
|
|
4395
4410
|
get type() {
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
}
|
|
4399
|
-
/**
|
|
4400
|
-
If this is a widget block, this will return the widget
|
|
4401
|
-
associated with it.
|
|
4402
|
-
*/
|
|
4403
|
-
get widget() {
|
|
4404
|
-
return this.deco && this.deco.widget;
|
|
4411
|
+
return typeof this._content == "number" ? BlockType.Text :
|
|
4412
|
+
Array.isArray(this._content) ? this._content : this._content.type;
|
|
4405
4413
|
}
|
|
4406
4414
|
/**
|
|
4407
4415
|
The end of the element as a document position.
|
|
@@ -4412,11 +4420,26 @@ class BlockInfo {
|
|
|
4412
4420
|
*/
|
|
4413
4421
|
get bottom() { return this.top + this.height; }
|
|
4414
4422
|
/**
|
|
4423
|
+
If this is a widget block, this will return the widget
|
|
4424
|
+
associated with it.
|
|
4425
|
+
*/
|
|
4426
|
+
get widget() {
|
|
4427
|
+
return this._content instanceof PointDecoration ? this._content.widget : null;
|
|
4428
|
+
}
|
|
4429
|
+
/**
|
|
4430
|
+
If this is a textblock, this holds the number of line breaks
|
|
4431
|
+
that appear in widgets inside the block.
|
|
4432
|
+
*/
|
|
4433
|
+
get widgetLineBreaks() {
|
|
4434
|
+
return typeof this._content == "number" ? this._content : 0;
|
|
4435
|
+
}
|
|
4436
|
+
/**
|
|
4415
4437
|
@internal
|
|
4416
4438
|
*/
|
|
4417
4439
|
join(other) {
|
|
4418
|
-
let
|
|
4419
|
-
|
|
4440
|
+
let content = (Array.isArray(this._content) ? this._content : [this])
|
|
4441
|
+
.concat(Array.isArray(other._content) ? other._content : [other]);
|
|
4442
|
+
return new BlockInfo(this.from, this.length + other.length, this.top, this.height + other.height, content);
|
|
4420
4443
|
}
|
|
4421
4444
|
}
|
|
4422
4445
|
var QueryType = /*@__PURE__*/(function (QueryType) {
|
|
@@ -4428,13 +4451,13 @@ const Epsilon = 1e-3;
|
|
|
4428
4451
|
class HeightMap {
|
|
4429
4452
|
constructor(length, // The number of characters covered
|
|
4430
4453
|
height, // Height of this part of the document
|
|
4431
|
-
flags = 2 /*
|
|
4454
|
+
flags = 2 /* Outdated */) {
|
|
4432
4455
|
this.length = length;
|
|
4433
4456
|
this.height = height;
|
|
4434
4457
|
this.flags = flags;
|
|
4435
4458
|
}
|
|
4436
|
-
get outdated() { return (this.flags & 2 /*
|
|
4437
|
-
set outdated(value) { this.flags = (value ? 2 /*
|
|
4459
|
+
get outdated() { return (this.flags & 2 /* Outdated */) > 0; }
|
|
4460
|
+
set outdated(value) { this.flags = (value ? 2 /* Outdated */ : 0) | (this.flags & ~2 /* Outdated */); }
|
|
4438
4461
|
setHeight(oracle, height) {
|
|
4439
4462
|
if (this.height != height) {
|
|
4440
4463
|
if (Math.abs(this.height - height) > Epsilon)
|
|
@@ -4536,7 +4559,7 @@ class HeightMapBlock extends HeightMap {
|
|
|
4536
4559
|
this.deco = deco;
|
|
4537
4560
|
}
|
|
4538
4561
|
blockAt(_height, _oracle, top, offset) {
|
|
4539
|
-
return new BlockInfo(offset, this.length, top, this.height,
|
|
4562
|
+
return new BlockInfo(offset, this.length, top, this.height, this.deco || 0);
|
|
4540
4563
|
}
|
|
4541
4564
|
lineAt(_value, _type, oracle, top, offset) {
|
|
4542
4565
|
return this.blockAt(0, oracle, top, offset);
|
|
@@ -4558,10 +4581,14 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4558
4581
|
super(length, height, null);
|
|
4559
4582
|
this.collapsed = 0; // Amount of collapsed content in the line
|
|
4560
4583
|
this.widgetHeight = 0; // Maximum inline widget height
|
|
4584
|
+
this.breaks = 0; // Number of widget-introduced line breaks on the line
|
|
4585
|
+
}
|
|
4586
|
+
blockAt(_height, _oracle, top, offset) {
|
|
4587
|
+
return new BlockInfo(offset, this.length, top, this.height, this.breaks);
|
|
4561
4588
|
}
|
|
4562
4589
|
replace(_from, _to, nodes) {
|
|
4563
4590
|
let node = nodes[0];
|
|
4564
|
-
if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /*
|
|
4591
|
+
if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /* SingleLine */)) &&
|
|
4565
4592
|
Math.abs(this.length - node.length) < 10) {
|
|
4566
4593
|
if (node instanceof HeightMapGap)
|
|
4567
4594
|
node = new HeightMapText(node.length, this.height);
|
|
@@ -4579,7 +4606,8 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4579
4606
|
if (measured && measured.from <= offset && measured.more)
|
|
4580
4607
|
this.setHeight(oracle, measured.heights[measured.index++]);
|
|
4581
4608
|
else if (force || this.outdated)
|
|
4582
|
-
this.setHeight(oracle, Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed))
|
|
4609
|
+
this.setHeight(oracle, Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) +
|
|
4610
|
+
this.breaks * oracle.lineHeight);
|
|
4583
4611
|
this.outdated = false;
|
|
4584
4612
|
return this;
|
|
4585
4613
|
}
|
|
@@ -4610,12 +4638,12 @@ class HeightMapGap extends HeightMap {
|
|
|
4610
4638
|
let guess = offset + Math.round(Math.max(0, Math.min(1, (height - top) / this.height)) * this.length);
|
|
4611
4639
|
let line = oracle.doc.lineAt(guess), lineHeight = perLine + line.length * perChar;
|
|
4612
4640
|
let lineTop = Math.max(top, height - lineHeight / 2);
|
|
4613
|
-
return new BlockInfo(line.from, line.length, lineTop, lineHeight,
|
|
4641
|
+
return new BlockInfo(line.from, line.length, lineTop, lineHeight, 0);
|
|
4614
4642
|
}
|
|
4615
4643
|
else {
|
|
4616
4644
|
let line = Math.max(0, Math.min(lastLine - firstLine, Math.floor((height - top) / perLine)));
|
|
4617
4645
|
let { from, length } = oracle.doc.line(firstLine + line);
|
|
4618
|
-
return new BlockInfo(from, length, top + perLine * line, perLine,
|
|
4646
|
+
return new BlockInfo(from, length, top + perLine * line, perLine, 0);
|
|
4619
4647
|
}
|
|
4620
4648
|
}
|
|
4621
4649
|
lineAt(value, type, oracle, top, offset) {
|
|
@@ -4623,13 +4651,13 @@ class HeightMapGap extends HeightMap {
|
|
|
4623
4651
|
return this.blockAt(value, oracle, top, offset);
|
|
4624
4652
|
if (type == QueryType.ByPosNoHeight) {
|
|
4625
4653
|
let { from, to } = oracle.doc.lineAt(value);
|
|
4626
|
-
return new BlockInfo(from, to - from, 0, 0,
|
|
4654
|
+
return new BlockInfo(from, to - from, 0, 0, 0);
|
|
4627
4655
|
}
|
|
4628
4656
|
let { firstLine, perLine, perChar } = this.heightMetrics(oracle, offset);
|
|
4629
4657
|
let line = oracle.doc.lineAt(value), lineHeight = perLine + line.length * perChar;
|
|
4630
4658
|
let linesAbove = line.number - firstLine;
|
|
4631
4659
|
let lineTop = top + perLine * linesAbove + perChar * (line.from - offset - linesAbove);
|
|
4632
|
-
return new BlockInfo(line.from, line.length, Math.max(top, Math.min(lineTop, top + this.height - lineHeight)), lineHeight,
|
|
4660
|
+
return new BlockInfo(line.from, line.length, Math.max(top, Math.min(lineTop, top + this.height - lineHeight)), lineHeight, 0);
|
|
4633
4661
|
}
|
|
4634
4662
|
forEachLine(from, to, oracle, top, offset, f) {
|
|
4635
4663
|
from = Math.max(from, offset);
|
|
@@ -4642,7 +4670,7 @@ class HeightMapGap extends HeightMap {
|
|
|
4642
4670
|
lineTop += perLine * linesAbove + perChar * (from - offset - linesAbove);
|
|
4643
4671
|
}
|
|
4644
4672
|
let lineHeight = perLine + perChar * line.length;
|
|
4645
|
-
f(new BlockInfo(line.from, line.length, lineTop, lineHeight,
|
|
4673
|
+
f(new BlockInfo(line.from, line.length, lineTop, lineHeight, 0));
|
|
4646
4674
|
lineTop += lineHeight;
|
|
4647
4675
|
pos = line.to + 1;
|
|
4648
4676
|
}
|
|
@@ -4713,12 +4741,12 @@ class HeightMapGap extends HeightMap {
|
|
|
4713
4741
|
}
|
|
4714
4742
|
class HeightMapBranch extends HeightMap {
|
|
4715
4743
|
constructor(left, brk, right) {
|
|
4716
|
-
super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /*
|
|
4744
|
+
super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /* Outdated */ : 0));
|
|
4717
4745
|
this.left = left;
|
|
4718
4746
|
this.right = right;
|
|
4719
4747
|
this.size = left.size + right.size;
|
|
4720
4748
|
}
|
|
4721
|
-
get break() { return this.flags & 1 /*
|
|
4749
|
+
get break() { return this.flags & 1 /* Break */; }
|
|
4722
4750
|
blockAt(height, oracle, top, offset) {
|
|
4723
4751
|
let mid = top + this.left.height;
|
|
4724
4752
|
return height < mid ? this.left.blockAt(height, oracle, top, offset)
|
|
@@ -4868,14 +4896,15 @@ class NodeBuilder {
|
|
|
4868
4896
|
point(from, to, deco) {
|
|
4869
4897
|
if (from < to || deco.heightRelevant) {
|
|
4870
4898
|
let height = deco.widget ? deco.widget.estimatedHeight : 0;
|
|
4899
|
+
let breaks = deco.widget ? deco.widget.lineBreaks : 0;
|
|
4871
4900
|
if (height < 0)
|
|
4872
4901
|
height = this.oracle.lineHeight;
|
|
4873
4902
|
let len = to - from;
|
|
4874
4903
|
if (deco.block) {
|
|
4875
4904
|
this.addBlock(new HeightMapBlock(len, height, deco));
|
|
4876
4905
|
}
|
|
4877
|
-
else if (len || height >= relevantWidgetHeight) {
|
|
4878
|
-
this.addLineDeco(height, len);
|
|
4906
|
+
else if (len || breaks || height >= relevantWidgetHeight) {
|
|
4907
|
+
this.addLineDeco(height, breaks, len);
|
|
4879
4908
|
}
|
|
4880
4909
|
}
|
|
4881
4910
|
else if (to > from) {
|
|
@@ -4902,7 +4931,7 @@ class NodeBuilder {
|
|
|
4902
4931
|
blankContent(from, to) {
|
|
4903
4932
|
let gap = new HeightMapGap(to - from);
|
|
4904
4933
|
if (this.oracle.doc.lineAt(from).to == to)
|
|
4905
|
-
gap.flags |= 4 /*
|
|
4934
|
+
gap.flags |= 4 /* SingleLine */;
|
|
4906
4935
|
return gap;
|
|
4907
4936
|
}
|
|
4908
4937
|
ensureLine() {
|
|
@@ -4925,11 +4954,12 @@ class NodeBuilder {
|
|
|
4925
4954
|
if (type != BlockType.WidgetBefore)
|
|
4926
4955
|
this.covering = block;
|
|
4927
4956
|
}
|
|
4928
|
-
addLineDeco(height, length) {
|
|
4957
|
+
addLineDeco(height, breaks, length) {
|
|
4929
4958
|
let line = this.ensureLine();
|
|
4930
4959
|
line.length += length;
|
|
4931
4960
|
line.collapsed += length;
|
|
4932
4961
|
line.widgetHeight = Math.max(line.widgetHeight, height);
|
|
4962
|
+
line.breaks += breaks;
|
|
4933
4963
|
this.writtenTo = this.pos = this.pos + length;
|
|
4934
4964
|
}
|
|
4935
4965
|
finish(from) {
|
|
@@ -5063,6 +5093,14 @@ class ViewState {
|
|
|
5063
5093
|
this.contentDOMHeight = 0;
|
|
5064
5094
|
this.editorHeight = 0;
|
|
5065
5095
|
this.editorWidth = 0;
|
|
5096
|
+
this.scrollTop = 0;
|
|
5097
|
+
this.scrolledToBottom = true;
|
|
5098
|
+
// The vertical position (document-relative) to which to anchor the
|
|
5099
|
+
// scroll position. -1 means anchor to the end of the document.
|
|
5100
|
+
this.scrollAnchorPos = 0;
|
|
5101
|
+
// The height at the anchor position. Set by the DOM update phase.
|
|
5102
|
+
// -1 means no height available.
|
|
5103
|
+
this.scrollAnchorHeight = -1;
|
|
5066
5104
|
// See VP.MaxDOMHeight
|
|
5067
5105
|
this.scaler = IdScaler;
|
|
5068
5106
|
this.scrollTarget = null;
|
|
@@ -5103,7 +5141,7 @@ class ViewState {
|
|
|
5103
5141
|
}
|
|
5104
5142
|
}
|
|
5105
5143
|
this.viewports = viewports.sort((a, b) => a.from - b.from);
|
|
5106
|
-
this.scaler = this.heightMap.height <= 7000000 /*
|
|
5144
|
+
this.scaler = this.heightMap.height <= 7000000 /* MaxDOMHeight */ ? IdScaler :
|
|
5107
5145
|
new BigScaler(this.heightOracle, this.heightMap, this.viewports);
|
|
5108
5146
|
}
|
|
5109
5147
|
updateViewportLines() {
|
|
@@ -5119,20 +5157,29 @@ class ViewState {
|
|
|
5119
5157
|
let contentChanges = update.changedRanges;
|
|
5120
5158
|
let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length)));
|
|
5121
5159
|
let prevHeight = this.heightMap.height;
|
|
5160
|
+
let scrollAnchor = this.scrolledToBottom ? null : this.lineBlockAtHeight(this.scrollTop);
|
|
5122
5161
|
this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
|
|
5123
5162
|
if (this.heightMap.height != prevHeight)
|
|
5124
|
-
update.flags |= 2 /*
|
|
5163
|
+
update.flags |= 2 /* Height */;
|
|
5164
|
+
if (scrollAnchor) {
|
|
5165
|
+
this.scrollAnchorPos = update.changes.mapPos(scrollAnchor.from, -1);
|
|
5166
|
+
this.scrollAnchorHeight = scrollAnchor.top;
|
|
5167
|
+
}
|
|
5168
|
+
else {
|
|
5169
|
+
this.scrollAnchorPos = -1;
|
|
5170
|
+
this.scrollAnchorHeight = this.heightMap.height;
|
|
5171
|
+
}
|
|
5125
5172
|
let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
|
|
5126
5173
|
if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) ||
|
|
5127
5174
|
!this.viewportIsAppropriate(viewport))
|
|
5128
5175
|
viewport = this.getViewport(0, scrollTarget);
|
|
5129
|
-
let updateLines = !update.changes.empty || (update.flags & 2 /*
|
|
5176
|
+
let updateLines = !update.changes.empty || (update.flags & 2 /* Height */) ||
|
|
5130
5177
|
viewport.from != this.viewport.from || viewport.to != this.viewport.to;
|
|
5131
5178
|
this.viewport = viewport;
|
|
5132
5179
|
this.updateForViewport();
|
|
5133
5180
|
if (updateLines)
|
|
5134
5181
|
this.updateViewportLines();
|
|
5135
|
-
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /*
|
|
5182
|
+
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /* Margin */ << 1))
|
|
5136
5183
|
this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
|
|
5137
5184
|
update.flags |= this.computeVisibleRanges();
|
|
5138
5185
|
if (scrollTarget)
|
|
@@ -5158,14 +5205,19 @@ class ViewState {
|
|
|
5158
5205
|
if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
|
|
5159
5206
|
this.paddingTop = paddingTop;
|
|
5160
5207
|
this.paddingBottom = paddingBottom;
|
|
5161
|
-
result |= 8 /*
|
|
5208
|
+
result |= 8 /* Geometry */ | 2 /* Height */;
|
|
5162
5209
|
}
|
|
5163
5210
|
if (this.editorWidth != view.scrollDOM.clientWidth) {
|
|
5164
5211
|
if (oracle.lineWrapping)
|
|
5165
5212
|
measureContent = true;
|
|
5166
5213
|
this.editorWidth = view.scrollDOM.clientWidth;
|
|
5167
|
-
result |= 8 /*
|
|
5214
|
+
result |= 8 /* Geometry */;
|
|
5215
|
+
}
|
|
5216
|
+
if (this.scrollTop != view.scrollDOM.scrollTop) {
|
|
5217
|
+
this.scrollAnchorHeight = -1;
|
|
5218
|
+
this.scrollTop = view.scrollDOM.scrollTop;
|
|
5168
5219
|
}
|
|
5220
|
+
this.scrolledToBottom = this.scrollTop > view.scrollDOM.scrollHeight - view.scrollDOM.clientHeight - 4;
|
|
5169
5221
|
// Pixel viewport
|
|
5170
5222
|
let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
|
|
5171
5223
|
let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
|
|
@@ -5182,7 +5234,7 @@ class ViewState {
|
|
|
5182
5234
|
if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
|
|
5183
5235
|
this.contentDOMWidth = domRect.width;
|
|
5184
5236
|
this.editorHeight = view.scrollDOM.clientHeight;
|
|
5185
|
-
result |= 8 /*
|
|
5237
|
+
result |= 8 /* Geometry */;
|
|
5186
5238
|
}
|
|
5187
5239
|
if (measureContent) {
|
|
5188
5240
|
let lineHeights = view.docView.measureVisibleLineHeights(this.viewport);
|
|
@@ -5193,7 +5245,7 @@ class ViewState {
|
|
|
5193
5245
|
refresh = lineHeight > 0 && oracle.refresh(whiteSpace, lineHeight, charWidth, textHeight, contentWidth / charWidth, lineHeights);
|
|
5194
5246
|
if (refresh) {
|
|
5195
5247
|
view.docView.minWidth = 0;
|
|
5196
|
-
result |= 8 /*
|
|
5248
|
+
result |= 8 /* Geometry */;
|
|
5197
5249
|
}
|
|
5198
5250
|
}
|
|
5199
5251
|
if (dTop > 0 && dBottom > 0)
|
|
@@ -5206,7 +5258,7 @@ class ViewState {
|
|
|
5206
5258
|
this.heightMap = (refresh ? HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)]) : this.heightMap).updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
5207
5259
|
}
|
|
5208
5260
|
if (oracle.heightChanged)
|
|
5209
|
-
result |= 2 /*
|
|
5261
|
+
result |= 2 /* Height */;
|
|
5210
5262
|
}
|
|
5211
5263
|
let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) ||
|
|
5212
5264
|
this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from ||
|
|
@@ -5214,9 +5266,9 @@ class ViewState {
|
|
|
5214
5266
|
if (viewportChange)
|
|
5215
5267
|
this.viewport = this.getViewport(bias, this.scrollTarget);
|
|
5216
5268
|
this.updateForViewport();
|
|
5217
|
-
if ((result & 2 /*
|
|
5269
|
+
if ((result & 2 /* Height */) || viewportChange)
|
|
5218
5270
|
this.updateViewportLines();
|
|
5219
|
-
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /*
|
|
5271
|
+
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /* Margin */ << 1))
|
|
5220
5272
|
this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps, view));
|
|
5221
5273
|
result |= this.computeVisibleRanges();
|
|
5222
5274
|
if (this.mustEnforceCursorAssoc) {
|
|
@@ -5235,10 +5287,10 @@ class ViewState {
|
|
|
5235
5287
|
// This will divide VP.Margin between the top and the
|
|
5236
5288
|
// bottom, depending on the bias (the change in viewport position
|
|
5237
5289
|
// since the last update). It'll hold a number between 0 and 1
|
|
5238
|
-
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /*
|
|
5290
|
+
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /* Margin */ / 2));
|
|
5239
5291
|
let map = this.heightMap, oracle = this.heightOracle;
|
|
5240
5292
|
let { visibleTop, visibleBottom } = this;
|
|
5241
|
-
let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1000 /*
|
|
5293
|
+
let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1000 /* Margin */, QueryType.ByHeight, oracle, 0, 0).from, map.lineAt(visibleBottom + (1 - marginTop) * 1000 /* Margin */, QueryType.ByHeight, oracle, 0, 0).to);
|
|
5242
5294
|
// If scrollTarget is given, make sure the viewport includes that position
|
|
5243
5295
|
if (scrollTarget) {
|
|
5244
5296
|
let { head } = scrollTarget.range;
|
|
@@ -5251,7 +5303,7 @@ class ViewState {
|
|
|
5251
5303
|
topPos = block.top;
|
|
5252
5304
|
else
|
|
5253
5305
|
topPos = block.bottom - viewHeight;
|
|
5254
|
-
viewport = new Viewport(map.lineAt(topPos - 1000 /*
|
|
5306
|
+
viewport = new Viewport(map.lineAt(topPos - 1000 /* Margin */ / 2, QueryType.ByHeight, oracle, 0, 0).from, map.lineAt(topPos + viewHeight + 1000 /* Margin */ / 2, QueryType.ByHeight, oracle, 0, 0).to);
|
|
5255
5307
|
}
|
|
5256
5308
|
}
|
|
5257
5309
|
return viewport;
|
|
@@ -5268,10 +5320,10 @@ class ViewState {
|
|
|
5268
5320
|
let { top } = this.heightMap.lineAt(from, QueryType.ByPos, this.heightOracle, 0, 0);
|
|
5269
5321
|
let { bottom } = this.heightMap.lineAt(to, QueryType.ByPos, this.heightOracle, 0, 0);
|
|
5270
5322
|
let { visibleTop, visibleBottom } = this;
|
|
5271
|
-
return (from == 0 || top <= visibleTop - Math.max(10 /*
|
|
5323
|
+
return (from == 0 || top <= visibleTop - Math.max(10 /* MinCoverMargin */, Math.min(-bias, 250 /* MaxCoverMargin */))) &&
|
|
5272
5324
|
(to == this.state.doc.length ||
|
|
5273
|
-
bottom >= visibleBottom + Math.max(10 /*
|
|
5274
|
-
(top > visibleTop - 2 * 1000 /*
|
|
5325
|
+
bottom >= visibleBottom + Math.max(10 /* MinCoverMargin */, Math.min(bias, 250 /* MaxCoverMargin */))) &&
|
|
5326
|
+
(top > visibleTop - 2 * 1000 /* Margin */ && bottom < visibleBottom + 2 * 1000 /* Margin */);
|
|
5275
5327
|
}
|
|
5276
5328
|
mapLineGaps(gaps, changes) {
|
|
5277
5329
|
if (!gaps.length || changes.empty)
|
|
@@ -5291,7 +5343,7 @@ class ViewState {
|
|
|
5291
5343
|
// the artifacts this might produce from the user.
|
|
5292
5344
|
ensureLineGaps(current, mayMeasure) {
|
|
5293
5345
|
let wrapping = this.heightOracle.lineWrapping;
|
|
5294
|
-
let margin = wrapping ? 10000 /*
|
|
5346
|
+
let margin = wrapping ? 10000 /* MarginWrap */ : 2000 /* Margin */, halfMargin = margin >> 1, doubleMargin = margin << 1;
|
|
5295
5347
|
// The non-wrapping logic won't work at all in predominantly right-to-left text.
|
|
5296
5348
|
if (this.defaultTextDirection != Direction.LTR && !wrapping)
|
|
5297
5349
|
return [];
|
|
@@ -5304,8 +5356,8 @@ class ViewState {
|
|
|
5304
5356
|
avoid.push(sel.to);
|
|
5305
5357
|
for (let pos of avoid) {
|
|
5306
5358
|
if (pos > from && pos < to) {
|
|
5307
|
-
addGap(from, pos - 10 /*
|
|
5308
|
-
addGap(pos + 10 /*
|
|
5359
|
+
addGap(from, pos - 10 /* SelectionMargin */, line, structure);
|
|
5360
|
+
addGap(pos + 10 /* SelectionMargin */, to, line, structure);
|
|
5309
5361
|
return;
|
|
5310
5362
|
}
|
|
5311
5363
|
}
|
|
@@ -5399,7 +5451,7 @@ class ViewState {
|
|
|
5399
5451
|
let changed = ranges.length != this.visibleRanges.length ||
|
|
5400
5452
|
this.visibleRanges.some((r, i) => r.from != ranges[i].from || r.to != ranges[i].to);
|
|
5401
5453
|
this.visibleRanges = ranges;
|
|
5402
|
-
return changed ? 4 /*
|
|
5454
|
+
return changed ? 4 /* Viewport */ : 0;
|
|
5403
5455
|
}
|
|
5404
5456
|
lineBlockAt(pos) {
|
|
5405
5457
|
return (pos >= this.viewport.from && pos <= this.viewport.to && this.viewportLines.find(b => b.from <= pos && b.to >= pos)) ||
|
|
@@ -5491,7 +5543,7 @@ class BigScaler {
|
|
|
5491
5543
|
vpHeight += bottom - top;
|
|
5492
5544
|
return { from, to, top, bottom, domTop: 0, domBottom: 0 };
|
|
5493
5545
|
});
|
|
5494
|
-
this.scale = (7000000 /*
|
|
5546
|
+
this.scale = (7000000 /* MaxDOMHeight */ - vpHeight) / (heightMap.height - vpHeight);
|
|
5495
5547
|
for (let obj of this.viewports) {
|
|
5496
5548
|
obj.domTop = domBase + (obj.top - base) * this.scale;
|
|
5497
5549
|
domBase = obj.domBottom = obj.domTop + (obj.bottom - obj.top);
|
|
@@ -5525,7 +5577,7 @@ function scaleBlock(block, scaler) {
|
|
|
5525
5577
|
if (scaler.scale == 1)
|
|
5526
5578
|
return block;
|
|
5527
5579
|
let bTop = scaler.toDOM(block.top), bBottom = scaler.toDOM(block.bottom);
|
|
5528
|
-
return new BlockInfo(block.from, block.length, bTop, bBottom - bTop, block.
|
|
5580
|
+
return new BlockInfo(block.from, block.length, bTop, bBottom - bTop, Array.isArray(block._content) ? block._content.map(b => scaleBlock(b, scaler)) : block._content);
|
|
5529
5581
|
}
|
|
5530
5582
|
|
|
5531
5583
|
const theme = /*@__PURE__*/Facet.define({ combine: strs => strs.join(" ") });
|
|
@@ -6385,7 +6437,7 @@ class DOMObserver {
|
|
|
6385
6437
|
return null;
|
|
6386
6438
|
cView.markDirty(rec.type == "attributes");
|
|
6387
6439
|
if (rec.type == "attributes")
|
|
6388
|
-
cView.dirty |= 4 /*
|
|
6440
|
+
cView.dirty |= 4 /* Attrs */;
|
|
6389
6441
|
if (rec.type == "childList") {
|
|
6390
6442
|
let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1);
|
|
6391
6443
|
let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1);
|
|
@@ -6508,7 +6560,7 @@ class EditorView {
|
|
|
6508
6560
|
/**
|
|
6509
6561
|
@internal
|
|
6510
6562
|
*/
|
|
6511
|
-
this.updateState = 2 /*
|
|
6563
|
+
this.updateState = 2 /* Updating */;
|
|
6512
6564
|
/**
|
|
6513
6565
|
@internal
|
|
6514
6566
|
*/
|
|
@@ -6541,7 +6593,7 @@ class EditorView {
|
|
|
6541
6593
|
this.docView = new DocView(this);
|
|
6542
6594
|
this.mountStyles();
|
|
6543
6595
|
this.updateAttrs();
|
|
6544
|
-
this.updateState = 0 /*
|
|
6596
|
+
this.updateState = 0 /* Idle */;
|
|
6545
6597
|
this.requestMeasure();
|
|
6546
6598
|
if (config.parent)
|
|
6547
6599
|
config.parent.appendChild(this.dom);
|
|
@@ -6594,8 +6646,9 @@ class EditorView {
|
|
|
6594
6646
|
*/
|
|
6595
6647
|
get win() { return this.dom.ownerDocument.defaultView || window; }
|
|
6596
6648
|
dispatch(...input) {
|
|
6597
|
-
|
|
6598
|
-
: this.state.update(...input)
|
|
6649
|
+
let tr = input.length == 1 && input[0] instanceof Transaction ? input[0]
|
|
6650
|
+
: this.state.update(...input);
|
|
6651
|
+
this._dispatch(tr, this);
|
|
6599
6652
|
}
|
|
6600
6653
|
/**
|
|
6601
6654
|
Update the view for the given array of transactions. This will
|
|
@@ -6606,7 +6659,7 @@ class EditorView {
|
|
|
6606
6659
|
as a primitive.
|
|
6607
6660
|
*/
|
|
6608
6661
|
update(transactions) {
|
|
6609
|
-
if (this.updateState != 0 /*
|
|
6662
|
+
if (this.updateState != 0 /* Idle */)
|
|
6610
6663
|
throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
|
|
6611
6664
|
let redrawn = false, attrsChanged = false, update;
|
|
6612
6665
|
let state = this.state;
|
|
@@ -6623,7 +6676,7 @@ class EditorView {
|
|
|
6623
6676
|
if (transactions.some(tr => tr.annotation(isFocusChange))) {
|
|
6624
6677
|
this.inputState.notifiedFocused = focus;
|
|
6625
6678
|
// If a focus-change transaction is being dispatched, set this update flag.
|
|
6626
|
-
focusFlag = 1 /*
|
|
6679
|
+
focusFlag = 1 /* Focus */;
|
|
6627
6680
|
}
|
|
6628
6681
|
else if (focus != this.inputState.notifiedFocused) {
|
|
6629
6682
|
this.inputState.notifiedFocused = focus;
|
|
@@ -6631,7 +6684,7 @@ class EditorView {
|
|
|
6631
6684
|
// add a flag to this update
|
|
6632
6685
|
dispatchFocus = focusChangeTransaction(state, focus);
|
|
6633
6686
|
if (!dispatchFocus)
|
|
6634
|
-
focusFlag = 1 /*
|
|
6687
|
+
focusFlag = 1 /* Focus */;
|
|
6635
6688
|
}
|
|
6636
6689
|
// If there was a pending DOM change, eagerly read it and try to
|
|
6637
6690
|
// apply it after the given transactions.
|
|
@@ -6654,7 +6707,7 @@ class EditorView {
|
|
|
6654
6707
|
update.flags |= focusFlag;
|
|
6655
6708
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6656
6709
|
try {
|
|
6657
|
-
this.updateState = 2 /*
|
|
6710
|
+
this.updateState = 2 /* Updating */;
|
|
6658
6711
|
for (let tr of transactions) {
|
|
6659
6712
|
if (scrollTarget)
|
|
6660
6713
|
scrollTarget = scrollTarget.map(tr.changes);
|
|
@@ -6680,7 +6733,7 @@ class EditorView {
|
|
|
6680
6733
|
this.docView.updateSelection(redrawn, transactions.some(tr => tr.isUserEvent("select.pointer")));
|
|
6681
6734
|
}
|
|
6682
6735
|
finally {
|
|
6683
|
-
this.updateState = 0 /*
|
|
6736
|
+
this.updateState = 0 /* Idle */;
|
|
6684
6737
|
}
|
|
6685
6738
|
if (update.startState.facet(theme) != update.state.facet(theme))
|
|
6686
6739
|
this.viewState.mustMeasureContent = true;
|
|
@@ -6707,13 +6760,13 @@ class EditorView {
|
|
|
6707
6760
|
[`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
|
|
6708
6761
|
*/
|
|
6709
6762
|
setState(newState) {
|
|
6710
|
-
if (this.updateState != 0 /*
|
|
6763
|
+
if (this.updateState != 0 /* Idle */)
|
|
6711
6764
|
throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");
|
|
6712
6765
|
if (this.destroyed) {
|
|
6713
6766
|
this.viewState.state = newState;
|
|
6714
6767
|
return;
|
|
6715
6768
|
}
|
|
6716
|
-
this.updateState = 2 /*
|
|
6769
|
+
this.updateState = 2 /* Updating */;
|
|
6717
6770
|
let hadFocus = this.hasFocus;
|
|
6718
6771
|
try {
|
|
6719
6772
|
for (let plugin of this.plugins)
|
|
@@ -6730,7 +6783,7 @@ class EditorView {
|
|
|
6730
6783
|
this.bidiCache = [];
|
|
6731
6784
|
}
|
|
6732
6785
|
finally {
|
|
6733
|
-
this.updateState = 0 /*
|
|
6786
|
+
this.updateState = 0 /* Idle */;
|
|
6734
6787
|
}
|
|
6735
6788
|
if (hadFocus)
|
|
6736
6789
|
this.focus();
|
|
@@ -6777,13 +6830,23 @@ class EditorView {
|
|
|
6777
6830
|
if (flush)
|
|
6778
6831
|
this.observer.forceFlush();
|
|
6779
6832
|
let updated = null;
|
|
6780
|
-
let
|
|
6781
|
-
|
|
6833
|
+
let sDOM = this.scrollDOM, { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
|
|
6834
|
+
this.viewState.scrollAnchorHeight = -1;
|
|
6835
|
+
if (scrollAnchorHeight < 0 || sDOM.scrollTop != this.viewState.scrollTop) {
|
|
6836
|
+
if (sDOM.scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
|
|
6837
|
+
scrollAnchorPos = -1;
|
|
6838
|
+
scrollAnchorHeight = this.viewState.heightMap.height;
|
|
6839
|
+
}
|
|
6840
|
+
else {
|
|
6841
|
+
let block = this.viewState.lineBlockAtHeight(sDOM.scrollTop);
|
|
6842
|
+
scrollAnchorPos = block.from;
|
|
6843
|
+
scrollAnchorHeight = block.top;
|
|
6844
|
+
}
|
|
6845
|
+
}
|
|
6782
6846
|
try {
|
|
6783
6847
|
for (let i = 0;; i++) {
|
|
6784
|
-
this.updateState = 1 /*
|
|
6848
|
+
this.updateState = 1 /* Measuring */;
|
|
6785
6849
|
let oldViewport = this.viewport;
|
|
6786
|
-
let refBlock = this.viewState.lineBlockAtHeight(refHeight);
|
|
6787
6850
|
let changed = this.viewState.measure(this);
|
|
6788
6851
|
if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
|
|
6789
6852
|
break;
|
|
@@ -6795,7 +6858,7 @@ class EditorView {
|
|
|
6795
6858
|
}
|
|
6796
6859
|
let measuring = [];
|
|
6797
6860
|
// Only run measure requests in this cycle when the viewport didn't change
|
|
6798
|
-
if (!(changed & 4 /*
|
|
6861
|
+
if (!(changed & 4 /* Viewport */))
|
|
6799
6862
|
[this.measureRequests, measuring] = [measuring, this.measureRequests];
|
|
6800
6863
|
let measured = measuring.map(m => {
|
|
6801
6864
|
try {
|
|
@@ -6812,7 +6875,7 @@ class EditorView {
|
|
|
6812
6875
|
updated = update;
|
|
6813
6876
|
else
|
|
6814
6877
|
updated.flags |= changed;
|
|
6815
|
-
this.updateState = 2 /*
|
|
6878
|
+
this.updateState = 2 /* Updating */;
|
|
6816
6879
|
if (!update.empty) {
|
|
6817
6880
|
this.updatePlugins(update);
|
|
6818
6881
|
this.inputState.update(update);
|
|
@@ -6836,10 +6899,12 @@ class EditorView {
|
|
|
6836
6899
|
this.viewState.scrollTarget = null;
|
|
6837
6900
|
scrolled = true;
|
|
6838
6901
|
}
|
|
6839
|
-
else {
|
|
6840
|
-
let
|
|
6902
|
+
else if (scrollAnchorHeight > -1) {
|
|
6903
|
+
let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height :
|
|
6904
|
+
this.viewState.lineBlockAt(scrollAnchorPos).top;
|
|
6905
|
+
let diff = newAnchorHeight - scrollAnchorHeight;
|
|
6841
6906
|
if (diff > 1 || diff < -1) {
|
|
6842
|
-
|
|
6907
|
+
sDOM.scrollTop += diff;
|
|
6843
6908
|
scrolled = true;
|
|
6844
6909
|
}
|
|
6845
6910
|
}
|
|
@@ -6849,10 +6914,11 @@ class EditorView {
|
|
|
6849
6914
|
if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to &&
|
|
6850
6915
|
!scrolled && this.measureRequests.length == 0)
|
|
6851
6916
|
break;
|
|
6917
|
+
scrollAnchorHeight = -1;
|
|
6852
6918
|
}
|
|
6853
6919
|
}
|
|
6854
6920
|
finally {
|
|
6855
|
-
this.updateState = 0 /*
|
|
6921
|
+
this.updateState = 0 /* Idle */;
|
|
6856
6922
|
this.measureScheduled = -1;
|
|
6857
6923
|
}
|
|
6858
6924
|
if (updated && !updated.empty)
|
|
@@ -6911,9 +6977,9 @@ class EditorView {
|
|
|
6911
6977
|
StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1).reverse());
|
|
6912
6978
|
}
|
|
6913
6979
|
readMeasured() {
|
|
6914
|
-
if (this.updateState == 2 /*
|
|
6980
|
+
if (this.updateState == 2 /* Updating */)
|
|
6915
6981
|
throw new Error("Reading the editor layout isn't allowed during an update");
|
|
6916
|
-
if (this.updateState == 0 /*
|
|
6982
|
+
if (this.updateState == 0 /* Idle */ && this.measureScheduled > -1)
|
|
6917
6983
|
this.measure(false);
|
|
6918
6984
|
}
|
|
6919
6985
|
/**
|
|
@@ -7707,15 +7773,6 @@ function wrappedLine(view, pos, inside) {
|
|
|
7707
7773
|
to: Math.min(inside.to, view.moveToLineBoundary(range, true, true).from),
|
|
7708
7774
|
type: BlockType.Text };
|
|
7709
7775
|
}
|
|
7710
|
-
function blockAt(view, pos) {
|
|
7711
|
-
let line = view.lineBlockAt(pos);
|
|
7712
|
-
if (Array.isArray(line.type))
|
|
7713
|
-
for (let l of line.type) {
|
|
7714
|
-
if (l.to > pos || l.to == pos && (l.to == line.to || l.type == BlockType.Text))
|
|
7715
|
-
return l;
|
|
7716
|
-
}
|
|
7717
|
-
return line;
|
|
7718
|
-
}
|
|
7719
7776
|
function rectanglesForRange(view, className, range) {
|
|
7720
7777
|
if (range.to <= view.viewport.from || range.from >= view.viewport.to)
|
|
7721
7778
|
return [];
|
|
@@ -7729,12 +7786,10 @@ function rectanglesForRange(view, className, range) {
|
|
|
7729
7786
|
let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
|
|
7730
7787
|
let visualStart = startBlock.type == BlockType.Text ? startBlock : null;
|
|
7731
7788
|
let visualEnd = endBlock.type == BlockType.Text ? endBlock : null;
|
|
7732
|
-
if (view.lineWrapping)
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
visualEnd = wrappedLine(view, to, visualEnd);
|
|
7737
|
-
}
|
|
7789
|
+
if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
|
|
7790
|
+
visualStart = wrappedLine(view, from, visualStart);
|
|
7791
|
+
if (visualEnd && (view.lineWrapping || endBlock.widgetLineBreaks))
|
|
7792
|
+
visualEnd = wrappedLine(view, to, visualEnd);
|
|
7738
7793
|
if (visualStart && visualEnd && visualStart.from == visualEnd.from) {
|
|
7739
7794
|
return pieces(drawForLine(range.from, range.to, visualStart));
|
|
7740
7795
|
}
|
|
@@ -7742,14 +7797,15 @@ function rectanglesForRange(view, className, range) {
|
|
|
7742
7797
|
let top = visualStart ? drawForLine(range.from, null, visualStart) : drawForWidget(startBlock, false);
|
|
7743
7798
|
let bottom = visualEnd ? drawForLine(null, range.to, visualEnd) : drawForWidget(endBlock, true);
|
|
7744
7799
|
let between = [];
|
|
7745
|
-
if ((visualStart || startBlock).to < (visualEnd || endBlock).from - (visualStart && visualEnd ? 1 : 0)
|
|
7800
|
+
if ((visualStart || startBlock).to < (visualEnd || endBlock).from - (visualStart && visualEnd ? 1 : 0) ||
|
|
7801
|
+
startBlock.widgetLineBreaks > 1 && top.bottom + view.defaultLineHeight / 2 < bottom.top)
|
|
7746
7802
|
between.push(piece(leftSide, top.bottom, rightSide, bottom.top));
|
|
7747
7803
|
else if (top.bottom < bottom.top && view.elementAtHeight((top.bottom + bottom.top) / 2).type == BlockType.Text)
|
|
7748
7804
|
top.bottom = bottom.top = (top.bottom + bottom.top) / 2;
|
|
7749
7805
|
return pieces(top).concat(between).concat(pieces(bottom));
|
|
7750
7806
|
}
|
|
7751
7807
|
function piece(left, top, right, bottom) {
|
|
7752
|
-
return new RectangleMarker(className, left - base.left, top - base.top - 0.01 /*
|
|
7808
|
+
return new RectangleMarker(className, left - base.left, top - base.top - 0.01 /* Epsilon */, right - left, bottom - top + 0.01 /* Epsilon */);
|
|
7753
7809
|
}
|
|
7754
7810
|
function pieces({ top, bottom, horizontal }) {
|
|
7755
7811
|
let pieces = [];
|
|
@@ -8764,12 +8820,12 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
8764
8820
|
continue;
|
|
8765
8821
|
}
|
|
8766
8822
|
let arrow = tooltip.arrow ? tView.dom.querySelector(".cm-tooltip-arrow") : null;
|
|
8767
|
-
let arrowHeight = arrow ? 7 /*
|
|
8823
|
+
let arrowHeight = arrow ? 7 /* Size */ : 0;
|
|
8768
8824
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
8769
8825
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
|
|
8770
8826
|
let left = size.width > space.right - space.left ? (ltr ? space.left : space.right - size.width)
|
|
8771
|
-
: ltr ? Math.min(pos.left - (arrow ? 14 /*
|
|
8772
|
-
: Math.max(space.left, pos.left - width + (arrow ? 14 /*
|
|
8827
|
+
: ltr ? Math.min(pos.left - (arrow ? 14 /* Offset */ : 0) + offset.x, space.right - width)
|
|
8828
|
+
: Math.max(space.left, pos.left - width + (arrow ? 14 /* Offset */ : 0) - offset.x);
|
|
8773
8829
|
let above = !!tooltip.above;
|
|
8774
8830
|
if (!tooltip.strictSide && (above
|
|
8775
8831
|
? pos.top - (size.bottom - size.top) - offset.y < space.top
|
|
@@ -8803,7 +8859,7 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
8803
8859
|
dom.style.left = left + "px";
|
|
8804
8860
|
}
|
|
8805
8861
|
if (arrow)
|
|
8806
|
-
arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /*
|
|
8862
|
+
arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Offset */ - 7 /* Size */)}px`;
|
|
8807
8863
|
if (tView.overlap !== true)
|
|
8808
8864
|
others.push({ left, top, right, bottom: top + height });
|
|
8809
8865
|
dom.classList.toggle("cm-tooltip-above", above);
|
|
@@ -8846,8 +8902,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
8846
8902
|
color: "white"
|
|
8847
8903
|
},
|
|
8848
8904
|
".cm-tooltip-arrow": {
|
|
8849
|
-
height: `${7 /*
|
|
8850
|
-
width: `${7 /*
|
|
8905
|
+
height: `${7 /* Size */}px`,
|
|
8906
|
+
width: `${7 /* Size */ * 2}px`,
|
|
8851
8907
|
position: "absolute",
|
|
8852
8908
|
zIndex: -1,
|
|
8853
8909
|
overflow: "hidden",
|
|
@@ -8856,26 +8912,26 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
|
8856
8912
|
position: "absolute",
|
|
8857
8913
|
width: 0,
|
|
8858
8914
|
height: 0,
|
|
8859
|
-
borderLeft: `${7 /*
|
|
8860
|
-
borderRight: `${7 /*
|
|
8915
|
+
borderLeft: `${7 /* Size */}px solid transparent`,
|
|
8916
|
+
borderRight: `${7 /* Size */}px solid transparent`,
|
|
8861
8917
|
},
|
|
8862
8918
|
".cm-tooltip-above &": {
|
|
8863
|
-
bottom: `-${7 /*
|
|
8919
|
+
bottom: `-${7 /* Size */}px`,
|
|
8864
8920
|
"&:before": {
|
|
8865
|
-
borderTop: `${7 /*
|
|
8921
|
+
borderTop: `${7 /* Size */}px solid #bbb`,
|
|
8866
8922
|
},
|
|
8867
8923
|
"&:after": {
|
|
8868
|
-
borderTop: `${7 /*
|
|
8924
|
+
borderTop: `${7 /* Size */}px solid #f5f5f5`,
|
|
8869
8925
|
bottom: "1px"
|
|
8870
8926
|
}
|
|
8871
8927
|
},
|
|
8872
8928
|
".cm-tooltip-below &": {
|
|
8873
|
-
top: `-${7 /*
|
|
8929
|
+
top: `-${7 /* Size */}px`,
|
|
8874
8930
|
"&:before": {
|
|
8875
|
-
borderBottom: `${7 /*
|
|
8931
|
+
borderBottom: `${7 /* Size */}px solid #bbb`,
|
|
8876
8932
|
},
|
|
8877
8933
|
"&:after": {
|
|
8878
|
-
borderBottom: `${7 /*
|
|
8934
|
+
borderBottom: `${7 /* Size */}px solid #f5f5f5`,
|
|
8879
8935
|
top: "1px"
|
|
8880
8936
|
}
|
|
8881
8937
|
},
|
|
@@ -9025,7 +9081,7 @@ class HoverPlugin {
|
|
|
9025
9081
|
if (tooltip && !isInTooltip(this.lastMove.target) || this.pending) {
|
|
9026
9082
|
let { pos } = tooltip || this.pending, end = (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.end) !== null && _a !== void 0 ? _a : pos;
|
|
9027
9083
|
if ((pos == end ? this.view.posAtCoords(this.lastMove) != pos
|
|
9028
|
-
: !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /*
|
|
9084
|
+
: !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /* MaxDist */))) {
|
|
9029
9085
|
this.view.dispatch({ effects: this.setHover.of(null) });
|
|
9030
9086
|
this.pending = null;
|
|
9031
9087
|
}
|
|
@@ -9107,7 +9163,7 @@ function hoverTooltip(source, options = {}) {
|
|
|
9107
9163
|
});
|
|
9108
9164
|
return [
|
|
9109
9165
|
hoverState,
|
|
9110
|
-
ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /*
|
|
9166
|
+
ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /* Time */)),
|
|
9111
9167
|
showHoverTooltipHost
|
|
9112
9168
|
];
|
|
9113
9169
|
}
|