@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.cjs
CHANGED
|
@@ -335,7 +335,7 @@ class ContentView {
|
|
|
335
335
|
constructor() {
|
|
336
336
|
this.parent = null;
|
|
337
337
|
this.dom = null;
|
|
338
|
-
this.dirty = 2 /*
|
|
338
|
+
this.dirty = 2 /* Node */;
|
|
339
339
|
}
|
|
340
340
|
get overrideDOMText() { return null; }
|
|
341
341
|
get posAtStart() {
|
|
@@ -357,7 +357,7 @@ class ContentView {
|
|
|
357
357
|
return this.posBefore(view) + view.length;
|
|
358
358
|
}
|
|
359
359
|
sync(view, track) {
|
|
360
|
-
if (this.dirty & 2 /*
|
|
360
|
+
if (this.dirty & 2 /* Node */) {
|
|
361
361
|
let parent = this.dom;
|
|
362
362
|
let prev = null, next;
|
|
363
363
|
for (let child of this.children) {
|
|
@@ -368,7 +368,7 @@ class ContentView {
|
|
|
368
368
|
child.reuseDOM(next);
|
|
369
369
|
}
|
|
370
370
|
child.sync(view, track);
|
|
371
|
-
child.dirty = 0 /*
|
|
371
|
+
child.dirty = 0 /* Not */;
|
|
372
372
|
}
|
|
373
373
|
next = prev ? prev.nextSibling : parent.firstChild;
|
|
374
374
|
if (track && !track.written && track.node == parent && next != child.dom)
|
|
@@ -388,11 +388,11 @@ class ContentView {
|
|
|
388
388
|
while (next)
|
|
389
389
|
next = rm$1(next);
|
|
390
390
|
}
|
|
391
|
-
else if (this.dirty & 1 /*
|
|
391
|
+
else if (this.dirty & 1 /* Child */) {
|
|
392
392
|
for (let child of this.children)
|
|
393
393
|
if (child.dirty) {
|
|
394
394
|
child.sync(view, track);
|
|
395
|
-
child.dirty = 0 /*
|
|
395
|
+
child.dirty = 0 /* Not */;
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
398
|
}
|
|
@@ -457,16 +457,16 @@ class ContentView {
|
|
|
457
457
|
endDOM: toI < this.children.length && toI >= 0 ? this.children[toI].dom : null };
|
|
458
458
|
}
|
|
459
459
|
markDirty(andParent = false) {
|
|
460
|
-
this.dirty |= 2 /*
|
|
460
|
+
this.dirty |= 2 /* Node */;
|
|
461
461
|
this.markParentsDirty(andParent);
|
|
462
462
|
}
|
|
463
463
|
markParentsDirty(childList) {
|
|
464
464
|
for (let parent = this.parent; parent; parent = parent.parent) {
|
|
465
465
|
if (childList)
|
|
466
|
-
parent.dirty |= 2 /*
|
|
467
|
-
if (parent.dirty & 1 /*
|
|
466
|
+
parent.dirty |= 2 /* Node */;
|
|
467
|
+
if (parent.dirty & 1 /* Child */)
|
|
468
468
|
return;
|
|
469
|
-
parent.dirty |= 1 /*
|
|
469
|
+
parent.dirty |= 1 /* Child */;
|
|
470
470
|
childList = false;
|
|
471
471
|
}
|
|
472
472
|
}
|
|
@@ -745,13 +745,13 @@ class MarkView extends ContentView {
|
|
|
745
745
|
reuseDOM(node) {
|
|
746
746
|
if (node.nodeName == this.mark.tagName.toUpperCase()) {
|
|
747
747
|
this.setDOM(node);
|
|
748
|
-
this.dirty |= 4 /*
|
|
748
|
+
this.dirty |= 4 /* Attrs */ | 2 /* Node */;
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
sync(view, track) {
|
|
752
752
|
if (!this.dom)
|
|
753
753
|
this.setDOM(this.setAttrs(document.createElement(this.mark.tagName)));
|
|
754
|
-
else if (this.dirty & 4 /*
|
|
754
|
+
else if (this.dirty & 4 /* Attrs */)
|
|
755
755
|
this.setAttrs(this.dom);
|
|
756
756
|
super.sync(view, track);
|
|
757
757
|
}
|
|
@@ -891,12 +891,13 @@ class WidgetView extends ContentView {
|
|
|
891
891
|
let rects = this.dom.getClientRects(), rect = null;
|
|
892
892
|
if (!rects.length)
|
|
893
893
|
return null;
|
|
894
|
-
|
|
894
|
+
let fromBack = this.side ? this.side < 0 : pos > 0;
|
|
895
|
+
for (let i = fromBack ? rects.length - 1 : 0;; i += (fromBack ? -1 : 1)) {
|
|
895
896
|
rect = rects[i];
|
|
896
897
|
if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom)
|
|
897
898
|
break;
|
|
898
899
|
}
|
|
899
|
-
return this.length ? rect : flattenRect(rect,
|
|
900
|
+
return this.length ? rect : flattenRect(rect, !fromBack);
|
|
900
901
|
}
|
|
901
902
|
get isEditable() { return false; }
|
|
902
903
|
get isWidget() { return true; }
|
|
@@ -1216,6 +1217,13 @@ class WidgetType {
|
|
|
1216
1217
|
*/
|
|
1217
1218
|
get estimatedHeight() { return -1; }
|
|
1218
1219
|
/**
|
|
1220
|
+
For inline widgets that are displayed inline (as opposed to
|
|
1221
|
+
`inline-block`) and introduce line breaks (through `<br>` tags
|
|
1222
|
+
or textual newlines), this must indicate the amount of line
|
|
1223
|
+
breaks they introduce. Defaults to 0.
|
|
1224
|
+
*/
|
|
1225
|
+
get lineBreaks() { return 0; }
|
|
1226
|
+
/**
|
|
1219
1227
|
Can be used to configure which kinds of events inside the widget
|
|
1220
1228
|
should be ignored by the editor. The default is to ignore all
|
|
1221
1229
|
events.
|
|
@@ -1318,8 +1326,8 @@ class Decoration extends state.RangeValue {
|
|
|
1318
1326
|
given position.
|
|
1319
1327
|
*/
|
|
1320
1328
|
static widget(spec) {
|
|
1321
|
-
let side = spec.side || 0, block = !!spec.block;
|
|
1322
|
-
side += block ? (side > 0 ? 300000000 /*
|
|
1329
|
+
let side = Math.max(-10000, Math.min(10000, spec.side || 0)), block = !!spec.block;
|
|
1330
|
+
side += block ? (side > 0 ? 300000000 /* BlockAfter */ : -400000000 /* BlockBefore */) : (side > 0 ? 100000000 /* InlineAfter */ : -100000000 /* InlineBefore */);
|
|
1323
1331
|
return new PointDecoration(spec, side, side, block, spec.widget || null, false);
|
|
1324
1332
|
}
|
|
1325
1333
|
/**
|
|
@@ -1329,13 +1337,13 @@ class Decoration extends state.RangeValue {
|
|
|
1329
1337
|
static replace(spec) {
|
|
1330
1338
|
let block = !!spec.block, startSide, endSide;
|
|
1331
1339
|
if (spec.isBlockGap) {
|
|
1332
|
-
startSide = -500000000 /*
|
|
1333
|
-
endSide = 400000000 /*
|
|
1340
|
+
startSide = -500000000 /* GapStart */;
|
|
1341
|
+
endSide = 400000000 /* GapEnd */;
|
|
1334
1342
|
}
|
|
1335
1343
|
else {
|
|
1336
1344
|
let { start, end } = getInclusive(spec, block);
|
|
1337
|
-
startSide = (start ? (block ? -300000000 /*
|
|
1338
|
-
endSide = (end ? (block ? 200000000 /*
|
|
1345
|
+
startSide = (start ? (block ? -300000000 /* BlockIncStart */ : -1 /* InlineIncStart */) : 500000000 /* NonIncStart */) - 1;
|
|
1346
|
+
endSide = (end ? (block ? 200000000 /* BlockIncEnd */ : 1 /* InlineIncEnd */) : -600000000 /* NonIncEnd */) + 1;
|
|
1339
1347
|
}
|
|
1340
1348
|
return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
|
|
1341
1349
|
}
|
|
@@ -1366,7 +1374,7 @@ Decoration.none = state.RangeSet.empty;
|
|
|
1366
1374
|
class MarkDecoration extends Decoration {
|
|
1367
1375
|
constructor(spec) {
|
|
1368
1376
|
let { start, end } = getInclusive(spec);
|
|
1369
|
-
super(start ? -1 /*
|
|
1377
|
+
super(start ? -1 /* InlineIncStart */ : 500000000 /* NonIncStart */, end ? 1 /* InlineIncEnd */ : -600000000 /* NonIncEnd */, null, spec);
|
|
1370
1378
|
this.tagName = spec.tagName || "span";
|
|
1371
1379
|
this.class = spec.class || "";
|
|
1372
1380
|
this.attrs = spec.attributes || null;
|
|
@@ -1387,7 +1395,7 @@ class MarkDecoration extends Decoration {
|
|
|
1387
1395
|
MarkDecoration.prototype.point = false;
|
|
1388
1396
|
class LineDecoration extends Decoration {
|
|
1389
1397
|
constructor(spec) {
|
|
1390
|
-
super(-200000000 /*
|
|
1398
|
+
super(-200000000 /* Line */, -200000000 /* Line */, null, spec);
|
|
1391
1399
|
}
|
|
1392
1400
|
eq(other) {
|
|
1393
1401
|
return other instanceof LineDecoration &&
|
|
@@ -1414,7 +1422,9 @@ class PointDecoration extends Decoration {
|
|
|
1414
1422
|
return this.startSide < this.endSide ? exports.BlockType.WidgetRange
|
|
1415
1423
|
: this.startSide <= 0 ? exports.BlockType.WidgetBefore : exports.BlockType.WidgetAfter;
|
|
1416
1424
|
}
|
|
1417
|
-
get heightRelevant() {
|
|
1425
|
+
get heightRelevant() {
|
|
1426
|
+
return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0);
|
|
1427
|
+
}
|
|
1418
1428
|
eq(other) {
|
|
1419
1429
|
return other instanceof PointDecoration &&
|
|
1420
1430
|
widgetsEq(this.widget, other.widget) &&
|
|
@@ -1526,7 +1536,7 @@ class LineView extends ContentView {
|
|
|
1526
1536
|
reuseDOM(node) {
|
|
1527
1537
|
if (node.nodeName == "DIV") {
|
|
1528
1538
|
this.setDOM(node);
|
|
1529
|
-
this.dirty |= 4 /*
|
|
1539
|
+
this.dirty |= 4 /* Attrs */ | 2 /* Node */;
|
|
1530
1540
|
}
|
|
1531
1541
|
}
|
|
1532
1542
|
sync(view, track) {
|
|
@@ -1536,7 +1546,7 @@ class LineView extends ContentView {
|
|
|
1536
1546
|
this.dom.className = "cm-line";
|
|
1537
1547
|
this.prevAttrs = this.attrs ? null : undefined;
|
|
1538
1548
|
}
|
|
1539
|
-
else if (this.dirty & 4 /*
|
|
1549
|
+
else if (this.dirty & 4 /* Attrs */) {
|
|
1540
1550
|
clearAttributes(this.dom);
|
|
1541
1551
|
this.dom.className = "cm-line";
|
|
1542
1552
|
this.prevAttrs = this.attrs ? null : undefined;
|
|
@@ -1684,7 +1694,7 @@ class ContentBuilder {
|
|
|
1684
1694
|
this.content = [];
|
|
1685
1695
|
this.curLine = null;
|
|
1686
1696
|
this.breakAtStart = 0;
|
|
1687
|
-
this.pendingBuffer = 0 /*
|
|
1697
|
+
this.pendingBuffer = 0 /* No */;
|
|
1688
1698
|
this.bufferMarks = [];
|
|
1689
1699
|
// Set to false directly after a widget that covers the position after it
|
|
1690
1700
|
this.atCursorPos = true;
|
|
@@ -1711,7 +1721,7 @@ class ContentBuilder {
|
|
|
1711
1721
|
flushBuffer(active = this.bufferMarks) {
|
|
1712
1722
|
if (this.pendingBuffer) {
|
|
1713
1723
|
this.curLine.append(wrapMarks(new WidgetBufferView(-1), active), active.length);
|
|
1714
|
-
this.pendingBuffer = 0 /*
|
|
1724
|
+
this.pendingBuffer = 0 /* No */;
|
|
1715
1725
|
}
|
|
1716
1726
|
}
|
|
1717
1727
|
addBlockWidget(view) {
|
|
@@ -1723,7 +1733,7 @@ class ContentBuilder {
|
|
|
1723
1733
|
if (this.pendingBuffer && openEnd <= this.bufferMarks.length)
|
|
1724
1734
|
this.flushBuffer();
|
|
1725
1735
|
else
|
|
1726
|
-
this.pendingBuffer = 0 /*
|
|
1736
|
+
this.pendingBuffer = 0 /* No */;
|
|
1727
1737
|
if (!this.posCovered())
|
|
1728
1738
|
this.getLine();
|
|
1729
1739
|
}
|
|
@@ -1752,7 +1762,7 @@ class ContentBuilder {
|
|
|
1752
1762
|
this.textOff = 0;
|
|
1753
1763
|
}
|
|
1754
1764
|
}
|
|
1755
|
-
let take = Math.min(this.text.length - this.textOff, length, 512 /*
|
|
1765
|
+
let take = Math.min(this.text.length - this.textOff, length, 512 /* Chunk */);
|
|
1756
1766
|
this.flushBuffer(active.slice(active.length - openStart));
|
|
1757
1767
|
this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
|
|
1758
1768
|
this.atCursorPos = true;
|
|
@@ -1788,8 +1798,8 @@ class ContentBuilder {
|
|
|
1788
1798
|
(from < to || deco.startSide > 0);
|
|
1789
1799
|
let cursorAfter = !view.isEditable && (from < to || openStart > active.length || deco.startSide <= 0);
|
|
1790
1800
|
let line = this.getLine();
|
|
1791
|
-
if (this.pendingBuffer == 2 /*
|
|
1792
|
-
this.pendingBuffer = 0 /*
|
|
1801
|
+
if (this.pendingBuffer == 2 /* IfCursor */ && !cursorBefore && !view.isEditable)
|
|
1802
|
+
this.pendingBuffer = 0 /* No */;
|
|
1793
1803
|
this.flushBuffer(active);
|
|
1794
1804
|
if (cursorBefore) {
|
|
1795
1805
|
line.append(wrapMarks(new WidgetBufferView(1), active), openStart);
|
|
@@ -1797,7 +1807,7 @@ class ContentBuilder {
|
|
|
1797
1807
|
}
|
|
1798
1808
|
line.append(wrapMarks(view, active), openStart);
|
|
1799
1809
|
this.atCursorPos = cursorAfter;
|
|
1800
|
-
this.pendingBuffer = !cursorAfter ? 0 /*
|
|
1810
|
+
this.pendingBuffer = !cursorAfter ? 0 /* No */ : from < to || openStart > active.length ? 1 /* Yes */ : 2 /* IfCursor */;
|
|
1801
1811
|
if (this.pendingBuffer)
|
|
1802
1812
|
this.bufferMarks = active.slice();
|
|
1803
1813
|
}
|
|
@@ -2124,27 +2134,27 @@ class ViewUpdate {
|
|
|
2124
2134
|
update.
|
|
2125
2135
|
*/
|
|
2126
2136
|
get viewportChanged() {
|
|
2127
|
-
return (this.flags & 4 /*
|
|
2137
|
+
return (this.flags & 4 /* Viewport */) > 0;
|
|
2128
2138
|
}
|
|
2129
2139
|
/**
|
|
2130
2140
|
Indicates whether the height of a block element in the editor
|
|
2131
2141
|
changed in this update.
|
|
2132
2142
|
*/
|
|
2133
2143
|
get heightChanged() {
|
|
2134
|
-
return (this.flags & 2 /*
|
|
2144
|
+
return (this.flags & 2 /* Height */) > 0;
|
|
2135
2145
|
}
|
|
2136
2146
|
/**
|
|
2137
2147
|
Returns true when the document was modified or the size of the
|
|
2138
2148
|
editor, or elements within the editor, changed.
|
|
2139
2149
|
*/
|
|
2140
2150
|
get geometryChanged() {
|
|
2141
|
-
return this.docChanged || (this.flags & (8 /*
|
|
2151
|
+
return this.docChanged || (this.flags & (8 /* Geometry */ | 2 /* Height */)) > 0;
|
|
2142
2152
|
}
|
|
2143
2153
|
/**
|
|
2144
2154
|
True when this update indicates a focus change.
|
|
2145
2155
|
*/
|
|
2146
2156
|
get focusChanged() {
|
|
2147
|
-
return (this.flags & 1 /*
|
|
2157
|
+
return (this.flags & 1 /* Focus */) > 0;
|
|
2148
2158
|
}
|
|
2149
2159
|
/**
|
|
2150
2160
|
Whether the document changed in this update.
|
|
@@ -2203,12 +2213,12 @@ for (let p of ["()", "[]", "{}"]) {
|
|
|
2203
2213
|
}
|
|
2204
2214
|
function charType(ch) {
|
|
2205
2215
|
return ch <= 0xf7 ? LowTypes[ch] :
|
|
2206
|
-
0x590 <= ch && ch <= 0x5f4 ? 2 /*
|
|
2216
|
+
0x590 <= ch && ch <= 0x5f4 ? 2 /* R */ :
|
|
2207
2217
|
0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
|
|
2208
|
-
0x6ee <= ch && ch <= 0x8ac ? 4 /*
|
|
2209
|
-
0x2000 <= ch && ch <= 0x200b ? 256 /*
|
|
2210
|
-
0xfb50 <= ch && ch <= 0xfdff ? 4 /*
|
|
2211
|
-
ch == 0x200c ? 256 /*
|
|
2218
|
+
0x6ee <= ch && ch <= 0x8ac ? 4 /* AL */ :
|
|
2219
|
+
0x2000 <= ch && ch <= 0x200b ? 256 /* NI */ :
|
|
2220
|
+
0xfb50 <= ch && ch <= 0xfdff ? 4 /* AL */ :
|
|
2221
|
+
ch == 0x200c ? 256 /* NI */ : 1 /* L */;
|
|
2212
2222
|
}
|
|
2213
2223
|
const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
|
|
2214
2224
|
/**
|
|
@@ -2273,8 +2283,8 @@ class BidiSpan {
|
|
|
2273
2283
|
// Reused array of character types
|
|
2274
2284
|
const types = [];
|
|
2275
2285
|
function computeOrder(line, direction) {
|
|
2276
|
-
let len = line.length, outerType = direction == LTR ? 1 /*
|
|
2277
|
-
if (!line || outerType == 1 /*
|
|
2286
|
+
let len = line.length, outerType = direction == LTR ? 1 /* L */ : 2 /* R */, oppositeType = direction == LTR ? 2 /* R */ : 1 /* L */;
|
|
2287
|
+
if (!line || outerType == 1 /* L */ && !BidiRE.test(line))
|
|
2278
2288
|
return trivialOrder(len);
|
|
2279
2289
|
// W1. Examine each non-spacing mark (NSM) in the level run, and
|
|
2280
2290
|
// change the type of the NSM to the type of the previous
|
|
@@ -2288,12 +2298,12 @@ function computeOrder(line, direction) {
|
|
|
2288
2298
|
// (Left after this: L, R, EN, AN, ET, CS, NI)
|
|
2289
2299
|
for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
|
|
2290
2300
|
let type = charType(line.charCodeAt(i));
|
|
2291
|
-
if (type == 512 /*
|
|
2301
|
+
if (type == 512 /* NSM */)
|
|
2292
2302
|
type = prev;
|
|
2293
|
-
else if (type == 8 /*
|
|
2294
|
-
type = 16 /*
|
|
2295
|
-
types[i] = type == 4 /*
|
|
2296
|
-
if (type & 7 /*
|
|
2303
|
+
else if (type == 8 /* EN */ && prevStrong == 4 /* AL */)
|
|
2304
|
+
type = 16 /* AN */;
|
|
2305
|
+
types[i] = type == 4 /* AL */ ? 2 /* R */ : type;
|
|
2306
|
+
if (type & 7 /* Strong */)
|
|
2297
2307
|
prevStrong = type;
|
|
2298
2308
|
prev = type;
|
|
2299
2309
|
}
|
|
@@ -2307,26 +2317,26 @@ function computeOrder(line, direction) {
|
|
|
2307
2317
|
// (Left after this: L, R, EN+AN, NI)
|
|
2308
2318
|
for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
|
|
2309
2319
|
let type = types[i];
|
|
2310
|
-
if (type == 128 /*
|
|
2311
|
-
if (i < len - 1 && prev == types[i + 1] && (prev & 24 /*
|
|
2320
|
+
if (type == 128 /* CS */) {
|
|
2321
|
+
if (i < len - 1 && prev == types[i + 1] && (prev & 24 /* Num */))
|
|
2312
2322
|
type = types[i] = prev;
|
|
2313
2323
|
else
|
|
2314
|
-
types[i] = 256 /*
|
|
2324
|
+
types[i] = 256 /* NI */;
|
|
2315
2325
|
}
|
|
2316
|
-
else if (type == 64 /*
|
|
2326
|
+
else if (type == 64 /* ET */) {
|
|
2317
2327
|
let end = i + 1;
|
|
2318
|
-
while (end < len && types[end] == 64 /*
|
|
2328
|
+
while (end < len && types[end] == 64 /* ET */)
|
|
2319
2329
|
end++;
|
|
2320
|
-
let replace = (i && prev == 8 /*
|
|
2330
|
+
let replace = (i && prev == 8 /* EN */) || (end < len && types[end] == 8 /* EN */) ? (prevStrong == 1 /* L */ ? 1 /* L */ : 8 /* EN */) : 256 /* NI */;
|
|
2321
2331
|
for (let j = i; j < end; j++)
|
|
2322
2332
|
types[j] = replace;
|
|
2323
2333
|
i = end - 1;
|
|
2324
2334
|
}
|
|
2325
|
-
else if (type == 8 /*
|
|
2326
|
-
types[i] = 1 /*
|
|
2335
|
+
else if (type == 8 /* EN */ && prevStrong == 1 /* L */) {
|
|
2336
|
+
types[i] = 1 /* L */;
|
|
2327
2337
|
}
|
|
2328
2338
|
prev = type;
|
|
2329
|
-
if (type & 7 /*
|
|
2339
|
+
if (type & 7 /* Strong */)
|
|
2330
2340
|
prevStrong = type;
|
|
2331
2341
|
}
|
|
2332
2342
|
// N0. Process bracket pairs in an isolating run sequence
|
|
@@ -2341,9 +2351,9 @@ function computeOrder(line, direction) {
|
|
|
2341
2351
|
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
2342
2352
|
if (BracketStack[sJ + 1] == -br) {
|
|
2343
2353
|
let flags = BracketStack[sJ + 2];
|
|
2344
|
-
let type = (flags & 2 /*
|
|
2345
|
-
!(flags & 4 /*
|
|
2346
|
-
(flags & 1 /*
|
|
2354
|
+
let type = (flags & 2 /* EmbedInside */) ? outerType :
|
|
2355
|
+
!(flags & 4 /* OppositeInside */) ? 0 :
|
|
2356
|
+
(flags & 1 /* OppositeBefore */) ? oppositeType : outerType;
|
|
2347
2357
|
if (type)
|
|
2348
2358
|
types[i] = types[BracketStack[sJ]] = type;
|
|
2349
2359
|
sI = sJ;
|
|
@@ -2351,7 +2361,7 @@ function computeOrder(line, direction) {
|
|
|
2351
2361
|
}
|
|
2352
2362
|
}
|
|
2353
2363
|
}
|
|
2354
|
-
else if (BracketStack.length == 189 /*
|
|
2364
|
+
else if (BracketStack.length == 189 /* MaxDepth */) {
|
|
2355
2365
|
break;
|
|
2356
2366
|
}
|
|
2357
2367
|
else {
|
|
@@ -2360,20 +2370,20 @@ function computeOrder(line, direction) {
|
|
|
2360
2370
|
BracketStack[sI++] = context;
|
|
2361
2371
|
}
|
|
2362
2372
|
}
|
|
2363
|
-
else if ((type = types[i]) == 2 /*
|
|
2373
|
+
else if ((type = types[i]) == 2 /* R */ || type == 1 /* L */) {
|
|
2364
2374
|
let embed = type == outerType;
|
|
2365
|
-
context = embed ? 0 : 1 /*
|
|
2375
|
+
context = embed ? 0 : 1 /* OppositeBefore */;
|
|
2366
2376
|
for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
|
|
2367
2377
|
let cur = BracketStack[sJ + 2];
|
|
2368
|
-
if (cur & 2 /*
|
|
2378
|
+
if (cur & 2 /* EmbedInside */)
|
|
2369
2379
|
break;
|
|
2370
2380
|
if (embed) {
|
|
2371
|
-
BracketStack[sJ + 2] |= 2 /*
|
|
2381
|
+
BracketStack[sJ + 2] |= 2 /* EmbedInside */;
|
|
2372
2382
|
}
|
|
2373
2383
|
else {
|
|
2374
|
-
if (cur & 4 /*
|
|
2384
|
+
if (cur & 4 /* OppositeInside */)
|
|
2375
2385
|
break;
|
|
2376
|
-
BracketStack[sJ + 2] |= 4 /*
|
|
2386
|
+
BracketStack[sJ + 2] |= 4 /* OppositeInside */;
|
|
2377
2387
|
}
|
|
2378
2388
|
}
|
|
2379
2389
|
}
|
|
@@ -2386,13 +2396,13 @@ function computeOrder(line, direction) {
|
|
|
2386
2396
|
// N2. Any remaining neutrals take the embedding direction.
|
|
2387
2397
|
// (Left after this: L, R, EN+AN)
|
|
2388
2398
|
for (let i = 0; i < len; i++) {
|
|
2389
|
-
if (types[i] == 256 /*
|
|
2399
|
+
if (types[i] == 256 /* NI */) {
|
|
2390
2400
|
let end = i + 1;
|
|
2391
|
-
while (end < len && types[end] == 256 /*
|
|
2401
|
+
while (end < len && types[end] == 256 /* NI */)
|
|
2392
2402
|
end++;
|
|
2393
|
-
let beforeL = (i ? types[i - 1] : outerType) == 1 /*
|
|
2394
|
-
let afterL = (end < len ? types[end] : outerType) == 1 /*
|
|
2395
|
-
let replace = beforeL == afterL ? (beforeL ? 1 /*
|
|
2403
|
+
let beforeL = (i ? types[i - 1] : outerType) == 1 /* L */;
|
|
2404
|
+
let afterL = (end < len ? types[end] : outerType) == 1 /* L */;
|
|
2405
|
+
let replace = beforeL == afterL ? (beforeL ? 1 /* L */ : 2 /* R */) : outerType;
|
|
2396
2406
|
for (let j = i; j < end; j++)
|
|
2397
2407
|
types[j] = replace;
|
|
2398
2408
|
i = end - 1;
|
|
@@ -2404,15 +2414,15 @@ function computeOrder(line, direction) {
|
|
|
2404
2414
|
// explicit embedding into account, we can build up the order on
|
|
2405
2415
|
// the fly, without following the level-based algorithm.
|
|
2406
2416
|
let order = [];
|
|
2407
|
-
if (outerType == 1 /*
|
|
2417
|
+
if (outerType == 1 /* L */) {
|
|
2408
2418
|
for (let i = 0; i < len;) {
|
|
2409
|
-
let start = i, rtl = types[i++] != 1 /*
|
|
2410
|
-
while (i < len && rtl == (types[i] != 1 /*
|
|
2419
|
+
let start = i, rtl = types[i++] != 1 /* L */;
|
|
2420
|
+
while (i < len && rtl == (types[i] != 1 /* L */))
|
|
2411
2421
|
i++;
|
|
2412
2422
|
if (rtl) {
|
|
2413
2423
|
for (let j = i; j > start;) {
|
|
2414
|
-
let end = j, l = types[--j] != 2 /*
|
|
2415
|
-
while (j > start && l == (types[j - 1] != 2 /*
|
|
2424
|
+
let end = j, l = types[--j] != 2 /* R */;
|
|
2425
|
+
while (j > start && l == (types[j - 1] != 2 /* R */))
|
|
2416
2426
|
j--;
|
|
2417
2427
|
order.push(new BidiSpan(j, end, l ? 2 : 1));
|
|
2418
2428
|
}
|
|
@@ -2424,8 +2434,8 @@ function computeOrder(line, direction) {
|
|
|
2424
2434
|
}
|
|
2425
2435
|
else {
|
|
2426
2436
|
for (let i = 0; i < len;) {
|
|
2427
|
-
let start = i, rtl = types[i++] == 2 /*
|
|
2428
|
-
while (i < len && rtl == (types[i] == 2 /*
|
|
2437
|
+
let start = i, rtl = types[i++] == 2 /* R */;
|
|
2438
|
+
while (i < len && rtl == (types[i] == 2 /* R */))
|
|
2429
2439
|
i++;
|
|
2430
2440
|
order.push(new BidiSpan(start, i, rtl ? 1 : 2));
|
|
2431
2441
|
}
|
|
@@ -2482,7 +2492,6 @@ class DOMReader {
|
|
|
2482
2492
|
constructor(points, state$1) {
|
|
2483
2493
|
this.points = points;
|
|
2484
2494
|
this.text = "";
|
|
2485
|
-
console.log("make reader");
|
|
2486
2495
|
this.lineSeparator = state$1.facet(state.EditorState.lineSeparator);
|
|
2487
2496
|
}
|
|
2488
2497
|
append(text) {
|
|
@@ -2617,10 +2626,7 @@ class DocView extends ContentView {
|
|
|
2617
2626
|
this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0);
|
|
2618
2627
|
}
|
|
2619
2628
|
get length() { return this.view.state.doc.length; }
|
|
2620
|
-
// Update the document view to a given state.
|
|
2621
|
-
// used as a hint to compute a new viewport that includes that
|
|
2622
|
-
// position, if we know the editor is going to scroll that position
|
|
2623
|
-
// into view.
|
|
2629
|
+
// Update the document view to a given state.
|
|
2624
2630
|
update(update) {
|
|
2625
2631
|
let changedRanges = update.changedRanges;
|
|
2626
2632
|
if (this.minWidth > 0 && changedRanges.length) {
|
|
@@ -2647,7 +2653,7 @@ class DocView extends ContentView {
|
|
|
2647
2653
|
let prevDeco = this.decorations, deco = this.updateDeco();
|
|
2648
2654
|
let decoDiff = findChangedDeco(prevDeco, deco, update.changes);
|
|
2649
2655
|
changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff);
|
|
2650
|
-
if (this.dirty == 0 /*
|
|
2656
|
+
if (this.dirty == 0 /* Not */ && changedRanges.length == 0) {
|
|
2651
2657
|
return false;
|
|
2652
2658
|
}
|
|
2653
2659
|
else {
|
|
@@ -2676,7 +2682,7 @@ class DocView extends ContentView {
|
|
|
2676
2682
|
// to detect that situation.
|
|
2677
2683
|
let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : undefined;
|
|
2678
2684
|
this.sync(this.view, track);
|
|
2679
|
-
this.dirty = 0 /*
|
|
2685
|
+
this.dirty = 0 /* Not */;
|
|
2680
2686
|
if (track && (track.written || observer.selectionRange.focusNode != track.node))
|
|
2681
2687
|
this.forceSelection = true;
|
|
2682
2688
|
this.dom.style.height = "";
|
|
@@ -2745,10 +2751,10 @@ class DocView extends ContentView {
|
|
|
2745
2751
|
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=1612076
|
|
2746
2752
|
if (browser.gecko) {
|
|
2747
2753
|
let nextTo = nextToUneditable(anchor.node, anchor.offset);
|
|
2748
|
-
if (nextTo && nextTo != (1 /*
|
|
2749
|
-
let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /*
|
|
2754
|
+
if (nextTo && nextTo != (1 /* Before */ | 2 /* After */)) {
|
|
2755
|
+
let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /* Before */ ? 1 : -1);
|
|
2750
2756
|
if (text)
|
|
2751
|
-
anchor = new DOMPos(text, nextTo == 1 /*
|
|
2757
|
+
anchor = new DOMPos(text, nextTo == 1 /* Before */ ? 0 : text.nodeValue.length);
|
|
2752
2758
|
}
|
|
2753
2759
|
}
|
|
2754
2760
|
rawSel.collapse(anchor.node, anchor.offset);
|
|
@@ -3029,8 +3035,12 @@ function computeCompositionDeco(view, changes) {
|
|
|
3029
3035
|
return Decoration.none;
|
|
3030
3036
|
let { from, to, node, text: textNode } = surrounding;
|
|
3031
3037
|
let newFrom = changes.mapPos(from, 1), newTo = Math.max(newFrom, changes.mapPos(to, -1));
|
|
3032
|
-
let { state } = view,
|
|
3033
|
-
|
|
3038
|
+
let { state } = view, reader = new DOMReader([], state);
|
|
3039
|
+
if (node.nodeType == 3)
|
|
3040
|
+
reader.readTextNode(node);
|
|
3041
|
+
else
|
|
3042
|
+
reader.readRange(node.firstChild, null);
|
|
3043
|
+
let { text } = reader;
|
|
3034
3044
|
if (text.indexOf(LineBreakPlaceholder) > -1)
|
|
3035
3045
|
return Decoration.none; // Don't try to preserve multi-line compositions
|
|
3036
3046
|
if (newTo - newFrom < text.length) {
|
|
@@ -3094,8 +3104,8 @@ function nearbyTextNode(startNode, startOffset, side) {
|
|
|
3094
3104
|
function nextToUneditable(node, offset) {
|
|
3095
3105
|
if (node.nodeType != 1)
|
|
3096
3106
|
return 0;
|
|
3097
|
-
return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /*
|
|
3098
|
-
(offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /*
|
|
3107
|
+
return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /* Before */ : 0) |
|
|
3108
|
+
(offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /* After */ : 0);
|
|
3099
3109
|
}
|
|
3100
3110
|
class DecorationComparator$1 {
|
|
3101
3111
|
constructor() {
|
|
@@ -3377,9 +3387,18 @@ function isSuspiciousChromeCaretResult(node, offset, x) {
|
|
|
3377
3387
|
: textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
|
|
3378
3388
|
return x - rect.left > 5;
|
|
3379
3389
|
}
|
|
3390
|
+
function blockAt(view, pos) {
|
|
3391
|
+
let line = view.lineBlockAt(pos);
|
|
3392
|
+
if (Array.isArray(line.type))
|
|
3393
|
+
for (let l of line.type) {
|
|
3394
|
+
if (l.to > pos || l.to == pos && (l.to == line.to || l.type == exports.BlockType.Text))
|
|
3395
|
+
return l;
|
|
3396
|
+
}
|
|
3397
|
+
return line;
|
|
3398
|
+
}
|
|
3380
3399
|
function moveToLineBoundary(view, start, forward, includeWrap) {
|
|
3381
|
-
let line = view
|
|
3382
|
-
let coords = !includeWrap || !view.lineWrapping ? null
|
|
3400
|
+
let line = blockAt(view, start.head);
|
|
3401
|
+
let coords = !includeWrap || line.type != exports.BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null
|
|
3383
3402
|
: view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
|
|
3384
3403
|
if (coords) {
|
|
3385
3404
|
let editorRect = view.dom.getBoundingClientRect();
|
|
@@ -3389,9 +3408,7 @@ function moveToLineBoundary(view, start, forward, includeWrap) {
|
|
|
3389
3408
|
if (pos != null)
|
|
3390
3409
|
return state.EditorSelection.cursor(pos, forward ? -1 : 1);
|
|
3391
3410
|
}
|
|
3392
|
-
|
|
3393
|
-
let end = lineView ? (forward ? lineView.posAtEnd : lineView.posAtStart) : (forward ? line.to : line.from);
|
|
3394
|
-
return state.EditorSelection.cursor(end, forward ? -1 : 1);
|
|
3411
|
+
return state.EditorSelection.cursor(forward ? line.to : line.from, forward ? -1 : 1);
|
|
3395
3412
|
}
|
|
3396
3413
|
function moveByChar(view, start, forward, by) {
|
|
3397
3414
|
let line = view.state.doc.lineAt(start.head), spans = view.bidiSpans(line);
|
|
@@ -4380,34 +4397,25 @@ class BlockInfo {
|
|
|
4380
4397
|
*/
|
|
4381
4398
|
height,
|
|
4382
4399
|
/**
|
|
4383
|
-
@internal
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
@internal
|
|
4400
|
+
@internal Weird packed field that holds an array of children
|
|
4401
|
+
for composite blocks, a decoration for block widgets, and a
|
|
4402
|
+
number indicating the amount of widget-create line breaks for
|
|
4403
|
+
text blocks.
|
|
4388
4404
|
*/
|
|
4389
|
-
|
|
4405
|
+
_content) {
|
|
4390
4406
|
this.from = from;
|
|
4391
4407
|
this.length = length;
|
|
4392
4408
|
this.top = top;
|
|
4393
4409
|
this.height = height;
|
|
4394
|
-
this.
|
|
4395
|
-
this.deco = deco;
|
|
4410
|
+
this._content = _content;
|
|
4396
4411
|
}
|
|
4397
4412
|
/**
|
|
4398
4413
|
The type of element this is. When querying lines, this may be
|
|
4399
4414
|
an array of all the blocks that make up the line.
|
|
4400
4415
|
*/
|
|
4401
4416
|
get type() {
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
}
|
|
4405
|
-
/**
|
|
4406
|
-
If this is a widget block, this will return the widget
|
|
4407
|
-
associated with it.
|
|
4408
|
-
*/
|
|
4409
|
-
get widget() {
|
|
4410
|
-
return this.deco && this.deco.widget;
|
|
4417
|
+
return typeof this._content == "number" ? exports.BlockType.Text :
|
|
4418
|
+
Array.isArray(this._content) ? this._content : this._content.type;
|
|
4411
4419
|
}
|
|
4412
4420
|
/**
|
|
4413
4421
|
The end of the element as a document position.
|
|
@@ -4418,11 +4426,26 @@ class BlockInfo {
|
|
|
4418
4426
|
*/
|
|
4419
4427
|
get bottom() { return this.top + this.height; }
|
|
4420
4428
|
/**
|
|
4429
|
+
If this is a widget block, this will return the widget
|
|
4430
|
+
associated with it.
|
|
4431
|
+
*/
|
|
4432
|
+
get widget() {
|
|
4433
|
+
return this._content instanceof PointDecoration ? this._content.widget : null;
|
|
4434
|
+
}
|
|
4435
|
+
/**
|
|
4436
|
+
If this is a textblock, this holds the number of line breaks
|
|
4437
|
+
that appear in widgets inside the block.
|
|
4438
|
+
*/
|
|
4439
|
+
get widgetLineBreaks() {
|
|
4440
|
+
return typeof this._content == "number" ? this._content : 0;
|
|
4441
|
+
}
|
|
4442
|
+
/**
|
|
4421
4443
|
@internal
|
|
4422
4444
|
*/
|
|
4423
4445
|
join(other) {
|
|
4424
|
-
let
|
|
4425
|
-
|
|
4446
|
+
let content = (Array.isArray(this._content) ? this._content : [this])
|
|
4447
|
+
.concat(Array.isArray(other._content) ? other._content : [other]);
|
|
4448
|
+
return new BlockInfo(this.from, this.length + other.length, this.top, this.height + other.height, content);
|
|
4426
4449
|
}
|
|
4427
4450
|
}
|
|
4428
4451
|
var QueryType;
|
|
@@ -4435,13 +4458,13 @@ const Epsilon = 1e-3;
|
|
|
4435
4458
|
class HeightMap {
|
|
4436
4459
|
constructor(length, // The number of characters covered
|
|
4437
4460
|
height, // Height of this part of the document
|
|
4438
|
-
flags = 2 /*
|
|
4461
|
+
flags = 2 /* Outdated */) {
|
|
4439
4462
|
this.length = length;
|
|
4440
4463
|
this.height = height;
|
|
4441
4464
|
this.flags = flags;
|
|
4442
4465
|
}
|
|
4443
|
-
get outdated() { return (this.flags & 2 /*
|
|
4444
|
-
set outdated(value) { this.flags = (value ? 2 /*
|
|
4466
|
+
get outdated() { return (this.flags & 2 /* Outdated */) > 0; }
|
|
4467
|
+
set outdated(value) { this.flags = (value ? 2 /* Outdated */ : 0) | (this.flags & ~2 /* Outdated */); }
|
|
4445
4468
|
setHeight(oracle, height) {
|
|
4446
4469
|
if (this.height != height) {
|
|
4447
4470
|
if (Math.abs(this.height - height) > Epsilon)
|
|
@@ -4543,7 +4566,7 @@ class HeightMapBlock extends HeightMap {
|
|
|
4543
4566
|
this.deco = deco;
|
|
4544
4567
|
}
|
|
4545
4568
|
blockAt(_height, _oracle, top, offset) {
|
|
4546
|
-
return new BlockInfo(offset, this.length, top, this.height,
|
|
4569
|
+
return new BlockInfo(offset, this.length, top, this.height, this.deco || 0);
|
|
4547
4570
|
}
|
|
4548
4571
|
lineAt(_value, _type, oracle, top, offset) {
|
|
4549
4572
|
return this.blockAt(0, oracle, top, offset);
|
|
@@ -4565,10 +4588,14 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4565
4588
|
super(length, height, null);
|
|
4566
4589
|
this.collapsed = 0; // Amount of collapsed content in the line
|
|
4567
4590
|
this.widgetHeight = 0; // Maximum inline widget height
|
|
4591
|
+
this.breaks = 0; // Number of widget-introduced line breaks on the line
|
|
4592
|
+
}
|
|
4593
|
+
blockAt(_height, _oracle, top, offset) {
|
|
4594
|
+
return new BlockInfo(offset, this.length, top, this.height, this.breaks);
|
|
4568
4595
|
}
|
|
4569
4596
|
replace(_from, _to, nodes) {
|
|
4570
4597
|
let node = nodes[0];
|
|
4571
|
-
if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /*
|
|
4598
|
+
if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /* SingleLine */)) &&
|
|
4572
4599
|
Math.abs(this.length - node.length) < 10) {
|
|
4573
4600
|
if (node instanceof HeightMapGap)
|
|
4574
4601
|
node = new HeightMapText(node.length, this.height);
|
|
@@ -4586,7 +4613,8 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4586
4613
|
if (measured && measured.from <= offset && measured.more)
|
|
4587
4614
|
this.setHeight(oracle, measured.heights[measured.index++]);
|
|
4588
4615
|
else if (force || this.outdated)
|
|
4589
|
-
this.setHeight(oracle, Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed))
|
|
4616
|
+
this.setHeight(oracle, Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) +
|
|
4617
|
+
this.breaks * oracle.lineHeight);
|
|
4590
4618
|
this.outdated = false;
|
|
4591
4619
|
return this;
|
|
4592
4620
|
}
|
|
@@ -4617,12 +4645,12 @@ class HeightMapGap extends HeightMap {
|
|
|
4617
4645
|
let guess = offset + Math.round(Math.max(0, Math.min(1, (height - top) / this.height)) * this.length);
|
|
4618
4646
|
let line = oracle.doc.lineAt(guess), lineHeight = perLine + line.length * perChar;
|
|
4619
4647
|
let lineTop = Math.max(top, height - lineHeight / 2);
|
|
4620
|
-
return new BlockInfo(line.from, line.length, lineTop, lineHeight,
|
|
4648
|
+
return new BlockInfo(line.from, line.length, lineTop, lineHeight, 0);
|
|
4621
4649
|
}
|
|
4622
4650
|
else {
|
|
4623
4651
|
let line = Math.max(0, Math.min(lastLine - firstLine, Math.floor((height - top) / perLine)));
|
|
4624
4652
|
let { from, length } = oracle.doc.line(firstLine + line);
|
|
4625
|
-
return new BlockInfo(from, length, top + perLine * line, perLine,
|
|
4653
|
+
return new BlockInfo(from, length, top + perLine * line, perLine, 0);
|
|
4626
4654
|
}
|
|
4627
4655
|
}
|
|
4628
4656
|
lineAt(value, type, oracle, top, offset) {
|
|
@@ -4630,13 +4658,13 @@ class HeightMapGap extends HeightMap {
|
|
|
4630
4658
|
return this.blockAt(value, oracle, top, offset);
|
|
4631
4659
|
if (type == QueryType.ByPosNoHeight) {
|
|
4632
4660
|
let { from, to } = oracle.doc.lineAt(value);
|
|
4633
|
-
return new BlockInfo(from, to - from, 0, 0,
|
|
4661
|
+
return new BlockInfo(from, to - from, 0, 0, 0);
|
|
4634
4662
|
}
|
|
4635
4663
|
let { firstLine, perLine, perChar } = this.heightMetrics(oracle, offset);
|
|
4636
4664
|
let line = oracle.doc.lineAt(value), lineHeight = perLine + line.length * perChar;
|
|
4637
4665
|
let linesAbove = line.number - firstLine;
|
|
4638
4666
|
let lineTop = top + perLine * linesAbove + perChar * (line.from - offset - linesAbove);
|
|
4639
|
-
return new BlockInfo(line.from, line.length, Math.max(top, Math.min(lineTop, top + this.height - lineHeight)), lineHeight,
|
|
4667
|
+
return new BlockInfo(line.from, line.length, Math.max(top, Math.min(lineTop, top + this.height - lineHeight)), lineHeight, 0);
|
|
4640
4668
|
}
|
|
4641
4669
|
forEachLine(from, to, oracle, top, offset, f) {
|
|
4642
4670
|
from = Math.max(from, offset);
|
|
@@ -4649,7 +4677,7 @@ class HeightMapGap extends HeightMap {
|
|
|
4649
4677
|
lineTop += perLine * linesAbove + perChar * (from - offset - linesAbove);
|
|
4650
4678
|
}
|
|
4651
4679
|
let lineHeight = perLine + perChar * line.length;
|
|
4652
|
-
f(new BlockInfo(line.from, line.length, lineTop, lineHeight,
|
|
4680
|
+
f(new BlockInfo(line.from, line.length, lineTop, lineHeight, 0));
|
|
4653
4681
|
lineTop += lineHeight;
|
|
4654
4682
|
pos = line.to + 1;
|
|
4655
4683
|
}
|
|
@@ -4720,12 +4748,12 @@ class HeightMapGap extends HeightMap {
|
|
|
4720
4748
|
}
|
|
4721
4749
|
class HeightMapBranch extends HeightMap {
|
|
4722
4750
|
constructor(left, brk, right) {
|
|
4723
|
-
super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /*
|
|
4751
|
+
super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /* Outdated */ : 0));
|
|
4724
4752
|
this.left = left;
|
|
4725
4753
|
this.right = right;
|
|
4726
4754
|
this.size = left.size + right.size;
|
|
4727
4755
|
}
|
|
4728
|
-
get break() { return this.flags & 1 /*
|
|
4756
|
+
get break() { return this.flags & 1 /* Break */; }
|
|
4729
4757
|
blockAt(height, oracle, top, offset) {
|
|
4730
4758
|
let mid = top + this.left.height;
|
|
4731
4759
|
return height < mid ? this.left.blockAt(height, oracle, top, offset)
|
|
@@ -4875,14 +4903,15 @@ class NodeBuilder {
|
|
|
4875
4903
|
point(from, to, deco) {
|
|
4876
4904
|
if (from < to || deco.heightRelevant) {
|
|
4877
4905
|
let height = deco.widget ? deco.widget.estimatedHeight : 0;
|
|
4906
|
+
let breaks = deco.widget ? deco.widget.lineBreaks : 0;
|
|
4878
4907
|
if (height < 0)
|
|
4879
4908
|
height = this.oracle.lineHeight;
|
|
4880
4909
|
let len = to - from;
|
|
4881
4910
|
if (deco.block) {
|
|
4882
4911
|
this.addBlock(new HeightMapBlock(len, height, deco));
|
|
4883
4912
|
}
|
|
4884
|
-
else if (len || height >= relevantWidgetHeight) {
|
|
4885
|
-
this.addLineDeco(height, len);
|
|
4913
|
+
else if (len || breaks || height >= relevantWidgetHeight) {
|
|
4914
|
+
this.addLineDeco(height, breaks, len);
|
|
4886
4915
|
}
|
|
4887
4916
|
}
|
|
4888
4917
|
else if (to > from) {
|
|
@@ -4909,7 +4938,7 @@ class NodeBuilder {
|
|
|
4909
4938
|
blankContent(from, to) {
|
|
4910
4939
|
let gap = new HeightMapGap(to - from);
|
|
4911
4940
|
if (this.oracle.doc.lineAt(from).to == to)
|
|
4912
|
-
gap.flags |= 4 /*
|
|
4941
|
+
gap.flags |= 4 /* SingleLine */;
|
|
4913
4942
|
return gap;
|
|
4914
4943
|
}
|
|
4915
4944
|
ensureLine() {
|
|
@@ -4932,11 +4961,12 @@ class NodeBuilder {
|
|
|
4932
4961
|
if (type != exports.BlockType.WidgetBefore)
|
|
4933
4962
|
this.covering = block;
|
|
4934
4963
|
}
|
|
4935
|
-
addLineDeco(height, length) {
|
|
4964
|
+
addLineDeco(height, breaks, length) {
|
|
4936
4965
|
let line = this.ensureLine();
|
|
4937
4966
|
line.length += length;
|
|
4938
4967
|
line.collapsed += length;
|
|
4939
4968
|
line.widgetHeight = Math.max(line.widgetHeight, height);
|
|
4969
|
+
line.breaks += breaks;
|
|
4940
4970
|
this.writtenTo = this.pos = this.pos + length;
|
|
4941
4971
|
}
|
|
4942
4972
|
finish(from) {
|
|
@@ -5070,6 +5100,14 @@ class ViewState {
|
|
|
5070
5100
|
this.contentDOMHeight = 0;
|
|
5071
5101
|
this.editorHeight = 0;
|
|
5072
5102
|
this.editorWidth = 0;
|
|
5103
|
+
this.scrollTop = 0;
|
|
5104
|
+
this.scrolledToBottom = true;
|
|
5105
|
+
// The vertical position (document-relative) to which to anchor the
|
|
5106
|
+
// scroll position. -1 means anchor to the end of the document.
|
|
5107
|
+
this.scrollAnchorPos = 0;
|
|
5108
|
+
// The height at the anchor position. Set by the DOM update phase.
|
|
5109
|
+
// -1 means no height available.
|
|
5110
|
+
this.scrollAnchorHeight = -1;
|
|
5073
5111
|
// See VP.MaxDOMHeight
|
|
5074
5112
|
this.scaler = IdScaler;
|
|
5075
5113
|
this.scrollTarget = null;
|
|
@@ -5110,7 +5148,7 @@ class ViewState {
|
|
|
5110
5148
|
}
|
|
5111
5149
|
}
|
|
5112
5150
|
this.viewports = viewports.sort((a, b) => a.from - b.from);
|
|
5113
|
-
this.scaler = this.heightMap.height <= 7000000 /*
|
|
5151
|
+
this.scaler = this.heightMap.height <= 7000000 /* MaxDOMHeight */ ? IdScaler :
|
|
5114
5152
|
new BigScaler(this.heightOracle, this.heightMap, this.viewports);
|
|
5115
5153
|
}
|
|
5116
5154
|
updateViewportLines() {
|
|
@@ -5126,20 +5164,29 @@ class ViewState {
|
|
|
5126
5164
|
let contentChanges = update.changedRanges;
|
|
5127
5165
|
let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : state.ChangeSet.empty(this.state.doc.length)));
|
|
5128
5166
|
let prevHeight = this.heightMap.height;
|
|
5167
|
+
let scrollAnchor = this.scrolledToBottom ? null : this.lineBlockAtHeight(this.scrollTop);
|
|
5129
5168
|
this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
|
|
5130
5169
|
if (this.heightMap.height != prevHeight)
|
|
5131
|
-
update.flags |= 2 /*
|
|
5170
|
+
update.flags |= 2 /* Height */;
|
|
5171
|
+
if (scrollAnchor) {
|
|
5172
|
+
this.scrollAnchorPos = update.changes.mapPos(scrollAnchor.from, -1);
|
|
5173
|
+
this.scrollAnchorHeight = scrollAnchor.top;
|
|
5174
|
+
}
|
|
5175
|
+
else {
|
|
5176
|
+
this.scrollAnchorPos = -1;
|
|
5177
|
+
this.scrollAnchorHeight = this.heightMap.height;
|
|
5178
|
+
}
|
|
5132
5179
|
let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
|
|
5133
5180
|
if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) ||
|
|
5134
5181
|
!this.viewportIsAppropriate(viewport))
|
|
5135
5182
|
viewport = this.getViewport(0, scrollTarget);
|
|
5136
|
-
let updateLines = !update.changes.empty || (update.flags & 2 /*
|
|
5183
|
+
let updateLines = !update.changes.empty || (update.flags & 2 /* Height */) ||
|
|
5137
5184
|
viewport.from != this.viewport.from || viewport.to != this.viewport.to;
|
|
5138
5185
|
this.viewport = viewport;
|
|
5139
5186
|
this.updateForViewport();
|
|
5140
5187
|
if (updateLines)
|
|
5141
5188
|
this.updateViewportLines();
|
|
5142
|
-
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /*
|
|
5189
|
+
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /* Margin */ << 1))
|
|
5143
5190
|
this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
|
|
5144
5191
|
update.flags |= this.computeVisibleRanges();
|
|
5145
5192
|
if (scrollTarget)
|
|
@@ -5165,14 +5212,19 @@ class ViewState {
|
|
|
5165
5212
|
if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
|
|
5166
5213
|
this.paddingTop = paddingTop;
|
|
5167
5214
|
this.paddingBottom = paddingBottom;
|
|
5168
|
-
result |= 8 /*
|
|
5215
|
+
result |= 8 /* Geometry */ | 2 /* Height */;
|
|
5169
5216
|
}
|
|
5170
5217
|
if (this.editorWidth != view.scrollDOM.clientWidth) {
|
|
5171
5218
|
if (oracle.lineWrapping)
|
|
5172
5219
|
measureContent = true;
|
|
5173
5220
|
this.editorWidth = view.scrollDOM.clientWidth;
|
|
5174
|
-
result |= 8 /*
|
|
5221
|
+
result |= 8 /* Geometry */;
|
|
5222
|
+
}
|
|
5223
|
+
if (this.scrollTop != view.scrollDOM.scrollTop) {
|
|
5224
|
+
this.scrollAnchorHeight = -1;
|
|
5225
|
+
this.scrollTop = view.scrollDOM.scrollTop;
|
|
5175
5226
|
}
|
|
5227
|
+
this.scrolledToBottom = this.scrollTop > view.scrollDOM.scrollHeight - view.scrollDOM.clientHeight - 4;
|
|
5176
5228
|
// Pixel viewport
|
|
5177
5229
|
let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
|
|
5178
5230
|
let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
|
|
@@ -5189,7 +5241,7 @@ class ViewState {
|
|
|
5189
5241
|
if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
|
|
5190
5242
|
this.contentDOMWidth = domRect.width;
|
|
5191
5243
|
this.editorHeight = view.scrollDOM.clientHeight;
|
|
5192
|
-
result |= 8 /*
|
|
5244
|
+
result |= 8 /* Geometry */;
|
|
5193
5245
|
}
|
|
5194
5246
|
if (measureContent) {
|
|
5195
5247
|
let lineHeights = view.docView.measureVisibleLineHeights(this.viewport);
|
|
@@ -5200,7 +5252,7 @@ class ViewState {
|
|
|
5200
5252
|
refresh = lineHeight > 0 && oracle.refresh(whiteSpace, lineHeight, charWidth, textHeight, contentWidth / charWidth, lineHeights);
|
|
5201
5253
|
if (refresh) {
|
|
5202
5254
|
view.docView.minWidth = 0;
|
|
5203
|
-
result |= 8 /*
|
|
5255
|
+
result |= 8 /* Geometry */;
|
|
5204
5256
|
}
|
|
5205
5257
|
}
|
|
5206
5258
|
if (dTop > 0 && dBottom > 0)
|
|
@@ -5213,7 +5265,7 @@ class ViewState {
|
|
|
5213
5265
|
this.heightMap = (refresh ? HeightMap.empty().applyChanges(this.stateDeco, state.Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)]) : this.heightMap).updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
5214
5266
|
}
|
|
5215
5267
|
if (oracle.heightChanged)
|
|
5216
|
-
result |= 2 /*
|
|
5268
|
+
result |= 2 /* Height */;
|
|
5217
5269
|
}
|
|
5218
5270
|
let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) ||
|
|
5219
5271
|
this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from ||
|
|
@@ -5221,9 +5273,9 @@ class ViewState {
|
|
|
5221
5273
|
if (viewportChange)
|
|
5222
5274
|
this.viewport = this.getViewport(bias, this.scrollTarget);
|
|
5223
5275
|
this.updateForViewport();
|
|
5224
|
-
if ((result & 2 /*
|
|
5276
|
+
if ((result & 2 /* Height */) || viewportChange)
|
|
5225
5277
|
this.updateViewportLines();
|
|
5226
|
-
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /*
|
|
5278
|
+
if (this.lineGaps.length || this.viewport.to - this.viewport.from > (2000 /* Margin */ << 1))
|
|
5227
5279
|
this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps, view));
|
|
5228
5280
|
result |= this.computeVisibleRanges();
|
|
5229
5281
|
if (this.mustEnforceCursorAssoc) {
|
|
@@ -5242,10 +5294,10 @@ class ViewState {
|
|
|
5242
5294
|
// This will divide VP.Margin between the top and the
|
|
5243
5295
|
// bottom, depending on the bias (the change in viewport position
|
|
5244
5296
|
// since the last update). It'll hold a number between 0 and 1
|
|
5245
|
-
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /*
|
|
5297
|
+
let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /* Margin */ / 2));
|
|
5246
5298
|
let map = this.heightMap, oracle = this.heightOracle;
|
|
5247
5299
|
let { visibleTop, visibleBottom } = this;
|
|
5248
|
-
let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1000 /*
|
|
5300
|
+
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);
|
|
5249
5301
|
// If scrollTarget is given, make sure the viewport includes that position
|
|
5250
5302
|
if (scrollTarget) {
|
|
5251
5303
|
let { head } = scrollTarget.range;
|
|
@@ -5258,7 +5310,7 @@ class ViewState {
|
|
|
5258
5310
|
topPos = block.top;
|
|
5259
5311
|
else
|
|
5260
5312
|
topPos = block.bottom - viewHeight;
|
|
5261
|
-
viewport = new Viewport(map.lineAt(topPos - 1000 /*
|
|
5313
|
+
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);
|
|
5262
5314
|
}
|
|
5263
5315
|
}
|
|
5264
5316
|
return viewport;
|
|
@@ -5275,10 +5327,10 @@ class ViewState {
|
|
|
5275
5327
|
let { top } = this.heightMap.lineAt(from, QueryType.ByPos, this.heightOracle, 0, 0);
|
|
5276
5328
|
let { bottom } = this.heightMap.lineAt(to, QueryType.ByPos, this.heightOracle, 0, 0);
|
|
5277
5329
|
let { visibleTop, visibleBottom } = this;
|
|
5278
|
-
return (from == 0 || top <= visibleTop - Math.max(10 /*
|
|
5330
|
+
return (from == 0 || top <= visibleTop - Math.max(10 /* MinCoverMargin */, Math.min(-bias, 250 /* MaxCoverMargin */))) &&
|
|
5279
5331
|
(to == this.state.doc.length ||
|
|
5280
|
-
bottom >= visibleBottom + Math.max(10 /*
|
|
5281
|
-
(top > visibleTop - 2 * 1000 /*
|
|
5332
|
+
bottom >= visibleBottom + Math.max(10 /* MinCoverMargin */, Math.min(bias, 250 /* MaxCoverMargin */))) &&
|
|
5333
|
+
(top > visibleTop - 2 * 1000 /* Margin */ && bottom < visibleBottom + 2 * 1000 /* Margin */);
|
|
5282
5334
|
}
|
|
5283
5335
|
mapLineGaps(gaps, changes) {
|
|
5284
5336
|
if (!gaps.length || changes.empty)
|
|
@@ -5298,7 +5350,7 @@ class ViewState {
|
|
|
5298
5350
|
// the artifacts this might produce from the user.
|
|
5299
5351
|
ensureLineGaps(current, mayMeasure) {
|
|
5300
5352
|
let wrapping = this.heightOracle.lineWrapping;
|
|
5301
|
-
let margin = wrapping ? 10000 /*
|
|
5353
|
+
let margin = wrapping ? 10000 /* MarginWrap */ : 2000 /* Margin */, halfMargin = margin >> 1, doubleMargin = margin << 1;
|
|
5302
5354
|
// The non-wrapping logic won't work at all in predominantly right-to-left text.
|
|
5303
5355
|
if (this.defaultTextDirection != exports.Direction.LTR && !wrapping)
|
|
5304
5356
|
return [];
|
|
@@ -5311,8 +5363,8 @@ class ViewState {
|
|
|
5311
5363
|
avoid.push(sel.to);
|
|
5312
5364
|
for (let pos of avoid) {
|
|
5313
5365
|
if (pos > from && pos < to) {
|
|
5314
|
-
addGap(from, pos - 10 /*
|
|
5315
|
-
addGap(pos + 10 /*
|
|
5366
|
+
addGap(from, pos - 10 /* SelectionMargin */, line, structure);
|
|
5367
|
+
addGap(pos + 10 /* SelectionMargin */, to, line, structure);
|
|
5316
5368
|
return;
|
|
5317
5369
|
}
|
|
5318
5370
|
}
|
|
@@ -5406,7 +5458,7 @@ class ViewState {
|
|
|
5406
5458
|
let changed = ranges.length != this.visibleRanges.length ||
|
|
5407
5459
|
this.visibleRanges.some((r, i) => r.from != ranges[i].from || r.to != ranges[i].to);
|
|
5408
5460
|
this.visibleRanges = ranges;
|
|
5409
|
-
return changed ? 4 /*
|
|
5461
|
+
return changed ? 4 /* Viewport */ : 0;
|
|
5410
5462
|
}
|
|
5411
5463
|
lineBlockAt(pos) {
|
|
5412
5464
|
return (pos >= this.viewport.from && pos <= this.viewport.to && this.viewportLines.find(b => b.from <= pos && b.to >= pos)) ||
|
|
@@ -5498,7 +5550,7 @@ class BigScaler {
|
|
|
5498
5550
|
vpHeight += bottom - top;
|
|
5499
5551
|
return { from, to, top, bottom, domTop: 0, domBottom: 0 };
|
|
5500
5552
|
});
|
|
5501
|
-
this.scale = (7000000 /*
|
|
5553
|
+
this.scale = (7000000 /* MaxDOMHeight */ - vpHeight) / (heightMap.height - vpHeight);
|
|
5502
5554
|
for (let obj of this.viewports) {
|
|
5503
5555
|
obj.domTop = domBase + (obj.top - base) * this.scale;
|
|
5504
5556
|
domBase = obj.domBottom = obj.domTop + (obj.bottom - obj.top);
|
|
@@ -5532,7 +5584,7 @@ function scaleBlock(block, scaler) {
|
|
|
5532
5584
|
if (scaler.scale == 1)
|
|
5533
5585
|
return block;
|
|
5534
5586
|
let bTop = scaler.toDOM(block.top), bBottom = scaler.toDOM(block.bottom);
|
|
5535
|
-
return new BlockInfo(block.from, block.length, bTop, bBottom - bTop, block.
|
|
5587
|
+
return new BlockInfo(block.from, block.length, bTop, bBottom - bTop, Array.isArray(block._content) ? block._content.map(b => scaleBlock(b, scaler)) : block._content);
|
|
5536
5588
|
}
|
|
5537
5589
|
|
|
5538
5590
|
const theme = state.Facet.define({ combine: strs => strs.join(" ") });
|
|
@@ -6392,7 +6444,7 @@ class DOMObserver {
|
|
|
6392
6444
|
return null;
|
|
6393
6445
|
cView.markDirty(rec.type == "attributes");
|
|
6394
6446
|
if (rec.type == "attributes")
|
|
6395
|
-
cView.dirty |= 4 /*
|
|
6447
|
+
cView.dirty |= 4 /* Attrs */;
|
|
6396
6448
|
if (rec.type == "childList") {
|
|
6397
6449
|
let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1);
|
|
6398
6450
|
let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1);
|
|
@@ -6515,7 +6567,7 @@ class EditorView {
|
|
|
6515
6567
|
/**
|
|
6516
6568
|
@internal
|
|
6517
6569
|
*/
|
|
6518
|
-
this.updateState = 2 /*
|
|
6570
|
+
this.updateState = 2 /* Updating */;
|
|
6519
6571
|
/**
|
|
6520
6572
|
@internal
|
|
6521
6573
|
*/
|
|
@@ -6548,7 +6600,7 @@ class EditorView {
|
|
|
6548
6600
|
this.docView = new DocView(this);
|
|
6549
6601
|
this.mountStyles();
|
|
6550
6602
|
this.updateAttrs();
|
|
6551
|
-
this.updateState = 0 /*
|
|
6603
|
+
this.updateState = 0 /* Idle */;
|
|
6552
6604
|
this.requestMeasure();
|
|
6553
6605
|
if (config.parent)
|
|
6554
6606
|
config.parent.appendChild(this.dom);
|
|
@@ -6601,8 +6653,9 @@ class EditorView {
|
|
|
6601
6653
|
*/
|
|
6602
6654
|
get win() { return this.dom.ownerDocument.defaultView || window; }
|
|
6603
6655
|
dispatch(...input) {
|
|
6604
|
-
|
|
6605
|
-
: this.state.update(...input)
|
|
6656
|
+
let tr = input.length == 1 && input[0] instanceof state.Transaction ? input[0]
|
|
6657
|
+
: this.state.update(...input);
|
|
6658
|
+
this._dispatch(tr, this);
|
|
6606
6659
|
}
|
|
6607
6660
|
/**
|
|
6608
6661
|
Update the view for the given array of transactions. This will
|
|
@@ -6613,7 +6666,7 @@ class EditorView {
|
|
|
6613
6666
|
as a primitive.
|
|
6614
6667
|
*/
|
|
6615
6668
|
update(transactions) {
|
|
6616
|
-
if (this.updateState != 0 /*
|
|
6669
|
+
if (this.updateState != 0 /* Idle */)
|
|
6617
6670
|
throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
|
|
6618
6671
|
let redrawn = false, attrsChanged = false, update;
|
|
6619
6672
|
let state$1 = this.state;
|
|
@@ -6630,7 +6683,7 @@ class EditorView {
|
|
|
6630
6683
|
if (transactions.some(tr => tr.annotation(isFocusChange))) {
|
|
6631
6684
|
this.inputState.notifiedFocused = focus;
|
|
6632
6685
|
// If a focus-change transaction is being dispatched, set this update flag.
|
|
6633
|
-
focusFlag = 1 /*
|
|
6686
|
+
focusFlag = 1 /* Focus */;
|
|
6634
6687
|
}
|
|
6635
6688
|
else if (focus != this.inputState.notifiedFocused) {
|
|
6636
6689
|
this.inputState.notifiedFocused = focus;
|
|
@@ -6638,7 +6691,7 @@ class EditorView {
|
|
|
6638
6691
|
// add a flag to this update
|
|
6639
6692
|
dispatchFocus = focusChangeTransaction(state$1, focus);
|
|
6640
6693
|
if (!dispatchFocus)
|
|
6641
|
-
focusFlag = 1 /*
|
|
6694
|
+
focusFlag = 1 /* Focus */;
|
|
6642
6695
|
}
|
|
6643
6696
|
// If there was a pending DOM change, eagerly read it and try to
|
|
6644
6697
|
// apply it after the given transactions.
|
|
@@ -6661,7 +6714,7 @@ class EditorView {
|
|
|
6661
6714
|
update.flags |= focusFlag;
|
|
6662
6715
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6663
6716
|
try {
|
|
6664
|
-
this.updateState = 2 /*
|
|
6717
|
+
this.updateState = 2 /* Updating */;
|
|
6665
6718
|
for (let tr of transactions) {
|
|
6666
6719
|
if (scrollTarget)
|
|
6667
6720
|
scrollTarget = scrollTarget.map(tr.changes);
|
|
@@ -6687,7 +6740,7 @@ class EditorView {
|
|
|
6687
6740
|
this.docView.updateSelection(redrawn, transactions.some(tr => tr.isUserEvent("select.pointer")));
|
|
6688
6741
|
}
|
|
6689
6742
|
finally {
|
|
6690
|
-
this.updateState = 0 /*
|
|
6743
|
+
this.updateState = 0 /* Idle */;
|
|
6691
6744
|
}
|
|
6692
6745
|
if (update.startState.facet(theme) != update.state.facet(theme))
|
|
6693
6746
|
this.viewState.mustMeasureContent = true;
|
|
@@ -6714,13 +6767,13 @@ class EditorView {
|
|
|
6714
6767
|
[`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
|
|
6715
6768
|
*/
|
|
6716
6769
|
setState(newState) {
|
|
6717
|
-
if (this.updateState != 0 /*
|
|
6770
|
+
if (this.updateState != 0 /* Idle */)
|
|
6718
6771
|
throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");
|
|
6719
6772
|
if (this.destroyed) {
|
|
6720
6773
|
this.viewState.state = newState;
|
|
6721
6774
|
return;
|
|
6722
6775
|
}
|
|
6723
|
-
this.updateState = 2 /*
|
|
6776
|
+
this.updateState = 2 /* Updating */;
|
|
6724
6777
|
let hadFocus = this.hasFocus;
|
|
6725
6778
|
try {
|
|
6726
6779
|
for (let plugin of this.plugins)
|
|
@@ -6737,7 +6790,7 @@ class EditorView {
|
|
|
6737
6790
|
this.bidiCache = [];
|
|
6738
6791
|
}
|
|
6739
6792
|
finally {
|
|
6740
|
-
this.updateState = 0 /*
|
|
6793
|
+
this.updateState = 0 /* Idle */;
|
|
6741
6794
|
}
|
|
6742
6795
|
if (hadFocus)
|
|
6743
6796
|
this.focus();
|
|
@@ -6784,13 +6837,23 @@ class EditorView {
|
|
|
6784
6837
|
if (flush)
|
|
6785
6838
|
this.observer.forceFlush();
|
|
6786
6839
|
let updated = null;
|
|
6787
|
-
let
|
|
6788
|
-
|
|
6840
|
+
let sDOM = this.scrollDOM, { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
|
|
6841
|
+
this.viewState.scrollAnchorHeight = -1;
|
|
6842
|
+
if (scrollAnchorHeight < 0 || sDOM.scrollTop != this.viewState.scrollTop) {
|
|
6843
|
+
if (sDOM.scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
|
|
6844
|
+
scrollAnchorPos = -1;
|
|
6845
|
+
scrollAnchorHeight = this.viewState.heightMap.height;
|
|
6846
|
+
}
|
|
6847
|
+
else {
|
|
6848
|
+
let block = this.viewState.lineBlockAtHeight(sDOM.scrollTop);
|
|
6849
|
+
scrollAnchorPos = block.from;
|
|
6850
|
+
scrollAnchorHeight = block.top;
|
|
6851
|
+
}
|
|
6852
|
+
}
|
|
6789
6853
|
try {
|
|
6790
6854
|
for (let i = 0;; i++) {
|
|
6791
|
-
this.updateState = 1 /*
|
|
6855
|
+
this.updateState = 1 /* Measuring */;
|
|
6792
6856
|
let oldViewport = this.viewport;
|
|
6793
|
-
let refBlock = this.viewState.lineBlockAtHeight(refHeight);
|
|
6794
6857
|
let changed = this.viewState.measure(this);
|
|
6795
6858
|
if (!changed && !this.measureRequests.length && this.viewState.scrollTarget == null)
|
|
6796
6859
|
break;
|
|
@@ -6802,7 +6865,7 @@ class EditorView {
|
|
|
6802
6865
|
}
|
|
6803
6866
|
let measuring = [];
|
|
6804
6867
|
// Only run measure requests in this cycle when the viewport didn't change
|
|
6805
|
-
if (!(changed & 4 /*
|
|
6868
|
+
if (!(changed & 4 /* Viewport */))
|
|
6806
6869
|
[this.measureRequests, measuring] = [measuring, this.measureRequests];
|
|
6807
6870
|
let measured = measuring.map(m => {
|
|
6808
6871
|
try {
|
|
@@ -6819,7 +6882,7 @@ class EditorView {
|
|
|
6819
6882
|
updated = update;
|
|
6820
6883
|
else
|
|
6821
6884
|
updated.flags |= changed;
|
|
6822
|
-
this.updateState = 2 /*
|
|
6885
|
+
this.updateState = 2 /* Updating */;
|
|
6823
6886
|
if (!update.empty) {
|
|
6824
6887
|
this.updatePlugins(update);
|
|
6825
6888
|
this.inputState.update(update);
|
|
@@ -6843,10 +6906,12 @@ class EditorView {
|
|
|
6843
6906
|
this.viewState.scrollTarget = null;
|
|
6844
6907
|
scrolled = true;
|
|
6845
6908
|
}
|
|
6846
|
-
else {
|
|
6847
|
-
let
|
|
6909
|
+
else if (scrollAnchorHeight > -1) {
|
|
6910
|
+
let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height :
|
|
6911
|
+
this.viewState.lineBlockAt(scrollAnchorPos).top;
|
|
6912
|
+
let diff = newAnchorHeight - scrollAnchorHeight;
|
|
6848
6913
|
if (diff > 1 || diff < -1) {
|
|
6849
|
-
|
|
6914
|
+
sDOM.scrollTop += diff;
|
|
6850
6915
|
scrolled = true;
|
|
6851
6916
|
}
|
|
6852
6917
|
}
|
|
@@ -6856,10 +6921,11 @@ class EditorView {
|
|
|
6856
6921
|
if (this.viewport.from == oldViewport.from && this.viewport.to == oldViewport.to &&
|
|
6857
6922
|
!scrolled && this.measureRequests.length == 0)
|
|
6858
6923
|
break;
|
|
6924
|
+
scrollAnchorHeight = -1;
|
|
6859
6925
|
}
|
|
6860
6926
|
}
|
|
6861
6927
|
finally {
|
|
6862
|
-
this.updateState = 0 /*
|
|
6928
|
+
this.updateState = 0 /* Idle */;
|
|
6863
6929
|
this.measureScheduled = -1;
|
|
6864
6930
|
}
|
|
6865
6931
|
if (updated && !updated.empty)
|
|
@@ -6918,9 +6984,9 @@ class EditorView {
|
|
|
6918
6984
|
styleMod.StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1).reverse());
|
|
6919
6985
|
}
|
|
6920
6986
|
readMeasured() {
|
|
6921
|
-
if (this.updateState == 2 /*
|
|
6987
|
+
if (this.updateState == 2 /* Updating */)
|
|
6922
6988
|
throw new Error("Reading the editor layout isn't allowed during an update");
|
|
6923
|
-
if (this.updateState == 0 /*
|
|
6989
|
+
if (this.updateState == 0 /* Idle */ && this.measureScheduled > -1)
|
|
6924
6990
|
this.measure(false);
|
|
6925
6991
|
}
|
|
6926
6992
|
/**
|
|
@@ -7714,15 +7780,6 @@ function wrappedLine(view, pos, inside) {
|
|
|
7714
7780
|
to: Math.min(inside.to, view.moveToLineBoundary(range, true, true).from),
|
|
7715
7781
|
type: exports.BlockType.Text };
|
|
7716
7782
|
}
|
|
7717
|
-
function blockAt(view, pos) {
|
|
7718
|
-
let line = view.lineBlockAt(pos);
|
|
7719
|
-
if (Array.isArray(line.type))
|
|
7720
|
-
for (let l of line.type) {
|
|
7721
|
-
if (l.to > pos || l.to == pos && (l.to == line.to || l.type == exports.BlockType.Text))
|
|
7722
|
-
return l;
|
|
7723
|
-
}
|
|
7724
|
-
return line;
|
|
7725
|
-
}
|
|
7726
7783
|
function rectanglesForRange(view, className, range) {
|
|
7727
7784
|
if (range.to <= view.viewport.from || range.from >= view.viewport.to)
|
|
7728
7785
|
return [];
|
|
@@ -7736,12 +7793,10 @@ function rectanglesForRange(view, className, range) {
|
|
|
7736
7793
|
let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
|
|
7737
7794
|
let visualStart = startBlock.type == exports.BlockType.Text ? startBlock : null;
|
|
7738
7795
|
let visualEnd = endBlock.type == exports.BlockType.Text ? endBlock : null;
|
|
7739
|
-
if (view.lineWrapping)
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
visualEnd = wrappedLine(view, to, visualEnd);
|
|
7744
|
-
}
|
|
7796
|
+
if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
|
|
7797
|
+
visualStart = wrappedLine(view, from, visualStart);
|
|
7798
|
+
if (visualEnd && (view.lineWrapping || endBlock.widgetLineBreaks))
|
|
7799
|
+
visualEnd = wrappedLine(view, to, visualEnd);
|
|
7745
7800
|
if (visualStart && visualEnd && visualStart.from == visualEnd.from) {
|
|
7746
7801
|
return pieces(drawForLine(range.from, range.to, visualStart));
|
|
7747
7802
|
}
|
|
@@ -7749,14 +7804,15 @@ function rectanglesForRange(view, className, range) {
|
|
|
7749
7804
|
let top = visualStart ? drawForLine(range.from, null, visualStart) : drawForWidget(startBlock, false);
|
|
7750
7805
|
let bottom = visualEnd ? drawForLine(null, range.to, visualEnd) : drawForWidget(endBlock, true);
|
|
7751
7806
|
let between = [];
|
|
7752
|
-
if ((visualStart || startBlock).to < (visualEnd || endBlock).from - (visualStart && visualEnd ? 1 : 0)
|
|
7807
|
+
if ((visualStart || startBlock).to < (visualEnd || endBlock).from - (visualStart && visualEnd ? 1 : 0) ||
|
|
7808
|
+
startBlock.widgetLineBreaks > 1 && top.bottom + view.defaultLineHeight / 2 < bottom.top)
|
|
7753
7809
|
between.push(piece(leftSide, top.bottom, rightSide, bottom.top));
|
|
7754
7810
|
else if (top.bottom < bottom.top && view.elementAtHeight((top.bottom + bottom.top) / 2).type == exports.BlockType.Text)
|
|
7755
7811
|
top.bottom = bottom.top = (top.bottom + bottom.top) / 2;
|
|
7756
7812
|
return pieces(top).concat(between).concat(pieces(bottom));
|
|
7757
7813
|
}
|
|
7758
7814
|
function piece(left, top, right, bottom) {
|
|
7759
|
-
return new RectangleMarker(className, left - base.left, top - base.top - 0.01 /*
|
|
7815
|
+
return new RectangleMarker(className, left - base.left, top - base.top - 0.01 /* Epsilon */, right - left, bottom - top + 0.01 /* Epsilon */);
|
|
7760
7816
|
}
|
|
7761
7817
|
function pieces({ top, bottom, horizontal }) {
|
|
7762
7818
|
let pieces = [];
|
|
@@ -8771,12 +8827,12 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
|
|
|
8771
8827
|
continue;
|
|
8772
8828
|
}
|
|
8773
8829
|
let arrow = tooltip.arrow ? tView.dom.querySelector(".cm-tooltip-arrow") : null;
|
|
8774
|
-
let arrowHeight = arrow ? 7 /*
|
|
8830
|
+
let arrowHeight = arrow ? 7 /* Size */ : 0;
|
|
8775
8831
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
8776
8832
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == exports.Direction.LTR;
|
|
8777
8833
|
let left = size.width > space.right - space.left ? (ltr ? space.left : space.right - size.width)
|
|
8778
|
-
: ltr ? Math.min(pos.left - (arrow ? 14 /*
|
|
8779
|
-
: Math.max(space.left, pos.left - width + (arrow ? 14 /*
|
|
8834
|
+
: ltr ? Math.min(pos.left - (arrow ? 14 /* Offset */ : 0) + offset.x, space.right - width)
|
|
8835
|
+
: Math.max(space.left, pos.left - width + (arrow ? 14 /* Offset */ : 0) - offset.x);
|
|
8780
8836
|
let above = !!tooltip.above;
|
|
8781
8837
|
if (!tooltip.strictSide && (above
|
|
8782
8838
|
? pos.top - (size.bottom - size.top) - offset.y < space.top
|
|
@@ -8810,7 +8866,7 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
|
|
|
8810
8866
|
dom.style.left = left + "px";
|
|
8811
8867
|
}
|
|
8812
8868
|
if (arrow)
|
|
8813
|
-
arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /*
|
|
8869
|
+
arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Offset */ - 7 /* Size */)}px`;
|
|
8814
8870
|
if (tView.overlap !== true)
|
|
8815
8871
|
others.push({ left, top, right, bottom: top + height });
|
|
8816
8872
|
dom.classList.toggle("cm-tooltip-above", above);
|
|
@@ -8853,8 +8909,8 @@ const baseTheme = EditorView.baseTheme({
|
|
|
8853
8909
|
color: "white"
|
|
8854
8910
|
},
|
|
8855
8911
|
".cm-tooltip-arrow": {
|
|
8856
|
-
height: `${7 /*
|
|
8857
|
-
width: `${7 /*
|
|
8912
|
+
height: `${7 /* Size */}px`,
|
|
8913
|
+
width: `${7 /* Size */ * 2}px`,
|
|
8858
8914
|
position: "absolute",
|
|
8859
8915
|
zIndex: -1,
|
|
8860
8916
|
overflow: "hidden",
|
|
@@ -8863,26 +8919,26 @@ const baseTheme = EditorView.baseTheme({
|
|
|
8863
8919
|
position: "absolute",
|
|
8864
8920
|
width: 0,
|
|
8865
8921
|
height: 0,
|
|
8866
|
-
borderLeft: `${7 /*
|
|
8867
|
-
borderRight: `${7 /*
|
|
8922
|
+
borderLeft: `${7 /* Size */}px solid transparent`,
|
|
8923
|
+
borderRight: `${7 /* Size */}px solid transparent`,
|
|
8868
8924
|
},
|
|
8869
8925
|
".cm-tooltip-above &": {
|
|
8870
|
-
bottom: `-${7 /*
|
|
8926
|
+
bottom: `-${7 /* Size */}px`,
|
|
8871
8927
|
"&:before": {
|
|
8872
|
-
borderTop: `${7 /*
|
|
8928
|
+
borderTop: `${7 /* Size */}px solid #bbb`,
|
|
8873
8929
|
},
|
|
8874
8930
|
"&:after": {
|
|
8875
|
-
borderTop: `${7 /*
|
|
8931
|
+
borderTop: `${7 /* Size */}px solid #f5f5f5`,
|
|
8876
8932
|
bottom: "1px"
|
|
8877
8933
|
}
|
|
8878
8934
|
},
|
|
8879
8935
|
".cm-tooltip-below &": {
|
|
8880
|
-
top: `-${7 /*
|
|
8936
|
+
top: `-${7 /* Size */}px`,
|
|
8881
8937
|
"&:before": {
|
|
8882
|
-
borderBottom: `${7 /*
|
|
8938
|
+
borderBottom: `${7 /* Size */}px solid #bbb`,
|
|
8883
8939
|
},
|
|
8884
8940
|
"&:after": {
|
|
8885
|
-
borderBottom: `${7 /*
|
|
8941
|
+
borderBottom: `${7 /* Size */}px solid #f5f5f5`,
|
|
8886
8942
|
top: "1px"
|
|
8887
8943
|
}
|
|
8888
8944
|
},
|
|
@@ -9032,7 +9088,7 @@ class HoverPlugin {
|
|
|
9032
9088
|
if (tooltip && !isInTooltip(this.lastMove.target) || this.pending) {
|
|
9033
9089
|
let { pos } = tooltip || this.pending, end = (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.end) !== null && _a !== void 0 ? _a : pos;
|
|
9034
9090
|
if ((pos == end ? this.view.posAtCoords(this.lastMove) != pos
|
|
9035
|
-
: !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /*
|
|
9091
|
+
: !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /* MaxDist */))) {
|
|
9036
9092
|
this.view.dispatch({ effects: this.setHover.of(null) });
|
|
9037
9093
|
this.pending = null;
|
|
9038
9094
|
}
|
|
@@ -9114,7 +9170,7 @@ function hoverTooltip(source, options = {}) {
|
|
|
9114
9170
|
});
|
|
9115
9171
|
return [
|
|
9116
9172
|
hoverState,
|
|
9117
|
-
ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /*
|
|
9173
|
+
ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /* Time */)),
|
|
9118
9174
|
showHoverTooltipHost
|
|
9119
9175
|
];
|
|
9120
9176
|
}
|