@codemirror/view 6.2.2 → 6.2.3

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/dist/index.cjs CHANGED
@@ -308,7 +308,7 @@ class ContentView {
308
308
  constructor() {
309
309
  this.parent = null;
310
310
  this.dom = null;
311
- this.dirty = 2 /* Node */;
311
+ this.dirty = 2 /* Dirty.Node */;
312
312
  }
313
313
  get editorView() {
314
314
  if (!this.parent)
@@ -339,7 +339,7 @@ class ContentView {
339
339
  // given position.
340
340
  coordsAt(_pos, _side) { return null; }
341
341
  sync(track) {
342
- if (this.dirty & 2 /* Node */) {
342
+ if (this.dirty & 2 /* Dirty.Node */) {
343
343
  let parent = this.dom;
344
344
  let prev = null, next;
345
345
  for (let child of this.children) {
@@ -350,7 +350,7 @@ class ContentView {
350
350
  child.reuseDOM(next);
351
351
  }
352
352
  child.sync(track);
353
- child.dirty = 0 /* Not */;
353
+ child.dirty = 0 /* Dirty.Not */;
354
354
  }
355
355
  next = prev ? prev.nextSibling : parent.firstChild;
356
356
  if (track && !track.written && track.node == parent && next != child.dom)
@@ -370,11 +370,11 @@ class ContentView {
370
370
  while (next)
371
371
  next = rm$1(next);
372
372
  }
373
- else if (this.dirty & 1 /* Child */) {
373
+ else if (this.dirty & 1 /* Dirty.Child */) {
374
374
  for (let child of this.children)
375
375
  if (child.dirty) {
376
376
  child.sync(track);
377
- child.dirty = 0 /* Not */;
377
+ child.dirty = 0 /* Dirty.Not */;
378
378
  }
379
379
  }
380
380
  }
@@ -439,16 +439,16 @@ class ContentView {
439
439
  endDOM: toI < this.children.length && toI >= 0 ? this.children[toI].dom : null };
440
440
  }
441
441
  markDirty(andParent = false) {
442
- this.dirty |= 2 /* Node */;
442
+ this.dirty |= 2 /* Dirty.Node */;
443
443
  this.markParentsDirty(andParent);
444
444
  }
445
445
  markParentsDirty(childList) {
446
446
  for (let parent = this.parent; parent; parent = parent.parent) {
447
447
  if (childList)
448
- parent.dirty |= 2 /* Node */;
449
- if (parent.dirty & 1 /* Child */)
448
+ parent.dirty |= 2 /* Dirty.Node */;
449
+ if (parent.dirty & 1 /* Dirty.Child */)
450
450
  return;
451
- parent.dirty |= 1 /* Child */;
451
+ parent.dirty |= 1 /* Dirty.Child */;
452
452
  childList = false;
453
453
  }
454
454
  }
@@ -724,13 +724,13 @@ class MarkView extends ContentView {
724
724
  reuseDOM(node) {
725
725
  if (node.nodeName == this.mark.tagName.toUpperCase()) {
726
726
  this.setDOM(node);
727
- this.dirty |= 4 /* Attrs */ | 2 /* Node */;
727
+ this.dirty |= 4 /* Dirty.Attrs */ | 2 /* Dirty.Node */;
728
728
  }
729
729
  }
730
730
  sync(track) {
731
731
  if (!this.dom)
732
732
  this.setDOM(this.setAttrs(document.createElement(this.mark.tagName)));
733
- else if (this.dirty & 4 /* Attrs */)
733
+ else if (this.dirty & 4 /* Dirty.Attrs */)
734
734
  this.setAttrs(this.dom);
735
735
  super.sync(track);
736
736
  }
@@ -1240,7 +1240,7 @@ class Decoration extends state.RangeValue {
1240
1240
  */
1241
1241
  static widget(spec) {
1242
1242
  let side = spec.side || 0, block = !!spec.block;
1243
- side += block ? (side > 0 ? 300000000 /* BlockAfter */ : -400000000 /* BlockBefore */) : (side > 0 ? 100000000 /* InlineAfter */ : -100000000 /* InlineBefore */);
1243
+ side += block ? (side > 0 ? 300000000 /* Side.BlockAfter */ : -400000000 /* Side.BlockBefore */) : (side > 0 ? 100000000 /* Side.InlineAfter */ : -100000000 /* Side.InlineBefore */);
1244
1244
  return new PointDecoration(spec, side, side, block, spec.widget || null, false);
1245
1245
  }
1246
1246
  /**
@@ -1250,13 +1250,13 @@ class Decoration extends state.RangeValue {
1250
1250
  static replace(spec) {
1251
1251
  let block = !!spec.block, startSide, endSide;
1252
1252
  if (spec.isBlockGap) {
1253
- startSide = -500000000 /* GapStart */;
1254
- endSide = 400000000 /* GapEnd */;
1253
+ startSide = -500000000 /* Side.GapStart */;
1254
+ endSide = 400000000 /* Side.GapEnd */;
1255
1255
  }
1256
1256
  else {
1257
1257
  let { start, end } = getInclusive(spec, block);
1258
- startSide = (start ? (block ? -300000000 /* BlockIncStart */ : -1 /* InlineIncStart */) : 500000000 /* NonIncStart */) - 1;
1259
- endSide = (end ? (block ? 200000000 /* BlockIncEnd */ : 1 /* InlineIncEnd */) : -600000000 /* NonIncEnd */) + 1;
1258
+ startSide = (start ? (block ? -300000000 /* Side.BlockIncStart */ : -1 /* Side.InlineIncStart */) : 500000000 /* Side.NonIncStart */) - 1;
1259
+ endSide = (end ? (block ? 200000000 /* Side.BlockIncEnd */ : 1 /* Side.InlineIncEnd */) : -600000000 /* Side.NonIncEnd */) + 1;
1260
1260
  }
1261
1261
  return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);
1262
1262
  }
@@ -1287,7 +1287,7 @@ Decoration.none = state.RangeSet.empty;
1287
1287
  class MarkDecoration extends Decoration {
1288
1288
  constructor(spec) {
1289
1289
  let { start, end } = getInclusive(spec);
1290
- super(start ? -1 /* InlineIncStart */ : 500000000 /* NonIncStart */, end ? 1 /* InlineIncEnd */ : -600000000 /* NonIncEnd */, null, spec);
1290
+ super(start ? -1 /* Side.InlineIncStart */ : 500000000 /* Side.NonIncStart */, end ? 1 /* Side.InlineIncEnd */ : -600000000 /* Side.NonIncEnd */, null, spec);
1291
1291
  this.tagName = spec.tagName || "span";
1292
1292
  this.class = spec.class || "";
1293
1293
  this.attrs = spec.attributes || null;
@@ -1308,7 +1308,7 @@ class MarkDecoration extends Decoration {
1308
1308
  MarkDecoration.prototype.point = false;
1309
1309
  class LineDecoration extends Decoration {
1310
1310
  constructor(spec) {
1311
- super(-200000000 /* Line */, -200000000 /* Line */, null, spec);
1311
+ super(-200000000 /* Side.Line */, -200000000 /* Side.Line */, null, spec);
1312
1312
  }
1313
1313
  eq(other) {
1314
1314
  return other instanceof LineDecoration && attrsEq(this.spec.attributes, other.spec.attributes);
@@ -1445,7 +1445,7 @@ class LineView extends ContentView {
1445
1445
  reuseDOM(node) {
1446
1446
  if (node.nodeName == "DIV") {
1447
1447
  this.setDOM(node);
1448
- this.dirty |= 4 /* Attrs */ | 2 /* Node */;
1448
+ this.dirty |= 4 /* Dirty.Attrs */ | 2 /* Dirty.Node */;
1449
1449
  }
1450
1450
  }
1451
1451
  sync(track) {
@@ -1455,7 +1455,7 @@ class LineView extends ContentView {
1455
1455
  this.dom.className = "cm-line";
1456
1456
  this.prevAttrs = this.attrs ? null : undefined;
1457
1457
  }
1458
- else if (this.dirty & 4 /* Attrs */) {
1458
+ else if (this.dirty & 4 /* Dirty.Attrs */) {
1459
1459
  clearAttributes(this.dom);
1460
1460
  this.dom.className = "cm-line";
1461
1461
  this.prevAttrs = this.attrs ? null : undefined;
@@ -1585,7 +1585,7 @@ class ContentBuilder {
1585
1585
  this.content = [];
1586
1586
  this.curLine = null;
1587
1587
  this.breakAtStart = 0;
1588
- this.pendingBuffer = 0 /* No */;
1588
+ this.pendingBuffer = 0 /* Buf.No */;
1589
1589
  // Set to false directly after a widget that covers the position after it
1590
1590
  this.atCursorPos = true;
1591
1591
  this.openStart = -1;
@@ -1611,7 +1611,7 @@ class ContentBuilder {
1611
1611
  flushBuffer(active) {
1612
1612
  if (this.pendingBuffer) {
1613
1613
  this.curLine.append(wrapMarks(new WidgetBufferView(-1), active), active.length);
1614
- this.pendingBuffer = 0 /* No */;
1614
+ this.pendingBuffer = 0 /* Buf.No */;
1615
1615
  }
1616
1616
  }
1617
1617
  addBlockWidget(view) {
@@ -1623,7 +1623,7 @@ class ContentBuilder {
1623
1623
  if (!openEnd)
1624
1624
  this.flushBuffer([]);
1625
1625
  else
1626
- this.pendingBuffer = 0 /* No */;
1626
+ this.pendingBuffer = 0 /* Buf.No */;
1627
1627
  if (!this.posCovered())
1628
1628
  this.getLine();
1629
1629
  }
@@ -1651,7 +1651,7 @@ class ContentBuilder {
1651
1651
  this.textOff = 0;
1652
1652
  }
1653
1653
  }
1654
- let take = Math.min(this.text.length - this.textOff, length, 512 /* Chunk */);
1654
+ let take = Math.min(this.text.length - this.textOff, length, 512 /* T.Chunk */);
1655
1655
  this.flushBuffer(active.slice(0, openStart));
1656
1656
  this.getLine().append(wrapMarks(new TextView(this.text.slice(this.textOff, this.textOff + take)), active), openStart);
1657
1657
  this.atCursorPos = true;
@@ -1686,8 +1686,8 @@ class ContentBuilder {
1686
1686
  let cursorBefore = this.atCursorPos && !view.isEditable && openStart <= active.length && (from < to || deco.startSide > 0);
1687
1687
  let cursorAfter = !view.isEditable && (from < to || deco.startSide <= 0);
1688
1688
  let line = this.getLine();
1689
- if (this.pendingBuffer == 2 /* IfCursor */ && !cursorBefore)
1690
- this.pendingBuffer = 0 /* No */;
1689
+ if (this.pendingBuffer == 2 /* Buf.IfCursor */ && !cursorBefore)
1690
+ this.pendingBuffer = 0 /* Buf.No */;
1691
1691
  this.flushBuffer(active);
1692
1692
  if (cursorBefore) {
1693
1693
  line.append(wrapMarks(new WidgetBufferView(1), active), openStart);
@@ -1695,7 +1695,7 @@ class ContentBuilder {
1695
1695
  }
1696
1696
  line.append(wrapMarks(view, active), openStart);
1697
1697
  this.atCursorPos = cursorAfter;
1698
- this.pendingBuffer = !cursorAfter ? 0 /* No */ : from < to ? 1 /* Yes */ : 2 /* IfCursor */;
1698
+ this.pendingBuffer = !cursorAfter ? 0 /* Buf.No */ : from < to ? 1 /* Buf.Yes */ : 2 /* Buf.IfCursor */;
1699
1699
  }
1700
1700
  }
1701
1701
  else if (this.doc.lineAt(this.pos).from == this.pos) { // Line decoration
@@ -1988,7 +1988,7 @@ class ViewUpdate {
1988
1988
  let focus = view.hasFocus;
1989
1989
  if (focus != view.inputState.notifiedFocused) {
1990
1990
  view.inputState.notifiedFocused = focus;
1991
- this.flags |= 1 /* Focus */;
1991
+ this.flags |= 1 /* UpdateFlag.Focus */;
1992
1992
  }
1993
1993
  }
1994
1994
  /**
@@ -2003,27 +2003,27 @@ class ViewUpdate {
2003
2003
  update.
2004
2004
  */
2005
2005
  get viewportChanged() {
2006
- return (this.flags & 4 /* Viewport */) > 0;
2006
+ return (this.flags & 4 /* UpdateFlag.Viewport */) > 0;
2007
2007
  }
2008
2008
  /**
2009
2009
  Indicates whether the height of a block element in the editor
2010
2010
  changed in this update.
2011
2011
  */
2012
2012
  get heightChanged() {
2013
- return (this.flags & 2 /* Height */) > 0;
2013
+ return (this.flags & 2 /* UpdateFlag.Height */) > 0;
2014
2014
  }
2015
2015
  /**
2016
2016
  Returns true when the document was modified or the size of the
2017
2017
  editor, or elements within the editor, changed.
2018
2018
  */
2019
2019
  get geometryChanged() {
2020
- return this.docChanged || (this.flags & (8 /* Geometry */ | 2 /* Height */)) > 0;
2020
+ return this.docChanged || (this.flags & (8 /* UpdateFlag.Geometry */ | 2 /* UpdateFlag.Height */)) > 0;
2021
2021
  }
2022
2022
  /**
2023
2023
  True when this update indicates a focus change.
2024
2024
  */
2025
2025
  get focusChanged() {
2026
- return (this.flags & 1 /* Focus */) > 0;
2026
+ return (this.flags & 1 /* UpdateFlag.Focus */) > 0;
2027
2027
  }
2028
2028
  /**
2029
2029
  Whether the document changed in this update.
@@ -2082,12 +2082,12 @@ for (let p of ["()", "[]", "{}"]) {
2082
2082
  }
2083
2083
  function charType(ch) {
2084
2084
  return ch <= 0xf7 ? LowTypes[ch] :
2085
- 0x590 <= ch && ch <= 0x5f4 ? 2 /* R */ :
2085
+ 0x590 <= ch && ch <= 0x5f4 ? 2 /* T.R */ :
2086
2086
  0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :
2087
- 0x6ee <= ch && ch <= 0x8ac ? 4 /* AL */ :
2088
- 0x2000 <= ch && ch <= 0x200b ? 256 /* NI */ :
2089
- 0xfb50 <= ch && ch <= 0xfdff ? 4 /* AL */ :
2090
- ch == 0x200c ? 256 /* NI */ : 1 /* L */;
2087
+ 0x6ee <= ch && ch <= 0x8ac ? 4 /* T.AL */ :
2088
+ 0x2000 <= ch && ch <= 0x200b ? 256 /* T.NI */ :
2089
+ 0xfb50 <= ch && ch <= 0xfdff ? 4 /* T.AL */ :
2090
+ ch == 0x200c ? 256 /* T.NI */ : 1 /* T.L */;
2091
2091
  }
2092
2092
  const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;
2093
2093
  /**
@@ -2152,8 +2152,8 @@ class BidiSpan {
2152
2152
  // Reused array of character types
2153
2153
  const types = [];
2154
2154
  function computeOrder(line, direction) {
2155
- let len = line.length, outerType = direction == LTR ? 1 /* L */ : 2 /* R */, oppositeType = direction == LTR ? 2 /* R */ : 1 /* L */;
2156
- if (!line || outerType == 1 /* L */ && !BidiRE.test(line))
2155
+ let len = line.length, outerType = direction == LTR ? 1 /* T.L */ : 2 /* T.R */, oppositeType = direction == LTR ? 2 /* T.R */ : 1 /* T.L */;
2156
+ if (!line || outerType == 1 /* T.L */ && !BidiRE.test(line))
2157
2157
  return trivialOrder(len);
2158
2158
  // W1. Examine each non-spacing mark (NSM) in the level run, and
2159
2159
  // change the type of the NSM to the type of the previous
@@ -2167,12 +2167,12 @@ function computeOrder(line, direction) {
2167
2167
  // (Left after this: L, R, EN, AN, ET, CS, NI)
2168
2168
  for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
2169
2169
  let type = charType(line.charCodeAt(i));
2170
- if (type == 512 /* NSM */)
2170
+ if (type == 512 /* T.NSM */)
2171
2171
  type = prev;
2172
- else if (type == 8 /* EN */ && prevStrong == 4 /* AL */)
2173
- type = 16 /* AN */;
2174
- types[i] = type == 4 /* AL */ ? 2 /* R */ : type;
2175
- if (type & 7 /* Strong */)
2172
+ else if (type == 8 /* T.EN */ && prevStrong == 4 /* T.AL */)
2173
+ type = 16 /* T.AN */;
2174
+ types[i] = type == 4 /* T.AL */ ? 2 /* T.R */ : type;
2175
+ if (type & 7 /* T.Strong */)
2176
2176
  prevStrong = type;
2177
2177
  prev = type;
2178
2178
  }
@@ -2186,26 +2186,26 @@ function computeOrder(line, direction) {
2186
2186
  // (Left after this: L, R, EN+AN, NI)
2187
2187
  for (let i = 0, prev = outerType, prevStrong = outerType; i < len; i++) {
2188
2188
  let type = types[i];
2189
- if (type == 128 /* CS */) {
2190
- if (i < len - 1 && prev == types[i + 1] && (prev & 24 /* Num */))
2189
+ if (type == 128 /* T.CS */) {
2190
+ if (i < len - 1 && prev == types[i + 1] && (prev & 24 /* T.Num */))
2191
2191
  type = types[i] = prev;
2192
2192
  else
2193
- types[i] = 256 /* NI */;
2193
+ types[i] = 256 /* T.NI */;
2194
2194
  }
2195
- else if (type == 64 /* ET */) {
2195
+ else if (type == 64 /* T.ET */) {
2196
2196
  let end = i + 1;
2197
- while (end < len && types[end] == 64 /* ET */)
2197
+ while (end < len && types[end] == 64 /* T.ET */)
2198
2198
  end++;
2199
- let replace = (i && prev == 8 /* EN */) || (end < len && types[end] == 8 /* EN */) ? (prevStrong == 1 /* L */ ? 1 /* L */ : 8 /* EN */) : 256 /* NI */;
2199
+ let replace = (i && prev == 8 /* T.EN */) || (end < len && types[end] == 8 /* T.EN */) ? (prevStrong == 1 /* T.L */ ? 1 /* T.L */ : 8 /* T.EN */) : 256 /* T.NI */;
2200
2200
  for (let j = i; j < end; j++)
2201
2201
  types[j] = replace;
2202
2202
  i = end - 1;
2203
2203
  }
2204
- else if (type == 8 /* EN */ && prevStrong == 1 /* L */) {
2205
- types[i] = 1 /* L */;
2204
+ else if (type == 8 /* T.EN */ && prevStrong == 1 /* T.L */) {
2205
+ types[i] = 1 /* T.L */;
2206
2206
  }
2207
2207
  prev = type;
2208
- if (type & 7 /* Strong */)
2208
+ if (type & 7 /* T.Strong */)
2209
2209
  prevStrong = type;
2210
2210
  }
2211
2211
  // N0. Process bracket pairs in an isolating run sequence
@@ -2220,9 +2220,9 @@ function computeOrder(line, direction) {
2220
2220
  for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
2221
2221
  if (BracketStack[sJ + 1] == -br) {
2222
2222
  let flags = BracketStack[sJ + 2];
2223
- let type = (flags & 2 /* EmbedInside */) ? outerType :
2224
- !(flags & 4 /* OppositeInside */) ? 0 :
2225
- (flags & 1 /* OppositeBefore */) ? oppositeType : outerType;
2223
+ let type = (flags & 2 /* Bracketed.EmbedInside */) ? outerType :
2224
+ !(flags & 4 /* Bracketed.OppositeInside */) ? 0 :
2225
+ (flags & 1 /* Bracketed.OppositeBefore */) ? oppositeType : outerType;
2226
2226
  if (type)
2227
2227
  types[i] = types[BracketStack[sJ]] = type;
2228
2228
  sI = sJ;
@@ -2230,7 +2230,7 @@ function computeOrder(line, direction) {
2230
2230
  }
2231
2231
  }
2232
2232
  }
2233
- else if (BracketStack.length == 189 /* MaxDepth */) {
2233
+ else if (BracketStack.length == 189 /* Bracketed.MaxDepth */) {
2234
2234
  break;
2235
2235
  }
2236
2236
  else {
@@ -2239,20 +2239,20 @@ function computeOrder(line, direction) {
2239
2239
  BracketStack[sI++] = context;
2240
2240
  }
2241
2241
  }
2242
- else if ((type = types[i]) == 2 /* R */ || type == 1 /* L */) {
2242
+ else if ((type = types[i]) == 2 /* T.R */ || type == 1 /* T.L */) {
2243
2243
  let embed = type == outerType;
2244
- context = embed ? 0 : 1 /* OppositeBefore */;
2244
+ context = embed ? 0 : 1 /* Bracketed.OppositeBefore */;
2245
2245
  for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {
2246
2246
  let cur = BracketStack[sJ + 2];
2247
- if (cur & 2 /* EmbedInside */)
2247
+ if (cur & 2 /* Bracketed.EmbedInside */)
2248
2248
  break;
2249
2249
  if (embed) {
2250
- BracketStack[sJ + 2] |= 2 /* EmbedInside */;
2250
+ BracketStack[sJ + 2] |= 2 /* Bracketed.EmbedInside */;
2251
2251
  }
2252
2252
  else {
2253
- if (cur & 4 /* OppositeInside */)
2253
+ if (cur & 4 /* Bracketed.OppositeInside */)
2254
2254
  break;
2255
- BracketStack[sJ + 2] |= 4 /* OppositeInside */;
2255
+ BracketStack[sJ + 2] |= 4 /* Bracketed.OppositeInside */;
2256
2256
  }
2257
2257
  }
2258
2258
  }
@@ -2265,13 +2265,13 @@ function computeOrder(line, direction) {
2265
2265
  // N2. Any remaining neutrals take the embedding direction.
2266
2266
  // (Left after this: L, R, EN+AN)
2267
2267
  for (let i = 0; i < len; i++) {
2268
- if (types[i] == 256 /* NI */) {
2268
+ if (types[i] == 256 /* T.NI */) {
2269
2269
  let end = i + 1;
2270
- while (end < len && types[end] == 256 /* NI */)
2270
+ while (end < len && types[end] == 256 /* T.NI */)
2271
2271
  end++;
2272
- let beforeL = (i ? types[i - 1] : outerType) == 1 /* L */;
2273
- let afterL = (end < len ? types[end] : outerType) == 1 /* L */;
2274
- let replace = beforeL == afterL ? (beforeL ? 1 /* L */ : 2 /* R */) : outerType;
2272
+ let beforeL = (i ? types[i - 1] : outerType) == 1 /* T.L */;
2273
+ let afterL = (end < len ? types[end] : outerType) == 1 /* T.L */;
2274
+ let replace = beforeL == afterL ? (beforeL ? 1 /* T.L */ : 2 /* T.R */) : outerType;
2275
2275
  for (let j = i; j < end; j++)
2276
2276
  types[j] = replace;
2277
2277
  i = end - 1;
@@ -2283,15 +2283,15 @@ function computeOrder(line, direction) {
2283
2283
  // explicit embedding into account, we can build up the order on
2284
2284
  // the fly, without following the level-based algorithm.
2285
2285
  let order = [];
2286
- if (outerType == 1 /* L */) {
2286
+ if (outerType == 1 /* T.L */) {
2287
2287
  for (let i = 0; i < len;) {
2288
- let start = i, rtl = types[i++] != 1 /* L */;
2289
- while (i < len && rtl == (types[i] != 1 /* L */))
2288
+ let start = i, rtl = types[i++] != 1 /* T.L */;
2289
+ while (i < len && rtl == (types[i] != 1 /* T.L */))
2290
2290
  i++;
2291
2291
  if (rtl) {
2292
2292
  for (let j = i; j > start;) {
2293
- let end = j, l = types[--j] != 2 /* R */;
2294
- while (j > start && l == (types[j - 1] != 2 /* R */))
2293
+ let end = j, l = types[--j] != 2 /* T.R */;
2294
+ while (j > start && l == (types[j - 1] != 2 /* T.R */))
2295
2295
  j--;
2296
2296
  order.push(new BidiSpan(j, end, l ? 2 : 1));
2297
2297
  }
@@ -2303,8 +2303,8 @@ function computeOrder(line, direction) {
2303
2303
  }
2304
2304
  else {
2305
2305
  for (let i = 0; i < len;) {
2306
- let start = i, rtl = types[i++] == 2 /* R */;
2307
- while (i < len && rtl == (types[i] == 2 /* R */))
2306
+ let start = i, rtl = types[i++] == 2 /* T.R */;
2307
+ while (i < len && rtl == (types[i] == 2 /* T.R */))
2308
2308
  i++;
2309
2309
  order.push(new BidiSpan(start, i, rtl ? 1 : 2));
2310
2310
  }
@@ -2525,7 +2525,7 @@ class DocView extends ContentView {
2525
2525
  let prevDeco = this.decorations, deco = this.updateDeco();
2526
2526
  let decoDiff = findChangedDeco(prevDeco, deco, update.changes);
2527
2527
  changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff);
2528
- if (this.dirty == 0 /* Not */ && changedRanges.length == 0) {
2528
+ if (this.dirty == 0 /* Dirty.Not */ && changedRanges.length == 0) {
2529
2529
  return false;
2530
2530
  }
2531
2531
  else {
@@ -2554,7 +2554,7 @@ class DocView extends ContentView {
2554
2554
  // to detect that situation.
2555
2555
  let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : undefined;
2556
2556
  this.sync(track);
2557
- this.dirty = 0 /* Not */;
2557
+ this.dirty = 0 /* Dirty.Not */;
2558
2558
  if (track && (track.written || observer.selectionRange.focusNode != track.node))
2559
2559
  this.forceSelection = true;
2560
2560
  this.dom.style.height = "";
@@ -2583,8 +2583,7 @@ class DocView extends ContentView {
2583
2583
  updateSelection(mustRead = false, fromPointer = false) {
2584
2584
  if (mustRead || !this.view.observer.selectionRange.focusNode)
2585
2585
  this.view.observer.readSelectionRange();
2586
- if (!(fromPointer || this.mayControlSelection()) ||
2587
- browser.ios && this.view.inputState.rapidCompositionStart)
2586
+ if (!(fromPointer || this.mayControlSelection()))
2588
2587
  return;
2589
2588
  let force = this.forceSelection;
2590
2589
  this.forceSelection = false;
@@ -2621,10 +2620,10 @@ class DocView extends ContentView {
2621
2620
  // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=1612076
2622
2621
  if (browser.gecko) {
2623
2622
  let nextTo = nextToUneditable(anchor.node, anchor.offset);
2624
- if (nextTo && nextTo != (1 /* Before */ | 2 /* After */)) {
2625
- let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /* Before */ ? 1 : -1);
2623
+ if (nextTo && nextTo != (1 /* NextTo.Before */ | 2 /* NextTo.After */)) {
2624
+ let text = nearbyTextNode(anchor.node, anchor.offset, nextTo == 1 /* NextTo.Before */ ? 1 : -1);
2626
2625
  if (text)
2627
- anchor = new DOMPos(text, nextTo == 1 /* Before */ ? 0 : text.nodeValue.length);
2626
+ anchor = new DOMPos(text, nextTo == 1 /* NextTo.Before */ ? 0 : text.nodeValue.length);
2628
2627
  }
2629
2628
  }
2630
2629
  rawSel.collapse(anchor.node, anchor.offset);
@@ -2956,8 +2955,8 @@ function nearbyTextNode(node, offset, side) {
2956
2955
  function nextToUneditable(node, offset) {
2957
2956
  if (node.nodeType != 1)
2958
2957
  return 0;
2959
- return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /* Before */ : 0) |
2960
- (offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /* After */ : 0);
2958
+ return (offset && node.childNodes[offset - 1].contentEditable == "false" ? 1 /* NextTo.Before */ : 0) |
2959
+ (offset < node.childNodes.length && node.childNodes[offset].contentEditable == "false" ? 2 /* NextTo.After */ : 0);
2961
2960
  }
2962
2961
  class DecorationComparator$1 {
2963
2962
  constructor() {
@@ -3312,7 +3311,7 @@ function skipAtoms(view, oldPos, pos) {
3312
3311
  for (let set of atoms) {
3313
3312
  set.between(pos.from - 1, pos.from + 1, (from, to, value) => {
3314
3313
  if (pos.from > from && pos.from < to) {
3315
- pos = oldPos.from > pos.from ? state.EditorSelection.cursor(from, 1) : state.EditorSelection.cursor(to, -1);
3314
+ pos = oldPos.head > pos.from ? state.EditorSelection.cursor(from, 1) : state.EditorSelection.cursor(to, -1);
3316
3315
  moved = true;
3317
3316
  }
3318
3317
  });
@@ -3354,7 +3353,6 @@ class InputState {
3354
3353
  // composition)
3355
3354
  this.compositionFirstChange = null;
3356
3355
  this.compositionEndedAt = 0;
3357
- this.rapidCompositionStart = false;
3358
3356
  this.mouseSelection = null;
3359
3357
  for (let type in handlers) {
3360
3358
  let handler = handlers[type];
@@ -3502,8 +3500,7 @@ class InputState {
3502
3500
  return false;
3503
3501
  }
3504
3502
  mustFlushObserver(event) {
3505
- return (event.type == "keydown" && event.keyCode != 229) ||
3506
- event.type == "compositionend" && !browser.ios;
3503
+ return event.type == "keydown" && event.keyCode != 229;
3507
3504
  }
3508
3505
  startMouseSelection(mouseSelection) {
3509
3506
  if (this.mouseSelection)
@@ -3771,8 +3768,7 @@ function basicMouseSelection(view, event) {
3771
3768
  return {
3772
3769
  update(update) {
3773
3770
  if (update.docChanged) {
3774
- if (start)
3775
- start.pos = update.changes.mapPos(start.pos);
3771
+ start.pos = update.changes.mapPos(start.pos);
3776
3772
  startSel = startSel.map(update.changes);
3777
3773
  lastEvent = null;
3778
3774
  }
@@ -3785,8 +3781,6 @@ function basicMouseSelection(view, event) {
3785
3781
  cur = last = queryPos(view, event);
3786
3782
  lastEvent = event;
3787
3783
  }
3788
- if (!cur || !start)
3789
- return startSel;
3790
3784
  let range = rangeForClick(view, cur.pos, cur.bias, type);
3791
3785
  if (start.pos != cur.pos && !extend) {
3792
3786
  let startRange = rangeForClick(view, start.pos, start.bias, type);
@@ -3958,36 +3952,24 @@ handlers.blur = view => {
3958
3952
  view.observer.clearSelectionRange();
3959
3953
  updateForFocusChange(view);
3960
3954
  };
3961
- function forceClearComposition(view, rapid) {
3962
- if (view.docView.compositionDeco.size) {
3963
- view.inputState.rapidCompositionStart = rapid;
3964
- try {
3965
- view.update([]);
3966
- }
3967
- finally {
3968
- view.inputState.rapidCompositionStart = false;
3969
- }
3970
- }
3971
- }
3972
3955
  handlers.compositionstart = handlers.compositionupdate = view => {
3973
3956
  if (view.inputState.compositionFirstChange == null)
3974
3957
  view.inputState.compositionFirstChange = true;
3975
3958
  if (view.inputState.composing < 0) {
3976
3959
  // FIXME possibly set a timeout to clear it again on Android
3977
3960
  view.inputState.composing = 0;
3978
- if (view.docView.compositionDeco.size) {
3979
- view.observer.flush();
3980
- forceClearComposition(view, true);
3981
- }
3982
3961
  }
3983
3962
  };
3984
3963
  handlers.compositionend = view => {
3985
3964
  view.inputState.composing = -1;
3986
3965
  view.inputState.compositionEndedAt = Date.now();
3987
3966
  view.inputState.compositionFirstChange = null;
3967
+ if (browser.chrome && browser.android)
3968
+ view.observer.flushSoon();
3988
3969
  setTimeout(() => {
3989
- if (view.inputState.composing < 0)
3990
- forceClearComposition(view, false);
3970
+ // Force the composition state to be cleared if it hasn't already been
3971
+ if (view.inputState.composing < 0 && view.docView.compositionDeco.size)
3972
+ view.update([]);
3991
3973
  }, 50);
3992
3974
  };
3993
3975
  handlers.contextmenu = view => {
@@ -4158,13 +4140,13 @@ const Epsilon = 1e-3;
4158
4140
  class HeightMap {
4159
4141
  constructor(length, // The number of characters covered
4160
4142
  height, // Height of this part of the document
4161
- flags = 2 /* Outdated */) {
4143
+ flags = 2 /* Flag.Outdated */) {
4162
4144
  this.length = length;
4163
4145
  this.height = height;
4164
4146
  this.flags = flags;
4165
4147
  }
4166
- get outdated() { return (this.flags & 2 /* Outdated */) > 0; }
4167
- set outdated(value) { this.flags = (value ? 2 /* Outdated */ : 0) | (this.flags & ~2 /* Outdated */); }
4148
+ get outdated() { return (this.flags & 2 /* Flag.Outdated */) > 0; }
4149
+ set outdated(value) { this.flags = (value ? 2 /* Flag.Outdated */ : 0) | (this.flags & ~2 /* Flag.Outdated */); }
4168
4150
  setHeight(oracle, height) {
4169
4151
  if (this.height != height) {
4170
4152
  if (Math.abs(this.height - height) > Epsilon)
@@ -4291,7 +4273,7 @@ class HeightMapText extends HeightMapBlock {
4291
4273
  }
4292
4274
  replace(_from, _to, nodes) {
4293
4275
  let node = nodes[0];
4294
- if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /* SingleLine */)) &&
4276
+ if (nodes.length == 1 && (node instanceof HeightMapText || node instanceof HeightMapGap && (node.flags & 4 /* Flag.SingleLine */)) &&
4295
4277
  Math.abs(this.length - node.length) < 10) {
4296
4278
  if (node instanceof HeightMapGap)
4297
4279
  node = new HeightMapText(node.length, this.height);
@@ -4417,12 +4399,12 @@ class HeightMapGap extends HeightMap {
4417
4399
  }
4418
4400
  class HeightMapBranch extends HeightMap {
4419
4401
  constructor(left, brk, right) {
4420
- super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /* Outdated */ : 0));
4402
+ super(left.length + brk + right.length, left.height + right.height, brk | (left.outdated || right.outdated ? 2 /* Flag.Outdated */ : 0));
4421
4403
  this.left = left;
4422
4404
  this.right = right;
4423
4405
  this.size = left.size + right.size;
4424
4406
  }
4425
- get break() { return this.flags & 1 /* Break */; }
4407
+ get break() { return this.flags & 1 /* Flag.Break */; }
4426
4408
  blockAt(height, doc, top, offset) {
4427
4409
  let mid = top + this.left.height;
4428
4410
  return height < mid ? this.left.blockAt(height, doc, top, offset)
@@ -4606,7 +4588,7 @@ class NodeBuilder {
4606
4588
  blankContent(from, to) {
4607
4589
  let gap = new HeightMapGap(to - from);
4608
4590
  if (this.oracle.doc.lineAt(from).to == to)
4609
- gap.flags |= 4 /* SingleLine */;
4591
+ gap.flags |= 4 /* Flag.SingleLine */;
4610
4592
  return gap;
4611
4593
  }
4612
4594
  ensureLine() {
@@ -4804,7 +4786,7 @@ class ViewState {
4804
4786
  }
4805
4787
  }
4806
4788
  this.viewports = viewports.sort((a, b) => a.from - b.from);
4807
- this.scaler = this.heightMap.height <= 7000000 /* MaxDOMHeight */ ? IdScaler :
4789
+ this.scaler = this.heightMap.height <= 7000000 /* VP.MaxDOMHeight */ ? IdScaler :
4808
4790
  new BigScaler(this.heightOracle.doc, this.heightMap, this.viewports);
4809
4791
  }
4810
4792
  updateViewportLines() {
@@ -4822,18 +4804,18 @@ class ViewState {
4822
4804
  let prevHeight = this.heightMap.height;
4823
4805
  this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
4824
4806
  if (this.heightMap.height != prevHeight)
4825
- update.flags |= 2 /* Height */;
4807
+ update.flags |= 2 /* UpdateFlag.Height */;
4826
4808
  let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
4827
4809
  if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) ||
4828
4810
  !this.viewportIsAppropriate(viewport))
4829
4811
  viewport = this.getViewport(0, scrollTarget);
4830
- let updateLines = !update.changes.empty || (update.flags & 2 /* Height */) ||
4812
+ let updateLines = !update.changes.empty || (update.flags & 2 /* UpdateFlag.Height */) ||
4831
4813
  viewport.from != this.viewport.from || viewport.to != this.viewport.to;
4832
4814
  this.viewport = viewport;
4833
4815
  this.updateForViewport();
4834
4816
  if (updateLines)
4835
4817
  this.updateViewportLines();
4836
- if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4818
+ if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* LG.DoubleMargin */)
4837
4819
  this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
4838
4820
  update.flags |= this.computeVisibleRanges();
4839
4821
  if (scrollTarget)
@@ -4857,13 +4839,13 @@ class ViewState {
4857
4839
  if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
4858
4840
  this.paddingTop = paddingTop;
4859
4841
  this.paddingBottom = paddingBottom;
4860
- result |= 8 /* Geometry */ | 2 /* Height */;
4842
+ result |= 8 /* UpdateFlag.Geometry */ | 2 /* UpdateFlag.Height */;
4861
4843
  }
4862
4844
  if (this.editorWidth != view.scrollDOM.clientWidth) {
4863
4845
  if (oracle.lineWrapping)
4864
4846
  measureContent = true;
4865
4847
  this.editorWidth = view.scrollDOM.clientWidth;
4866
- result |= 8 /* Geometry */;
4848
+ result |= 8 /* UpdateFlag.Geometry */;
4867
4849
  }
4868
4850
  // Pixel viewport
4869
4851
  let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
@@ -4881,7 +4863,7 @@ class ViewState {
4881
4863
  if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
4882
4864
  this.contentDOMWidth = contentWidth;
4883
4865
  this.editorHeight = view.scrollDOM.clientHeight;
4884
- result |= 8 /* Geometry */;
4866
+ result |= 8 /* UpdateFlag.Geometry */;
4885
4867
  }
4886
4868
  if (measureContent) {
4887
4869
  let lineHeights = view.docView.measureVisibleLineHeights(this.viewport);
@@ -4892,7 +4874,7 @@ class ViewState {
4892
4874
  refresh = oracle.refresh(whiteSpace, lineHeight, charWidth, contentWidth / charWidth, lineHeights);
4893
4875
  if (refresh) {
4894
4876
  view.docView.minWidth = 0;
4895
- result |= 8 /* Geometry */;
4877
+ result |= 8 /* UpdateFlag.Geometry */;
4896
4878
  }
4897
4879
  }
4898
4880
  if (dTop > 0 && dBottom > 0)
@@ -4905,16 +4887,16 @@ class ViewState {
4905
4887
  this.heightMap = this.heightMap.updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
4906
4888
  }
4907
4889
  if (oracle.heightChanged)
4908
- result |= 2 /* Height */;
4890
+ result |= 2 /* UpdateFlag.Height */;
4909
4891
  }
4910
4892
  let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) ||
4911
4893
  this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from || this.scrollTarget.range.head > this.viewport.to);
4912
4894
  if (viewportChange)
4913
4895
  this.viewport = this.getViewport(bias, this.scrollTarget);
4914
4896
  this.updateForViewport();
4915
- if ((result & 2 /* Height */) || viewportChange)
4897
+ if ((result & 2 /* UpdateFlag.Height */) || viewportChange)
4916
4898
  this.updateViewportLines();
4917
- if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4899
+ if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* LG.DoubleMargin */)
4918
4900
  this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps));
4919
4901
  result |= this.computeVisibleRanges();
4920
4902
  if (this.mustEnforceCursorAssoc) {
@@ -4933,9 +4915,9 @@ class ViewState {
4933
4915
  // This will divide VP.Margin between the top and the
4934
4916
  // bottom, depending on the bias (the change in viewport position
4935
4917
  // since the last update). It'll hold a number between 0 and 1
4936
- let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /* Margin */ / 2));
4918
+ let marginTop = 0.5 - Math.max(-0.5, Math.min(0.5, bias / 1000 /* VP.Margin */ / 2));
4937
4919
  let map = this.heightMap, doc = this.state.doc, { visibleTop, visibleBottom } = this;
4938
- let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1000 /* Margin */, QueryType.ByHeight, doc, 0, 0).from, map.lineAt(visibleBottom + (1 - marginTop) * 1000 /* Margin */, QueryType.ByHeight, doc, 0, 0).to);
4920
+ let viewport = new Viewport(map.lineAt(visibleTop - marginTop * 1000 /* VP.Margin */, QueryType.ByHeight, doc, 0, 0).from, map.lineAt(visibleBottom + (1 - marginTop) * 1000 /* VP.Margin */, QueryType.ByHeight, doc, 0, 0).to);
4939
4921
  // If scrollTarget is given, make sure the viewport includes that position
4940
4922
  if (scrollTarget) {
4941
4923
  let { head } = scrollTarget.range;
@@ -4948,7 +4930,7 @@ class ViewState {
4948
4930
  topPos = block.top;
4949
4931
  else
4950
4932
  topPos = block.bottom - viewHeight;
4951
- viewport = new Viewport(map.lineAt(topPos - 1000 /* Margin */ / 2, QueryType.ByHeight, doc, 0, 0).from, map.lineAt(topPos + viewHeight + 1000 /* Margin */ / 2, QueryType.ByHeight, doc, 0, 0).to);
4933
+ viewport = new Viewport(map.lineAt(topPos - 1000 /* VP.Margin */ / 2, QueryType.ByHeight, doc, 0, 0).from, map.lineAt(topPos + viewHeight + 1000 /* VP.Margin */ / 2, QueryType.ByHeight, doc, 0, 0).to);
4952
4934
  }
4953
4935
  }
4954
4936
  return viewport;
@@ -4965,10 +4947,10 @@ class ViewState {
4965
4947
  let { top } = this.heightMap.lineAt(from, QueryType.ByPos, this.state.doc, 0, 0);
4966
4948
  let { bottom } = this.heightMap.lineAt(to, QueryType.ByPos, this.state.doc, 0, 0);
4967
4949
  let { visibleTop, visibleBottom } = this;
4968
- return (from == 0 || top <= visibleTop - Math.max(10 /* MinCoverMargin */, Math.min(-bias, 250 /* MaxCoverMargin */))) &&
4950
+ return (from == 0 || top <= visibleTop - Math.max(10 /* VP.MinCoverMargin */, Math.min(-bias, 250 /* VP.MaxCoverMargin */))) &&
4969
4951
  (to == this.state.doc.length ||
4970
- bottom >= visibleBottom + Math.max(10 /* MinCoverMargin */, Math.min(bias, 250 /* MaxCoverMargin */))) &&
4971
- (top > visibleTop - 2 * 1000 /* Margin */ && bottom < visibleBottom + 2 * 1000 /* Margin */);
4952
+ bottom >= visibleBottom + Math.max(10 /* VP.MinCoverMargin */, Math.min(bias, 250 /* VP.MaxCoverMargin */))) &&
4953
+ (top > visibleTop - 2 * 1000 /* VP.Margin */ && bottom < visibleBottom + 2 * 1000 /* VP.Margin */);
4972
4954
  }
4973
4955
  mapLineGaps(gaps, changes) {
4974
4956
  if (!gaps.length || changes.empty)
@@ -4992,20 +4974,20 @@ class ViewState {
4992
4974
  if (this.defaultTextDirection != exports.Direction.LTR)
4993
4975
  return gaps;
4994
4976
  for (let line of this.viewportLines) {
4995
- if (line.length < 4000 /* DoubleMargin */)
4977
+ if (line.length < 4000 /* LG.DoubleMargin */)
4996
4978
  continue;
4997
4979
  let structure = lineStructure(line.from, line.to, this.stateDeco);
4998
- if (structure.total < 4000 /* DoubleMargin */)
4980
+ if (structure.total < 4000 /* LG.DoubleMargin */)
4999
4981
  continue;
5000
4982
  let viewFrom, viewTo;
5001
4983
  if (this.heightOracle.lineWrapping) {
5002
- let marginHeight = (2000 /* Margin */ / this.heightOracle.lineLength) * this.heightOracle.lineHeight;
4984
+ let marginHeight = (2000 /* LG.Margin */ / this.heightOracle.lineLength) * this.heightOracle.lineHeight;
5003
4985
  viewFrom = findPosition(structure, (this.visibleTop - line.top - marginHeight) / line.height);
5004
4986
  viewTo = findPosition(structure, (this.visibleBottom - line.top + marginHeight) / line.height);
5005
4987
  }
5006
4988
  else {
5007
4989
  let totalWidth = structure.total * this.heightOracle.charWidth;
5008
- let marginWidth = 2000 /* Margin */ * this.heightOracle.charWidth;
4990
+ let marginWidth = 2000 /* LG.Margin */ * this.heightOracle.charWidth;
5009
4991
  viewFrom = findPosition(structure, (this.pixelViewport.left - marginWidth) / totalWidth);
5010
4992
  viewTo = findPosition(structure, (this.pixelViewport.right + marginWidth) / totalWidth);
5011
4993
  }
@@ -5017,13 +4999,13 @@ class ViewState {
5017
4999
  let sel = this.state.selection.main;
5018
5000
  // Make sure the gaps don't cover a selection end
5019
5001
  if (sel.from >= line.from && sel.from <= line.to)
5020
- cutRange(outside, sel.from - 10 /* SelectionMargin */, sel.from + 10 /* SelectionMargin */);
5002
+ cutRange(outside, sel.from - 10 /* LG.SelectionMargin */, sel.from + 10 /* LG.SelectionMargin */);
5021
5003
  if (!sel.empty && sel.to >= line.from && sel.to <= line.to)
5022
- cutRange(outside, sel.to - 10 /* SelectionMargin */, sel.to + 10 /* SelectionMargin */);
5004
+ cutRange(outside, sel.to - 10 /* LG.SelectionMargin */, sel.to + 10 /* LG.SelectionMargin */);
5023
5005
  for (let { from, to } of outside)
5024
- if (to - from > 1000 /* HalfMargin */) {
5006
+ if (to - from > 1000 /* LG.HalfMargin */) {
5025
5007
  gaps.push(find(current, gap => gap.from >= line.from && gap.to <= line.to &&
5026
- Math.abs(gap.from - from) < 1000 /* HalfMargin */ && Math.abs(gap.to - to) < 1000 /* HalfMargin */) ||
5008
+ Math.abs(gap.from - from) < 1000 /* LG.HalfMargin */ && Math.abs(gap.to - to) < 1000 /* LG.HalfMargin */) ||
5027
5009
  new LineGap(from, to, this.gapSize(line, from, to, structure)));
5028
5010
  }
5029
5011
  }
@@ -5056,7 +5038,7 @@ class ViewState {
5056
5038
  let changed = ranges.length != this.visibleRanges.length ||
5057
5039
  this.visibleRanges.some((r, i) => r.from != ranges[i].from || r.to != ranges[i].to);
5058
5040
  this.visibleRanges = ranges;
5059
- return changed ? 4 /* Viewport */ : 0;
5041
+ return changed ? 4 /* UpdateFlag.Viewport */ : 0;
5060
5042
  }
5061
5043
  lineBlockAt(pos) {
5062
5044
  return (pos >= this.viewport.from && pos <= this.viewport.to && this.viewportLines.find(b => b.from <= pos && b.to >= pos)) ||
@@ -5162,7 +5144,7 @@ class BigScaler {
5162
5144
  vpHeight += bottom - top;
5163
5145
  return { from, to, top, bottom, domTop: 0, domBottom: 0 };
5164
5146
  });
5165
- this.scale = (7000000 /* MaxDOMHeight */ - vpHeight) / (heightMap.height - vpHeight);
5147
+ this.scale = (7000000 /* VP.MaxDOMHeight */ - vpHeight) / (heightMap.height - vpHeight);
5166
5148
  for (let obj of this.viewports) {
5167
5149
  obj.domTop = domBase + (obj.top - base) * this.scale;
5168
5150
  domBase = obj.domBottom = obj.domTop + (obj.bottom - obj.top);
@@ -5465,6 +5447,7 @@ class DOMObserver {
5465
5447
  this.resizeTimeout = -1;
5466
5448
  this.queue = [];
5467
5449
  this.delayedAndroidKey = null;
5450
+ this.lastChange = 0;
5468
5451
  this.scrollTargets = [];
5469
5452
  this.intersection = null;
5470
5453
  this.resize = null;
@@ -5511,8 +5494,7 @@ class DOMObserver {
5511
5494
  });
5512
5495
  this.resize.observe(view.scrollDOM);
5513
5496
  }
5514
- this.win = view.dom.ownerDocument.defaultView;
5515
- this.addWindowListeners(this.win);
5497
+ this.addWindowListeners(this.win = view.win);
5516
5498
  this.start();
5517
5499
  if (typeof IntersectionObserver == "function") {
5518
5500
  this.intersection = new IntersectionObserver(entries => {
@@ -5691,26 +5673,34 @@ class DOMObserver {
5691
5673
  // detected (via beforeinput or keydown), and then tries to flush
5692
5674
  // them or, if that has no effect, dispatches the given key.
5693
5675
  delayAndroidKey(key, keyCode) {
5676
+ var _a;
5694
5677
  if (!this.delayedAndroidKey)
5695
- requestAnimationFrame(() => {
5678
+ this.view.win.requestAnimationFrame(() => {
5696
5679
  let key = this.delayedAndroidKey;
5697
5680
  this.delayedAndroidKey = null;
5698
5681
  this.delayedFlush = -1;
5699
- if (!this.flush())
5682
+ if (!this.flush() && key.force)
5700
5683
  dispatchKey(this.dom, key.key, key.keyCode);
5701
5684
  });
5702
5685
  // Since backspace beforeinput is sometimes signalled spuriously,
5703
5686
  // Enter always takes precedence.
5704
5687
  if (!this.delayedAndroidKey || key == "Enter")
5705
- this.delayedAndroidKey = { key, keyCode };
5688
+ this.delayedAndroidKey = {
5689
+ key, keyCode,
5690
+ // Only run the key handler when no changes are detected if
5691
+ // this isn't coming right after another change, in which case
5692
+ // it is probably part of a weird chain of updates, and should
5693
+ // be ignored if it returns the DOM to its previous state.
5694
+ force: this.lastChange < Date.now() - 50 || !!((_a = this.delayedAndroidKey) === null || _a === void 0 ? void 0 : _a.force)
5695
+ };
5706
5696
  }
5707
5697
  flushSoon() {
5708
5698
  if (this.delayedFlush < 0)
5709
- this.delayedFlush = window.setTimeout(() => { this.delayedFlush = -1; this.flush(); }, 20);
5699
+ this.delayedFlush = this.view.win.requestAnimationFrame(() => { this.delayedFlush = -1; this.flush(); });
5710
5700
  }
5711
5701
  forceFlush() {
5712
5702
  if (this.delayedFlush >= 0) {
5713
- window.clearTimeout(this.delayedFlush);
5703
+ this.view.win.cancelAnimationFrame(this.delayedFlush);
5714
5704
  this.delayedFlush = -1;
5715
5705
  }
5716
5706
  this.flush();
@@ -5744,13 +5734,15 @@ class DOMObserver {
5744
5734
  // managing those will make sure processRecords is called and the
5745
5735
  // view is resynchronized after
5746
5736
  if (this.delayedFlush >= 0 || this.delayedAndroidKey)
5747
- return;
5737
+ return false;
5748
5738
  if (readSelection)
5749
5739
  this.readSelectionRange();
5750
5740
  let { from, to, typeOver } = this.processRecords();
5751
5741
  let newSel = this.selectionChanged && hasSelection(this.dom, this.selectionRange);
5752
5742
  if (from < 0 && !newSel)
5753
- return;
5743
+ return false;
5744
+ if (from > -1)
5745
+ this.lastChange = Date.now();
5754
5746
  this.view.inputState.lastFocusTime = 0;
5755
5747
  this.selectionChanged = false;
5756
5748
  let startState = this.view.state;
@@ -5766,7 +5758,7 @@ class DOMObserver {
5766
5758
  return null;
5767
5759
  cView.markDirty(rec.type == "attributes");
5768
5760
  if (rec.type == "attributes")
5769
- cView.dirty |= 4 /* Attrs */;
5761
+ cView.dirty |= 4 /* Dirty.Attrs */;
5770
5762
  if (rec.type == "childList") {
5771
5763
  let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1);
5772
5764
  let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1);
@@ -6093,7 +6085,7 @@ class EditorView {
6093
6085
  /**
6094
6086
  @internal
6095
6087
  */
6096
- this.updateState = 2 /* Updating */;
6088
+ this.updateState = 2 /* UpdateState.Updating */;
6097
6089
  /**
6098
6090
  @internal
6099
6091
  */
@@ -6132,7 +6124,7 @@ class EditorView {
6132
6124
  this.docView = new DocView(this);
6133
6125
  this.mountStyles();
6134
6126
  this.updateAttrs();
6135
- this.updateState = 0 /* Idle */;
6127
+ this.updateState = 0 /* UpdateState.Idle */;
6136
6128
  this.requestMeasure();
6137
6129
  if (config.parent)
6138
6130
  config.parent.appendChild(this.dom);
@@ -6180,6 +6172,10 @@ class EditorView {
6180
6172
  The document or shadow root that the view lives in.
6181
6173
  */
6182
6174
  get root() { return this._root; }
6175
+ /**
6176
+ @internal
6177
+ */
6178
+ get win() { return this.dom.ownerDocument.defaultView; }
6183
6179
  dispatch(...input) {
6184
6180
  this._dispatch(input.length == 1 && input[0] instanceof state.Transaction ? input[0]
6185
6181
  : this.state.update(...input));
@@ -6193,7 +6189,7 @@ class EditorView {
6193
6189
  as a primitive.
6194
6190
  */
6195
6191
  update(transactions) {
6196
- if (this.updateState != 0 /* Idle */)
6192
+ if (this.updateState != 0 /* UpdateState.Idle */)
6197
6193
  throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
6198
6194
  let redrawn = false, attrsChanged = false, update;
6199
6195
  let state$1 = this.state;
@@ -6213,7 +6209,7 @@ class EditorView {
6213
6209
  update = ViewUpdate.create(this, state$1, transactions);
6214
6210
  let scrollTarget = this.viewState.scrollTarget;
6215
6211
  try {
6216
- this.updateState = 2 /* Updating */;
6212
+ this.updateState = 2 /* UpdateState.Updating */;
6217
6213
  for (let tr of transactions) {
6218
6214
  if (scrollTarget)
6219
6215
  scrollTarget = scrollTarget.map(tr.changes);
@@ -6239,7 +6235,7 @@ class EditorView {
6239
6235
  this.docView.updateSelection(redrawn, transactions.some(tr => tr.isUserEvent("select.pointer")));
6240
6236
  }
6241
6237
  finally {
6242
- this.updateState = 0 /* Idle */;
6238
+ this.updateState = 0 /* UpdateState.Idle */;
6243
6239
  }
6244
6240
  if (update.startState.facet(theme) != update.state.facet(theme))
6245
6241
  this.viewState.mustMeasureContent = true;
@@ -6257,13 +6253,13 @@ class EditorView {
6257
6253
  [`dispatch`](https://codemirror.net/6/docs/ref/#view.EditorView.dispatch) instead.)
6258
6254
  */
6259
6255
  setState(newState) {
6260
- if (this.updateState != 0 /* Idle */)
6256
+ if (this.updateState != 0 /* UpdateState.Idle */)
6261
6257
  throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");
6262
6258
  if (this.destroyed) {
6263
6259
  this.viewState.state = newState;
6264
6260
  return;
6265
6261
  }
6266
- this.updateState = 2 /* Updating */;
6262
+ this.updateState = 2 /* UpdateState.Updating */;
6267
6263
  let hadFocus = this.hasFocus;
6268
6264
  try {
6269
6265
  for (let plugin of this.plugins)
@@ -6280,7 +6276,7 @@ class EditorView {
6280
6276
  this.bidiCache = [];
6281
6277
  }
6282
6278
  finally {
6283
- this.updateState = 0 /* Idle */;
6279
+ this.updateState = 0 /* UpdateState.Idle */;
6284
6280
  }
6285
6281
  if (hadFocus)
6286
6282
  this.focus();
@@ -6331,7 +6327,7 @@ class EditorView {
6331
6327
  let refHeight = scrollTop > scrollHeight - clientHeight - 4 ? scrollHeight : scrollTop;
6332
6328
  try {
6333
6329
  for (let i = 0;; i++) {
6334
- this.updateState = 1 /* Measuring */;
6330
+ this.updateState = 1 /* UpdateState.Measuring */;
6335
6331
  let oldViewport = this.viewport;
6336
6332
  let refBlock = this.viewState.lineBlockAtHeight(refHeight);
6337
6333
  let changed = this.viewState.measure(this);
@@ -6345,7 +6341,7 @@ class EditorView {
6345
6341
  }
6346
6342
  let measuring = [];
6347
6343
  // Only run measure requests in this cycle when the viewport didn't change
6348
- if (!(changed & 4 /* Viewport */))
6344
+ if (!(changed & 4 /* UpdateFlag.Viewport */))
6349
6345
  [this.measureRequests, measuring] = [measuring, this.measureRequests];
6350
6346
  let measured = measuring.map(m => {
6351
6347
  try {
@@ -6362,7 +6358,7 @@ class EditorView {
6362
6358
  updated = update;
6363
6359
  else
6364
6360
  updated.flags |= changed;
6365
- this.updateState = 2 /* Updating */;
6361
+ this.updateState = 2 /* UpdateState.Updating */;
6366
6362
  if (!update.empty) {
6367
6363
  this.updatePlugins(update);
6368
6364
  this.inputState.update(update);
@@ -6400,7 +6396,7 @@ class EditorView {
6400
6396
  }
6401
6397
  }
6402
6398
  finally {
6403
- this.updateState = 0 /* Idle */;
6399
+ this.updateState = 0 /* UpdateState.Idle */;
6404
6400
  this.measureScheduled = -1;
6405
6401
  }
6406
6402
  if (updated && !updated.empty)
@@ -6459,9 +6455,9 @@ class EditorView {
6459
6455
  styleMod.StyleModule.mount(this.root, this.styleModules.concat(baseTheme$1).reverse());
6460
6456
  }
6461
6457
  readMeasured() {
6462
- if (this.updateState == 2 /* Updating */)
6458
+ if (this.updateState == 2 /* UpdateState.Updating */)
6463
6459
  throw new Error("Reading the editor layout isn't allowed during an update");
6464
- if (this.updateState == 0 /* Idle */ && this.measureScheduled > -1)
6460
+ if (this.updateState == 0 /* UpdateState.Idle */ && this.measureScheduled > -1)
6465
6461
  this.measure(false);
6466
6462
  }
6467
6463
  /**
@@ -6474,7 +6470,7 @@ class EditorView {
6474
6470
  */
6475
6471
  requestMeasure(request) {
6476
6472
  if (this.measureScheduled < 0)
6477
- this.measureScheduled = requestAnimationFrame(() => this.measure());
6473
+ this.measureScheduled = this.win.requestAnimationFrame(() => this.measure());
6478
6474
  if (request) {
6479
6475
  if (request.key != null)
6480
6476
  for (let i = 0; i < this.measureRequests.length; i++) {
@@ -7349,7 +7345,7 @@ function measureRange(view, range) {
7349
7345
  return pieces(top).concat(between).concat(pieces(bottom));
7350
7346
  }
7351
7347
  function piece(left, top, right, bottom) {
7352
- return new Piece(left - base.left, top - base.top - 0.01 /* Epsilon */, right - left, bottom - top + 0.01 /* Epsilon */, "cm-selectionBackground");
7348
+ return new Piece(left - base.left, top - base.top - 0.01 /* C.Epsilon */, right - left, bottom - top + 0.01 /* C.Epsilon */, "cm-selectionBackground");
7353
7349
  }
7354
7350
  function pieces({ top, bottom, horizontal }) {
7355
7351
  let pieces = [];
@@ -8046,7 +8042,6 @@ const tooltipConfig = state.Facet.define({
8046
8042
  });
8047
8043
  const tooltipPlugin = ViewPlugin.fromClass(class {
8048
8044
  constructor(view) {
8049
- var _a;
8050
8045
  this.view = view;
8051
8046
  this.inView = true;
8052
8047
  this.lastTransaction = 0;
@@ -8064,7 +8059,7 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
8064
8059
  this.measureSoon();
8065
8060
  }, { threshold: [1] }) : null;
8066
8061
  this.observeIntersection();
8067
- (_a = view.dom.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener("resize", this.measureSoon = this.measureSoon.bind(this));
8062
+ view.win.addEventListener("resize", this.measureSoon = this.measureSoon.bind(this));
8068
8063
  this.maybeMeasure();
8069
8064
  }
8070
8065
  createContainer() {
@@ -8137,11 +8132,11 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
8137
8132
  return tooltipView;
8138
8133
  }
8139
8134
  destroy() {
8140
- var _a, _b;
8141
- (_a = this.view.dom.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.removeEventListener("resize", this.measureSoon);
8135
+ var _a;
8136
+ this.view.win.removeEventListener("resize", this.measureSoon);
8142
8137
  for (let { dom } of this.manager.tooltipViews)
8143
8138
  dom.remove();
8144
- (_b = this.intersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
8139
+ (_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
8145
8140
  clearTimeout(this.measureTimeout);
8146
8141
  }
8147
8142
  readMeasure() {
@@ -8172,12 +8167,12 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
8172
8167
  continue;
8173
8168
  }
8174
8169
  let arrow = tooltip.arrow ? tView.dom.querySelector(".cm-tooltip-arrow") : null;
8175
- let arrowHeight = arrow ? 7 /* Size */ : 0;
8170
+ let arrowHeight = arrow ? 7 /* Arrow.Size */ : 0;
8176
8171
  let width = size.right - size.left, height = size.bottom - size.top;
8177
8172
  let offset = tView.offset || noOffset, ltr = this.view.textDirection == exports.Direction.LTR;
8178
8173
  let left = size.width > space.right - space.left ? (ltr ? space.left : space.right - size.width)
8179
- : ltr ? Math.min(pos.left - (arrow ? 14 /* Offset */ : 0) + offset.x, space.right - width)
8180
- : Math.max(space.left, pos.left - width + (arrow ? 14 /* Offset */ : 0) - offset.x);
8174
+ : ltr ? Math.min(pos.left - (arrow ? 14 /* Arrow.Offset */ : 0) + offset.x, space.right - width)
8175
+ : Math.max(space.left, pos.left - width + (arrow ? 14 /* Arrow.Offset */ : 0) - offset.x);
8181
8176
  let above = !!tooltip.above;
8182
8177
  if (!tooltip.strictSide && (above
8183
8178
  ? pos.top - (size.bottom - size.top) - offset.y < space.top
@@ -8199,7 +8194,7 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
8199
8194
  dom.style.left = left + "px";
8200
8195
  }
8201
8196
  if (arrow)
8202
- arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Offset */ - 7 /* Size */)}px`;
8197
+ arrow.style.left = `${pos.left + (ltr ? offset.x : -offset.x) - (left + 14 /* Arrow.Offset */ - 7 /* Arrow.Size */)}px`;
8203
8198
  if (tView.overlap !== true)
8204
8199
  others.push({ left, top, right, bottom: top + height });
8205
8200
  dom.classList.toggle("cm-tooltip-above", above);
@@ -8241,8 +8236,8 @@ const baseTheme = EditorView.baseTheme({
8241
8236
  color: "white"
8242
8237
  },
8243
8238
  ".cm-tooltip-arrow": {
8244
- height: `${7 /* Size */}px`,
8245
- width: `${7 /* Size */ * 2}px`,
8239
+ height: `${7 /* Arrow.Size */}px`,
8240
+ width: `${7 /* Arrow.Size */ * 2}px`,
8246
8241
  position: "absolute",
8247
8242
  zIndex: -1,
8248
8243
  overflow: "hidden",
@@ -8251,26 +8246,26 @@ const baseTheme = EditorView.baseTheme({
8251
8246
  position: "absolute",
8252
8247
  width: 0,
8253
8248
  height: 0,
8254
- borderLeft: `${7 /* Size */}px solid transparent`,
8255
- borderRight: `${7 /* Size */}px solid transparent`,
8249
+ borderLeft: `${7 /* Arrow.Size */}px solid transparent`,
8250
+ borderRight: `${7 /* Arrow.Size */}px solid transparent`,
8256
8251
  },
8257
8252
  ".cm-tooltip-above &": {
8258
- bottom: `-${7 /* Size */}px`,
8253
+ bottom: `-${7 /* Arrow.Size */}px`,
8259
8254
  "&:before": {
8260
- borderTop: `${7 /* Size */}px solid #bbb`,
8255
+ borderTop: `${7 /* Arrow.Size */}px solid #bbb`,
8261
8256
  },
8262
8257
  "&:after": {
8263
- borderTop: `${7 /* Size */}px solid #f5f5f5`,
8258
+ borderTop: `${7 /* Arrow.Size */}px solid #f5f5f5`,
8264
8259
  bottom: "1px"
8265
8260
  }
8266
8261
  },
8267
8262
  ".cm-tooltip-below &": {
8268
- top: `-${7 /* Size */}px`,
8263
+ top: `-${7 /* Arrow.Size */}px`,
8269
8264
  "&:before": {
8270
- borderBottom: `${7 /* Size */}px solid #bbb`,
8265
+ borderBottom: `${7 /* Arrow.Size */}px solid #bbb`,
8271
8266
  },
8272
8267
  "&:after": {
8273
- borderBottom: `${7 /* Size */}px solid #f5f5f5`,
8268
+ borderBottom: `${7 /* Arrow.Size */}px solid #f5f5f5`,
8274
8269
  top: "1px"
8275
8270
  }
8276
8271
  },
@@ -8415,7 +8410,7 @@ class HoverPlugin {
8415
8410
  if (tooltip && !isInTooltip(this.lastMove.target) || this.pending) {
8416
8411
  let { pos } = tooltip || this.pending, end = (_a = tooltip === null || tooltip === void 0 ? void 0 : tooltip.end) !== null && _a !== void 0 ? _a : pos;
8417
8412
  if ((pos == end ? this.view.posAtCoords(this.lastMove) != pos
8418
- : !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /* MaxDist */))) {
8413
+ : !isOverRange(this.view, pos, end, event.clientX, event.clientY, 6 /* Hover.MaxDist */))) {
8419
8414
  this.view.dispatch({ effects: this.setHover.of(null) });
8420
8415
  this.pending = null;
8421
8416
  }
@@ -8497,7 +8492,7 @@ function hoverTooltip(source, options = {}) {
8497
8492
  });
8498
8493
  return [
8499
8494
  hoverState,
8500
- ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /* Time */)),
8495
+ ViewPlugin.define(view => new HoverPlugin(view, source, hoverState, setHover, options.hoverTime || 300 /* Hover.Time */)),
8501
8496
  showHoverTooltipHost
8502
8497
  ];
8503
8498
  }