@uiw/react-codemirror 4.21.13 → 4.21.14

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.
@@ -333,7 +333,7 @@ class SearchCursor {
333
333
  else
334
334
  this.matches.push(1, pos);
335
335
  }
336
- if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferPos))
336
+ if (match && this.test && !this.test(match.from, match.to, this.buffer, this.bufferStart))
337
337
  match = null;
338
338
  return match;
339
339
  }
@@ -521,7 +521,8 @@ function toCharEnd(text, pos) {
521
521
  }
522
522
 
523
523
  function createLineDialog(view) {
524
- let input = crelt("input", { class: "cm-textfield", name: "line" });
524
+ let line = String(view.state.doc.lineAt(view.state.selection.main.head).number);
525
+ let input = crelt("input", { class: "cm-textfield", name: "line", value: line });
525
526
  let dom = crelt("form", {
526
527
  class: "cm-gotoLine",
527
528
  onkeydown: (event) => {
@@ -597,7 +598,7 @@ const gotoLine = view => {
597
598
  panel = (0,view_.getPanel)(view, createLineDialog);
598
599
  }
599
600
  if (panel)
600
- panel.dom.querySelector("input").focus();
601
+ panel.dom.querySelector("input").select();
601
602
  return true;
602
603
  };
603
604
  const baseTheme$1 = /*@__PURE__*/view_.EditorView.baseTheme({
@@ -1608,7 +1609,7 @@ function insertCompletionText(state, text, from, to) {
1608
1609
  changes: { from: range.from + fromOff, to: to == main.from ? range.to : range.from + toOff, insert: text },
1609
1610
  range: state_.EditorSelection.cursor(range.from + fromOff + text.length)
1610
1611
  };
1611
- })), { userEvent: "input.complete" });
1612
+ })), { scrollIntoView: true, userEvent: "input.complete" });
1612
1613
  }
1613
1614
  const SourceCache = /*@__PURE__*/new WeakMap();
1614
1615
  function asSource(source) {
@@ -1660,7 +1661,7 @@ class FuzzyMatcher {
1660
1661
  // is. See `Penalty` above.
1661
1662
  match(word) {
1662
1663
  if (this.pattern.length == 0)
1663
- return this.ret(-100 /* NotFull */, []);
1664
+ return this.ret(-100 /* Penalty.NotFull */, []);
1664
1665
  if (word.length < this.pattern.length)
1665
1666
  return false;
1666
1667
  let { chars, folded, any, precise, byWord } = this;
@@ -1668,17 +1669,17 @@ class FuzzyMatcher {
1668
1669
  // at the start
1669
1670
  if (chars.length == 1) {
1670
1671
  let first = (0,state_.codePointAt)(word, 0), firstSize = (0,state_.codePointSize)(first);
1671
- let score = firstSize == word.length ? 0 : -100 /* NotFull */;
1672
+ let score = firstSize == word.length ? 0 : -100 /* Penalty.NotFull */;
1672
1673
  if (first == chars[0]) ;
1673
1674
  else if (first == folded[0])
1674
- score += -200 /* CaseFold */;
1675
+ score += -200 /* Penalty.CaseFold */;
1675
1676
  else
1676
1677
  return false;
1677
1678
  return this.ret(score, [0, firstSize]);
1678
1679
  }
1679
1680
  let direct = word.indexOf(this.pattern);
1680
1681
  if (direct == 0)
1681
- return this.ret(word.length == this.pattern.length ? 0 : -100 /* NotFull */, [0, this.pattern.length]);
1682
+ return this.ret(word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */, [0, this.pattern.length]);
1682
1683
  let len = chars.length, anyTo = 0;
1683
1684
  if (direct < 0) {
1684
1685
  for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len;) {
@@ -1702,7 +1703,7 @@ class FuzzyMatcher {
1702
1703
  let adjacentTo = 0, adjacentStart = -1, adjacentEnd = -1;
1703
1704
  let hasLower = /[a-z]/.test(word), wordAdjacent = true;
1704
1705
  // Go over the option's text, scanning for the various kinds of matches
1705
- for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /* NonWord */; i < e && byWordTo < len;) {
1706
+ for (let i = 0, e = Math.min(word.length, 200), prevType = 0 /* Tp.NonWord */; i < e && byWordTo < len;) {
1706
1707
  let next = (0,state_.codePointAt)(word, i);
1707
1708
  if (direct < 0) {
1708
1709
  if (preciseTo < len && next == chars[preciseTo])
@@ -1720,9 +1721,9 @@ class FuzzyMatcher {
1720
1721
  }
1721
1722
  }
1722
1723
  let ch, type = next < 0xff
1723
- ? (next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /* Lower */ : next >= 65 && next <= 90 ? 1 /* Upper */ : 0 /* NonWord */)
1724
- : ((ch = (0,state_.fromCodePoint)(next)) != ch.toLowerCase() ? 1 /* Upper */ : ch != ch.toUpperCase() ? 2 /* Lower */ : 0 /* NonWord */);
1725
- if (!i || type == 1 /* Upper */ && hasLower || prevType == 0 /* NonWord */ && type != 0 /* NonWord */) {
1724
+ ? (next >= 48 && next <= 57 || next >= 97 && next <= 122 ? 2 /* Tp.Lower */ : next >= 65 && next <= 90 ? 1 /* Tp.Upper */ : 0 /* Tp.NonWord */)
1725
+ : ((ch = (0,state_.fromCodePoint)(next)) != ch.toLowerCase() ? 1 /* Tp.Upper */ : ch != ch.toUpperCase() ? 2 /* Tp.Lower */ : 0 /* Tp.NonWord */);
1726
+ if (!i || type == 1 /* Tp.Upper */ && hasLower || prevType == 0 /* Tp.NonWord */ && type != 0 /* Tp.NonWord */) {
1726
1727
  if (chars[byWordTo] == next || (folded[byWordTo] == next && (byWordFolded = true)))
1727
1728
  byWord[byWordTo++] = i;
1728
1729
  else if (byWord.length)
@@ -1732,18 +1733,18 @@ class FuzzyMatcher {
1732
1733
  i += (0,state_.codePointSize)(next);
1733
1734
  }
1734
1735
  if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
1735
- return this.result(-100 /* ByWord */ + (byWordFolded ? -200 /* CaseFold */ : 0), byWord, word);
1736
+ return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0), byWord, word);
1736
1737
  if (adjacentTo == len && adjacentStart == 0)
1737
- return this.ret(-200 /* CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* NotFull */), [0, adjacentEnd]);
1738
+ return this.ret(-200 /* Penalty.CaseFold */ - word.length + (adjacentEnd == word.length ? 0 : -100 /* Penalty.NotFull */), [0, adjacentEnd]);
1738
1739
  if (direct > -1)
1739
- return this.ret(-700 /* NotStart */ - word.length, [direct, direct + this.pattern.length]);
1740
+ return this.ret(-700 /* Penalty.NotStart */ - word.length, [direct, direct + this.pattern.length]);
1740
1741
  if (adjacentTo == len)
1741
- return this.ret(-200 /* CaseFold */ + -700 /* NotStart */ - word.length, [adjacentStart, adjacentEnd]);
1742
+ return this.ret(-200 /* Penalty.CaseFold */ + -700 /* Penalty.NotStart */ - word.length, [adjacentStart, adjacentEnd]);
1742
1743
  if (byWordTo == len)
1743
- return this.result(-100 /* ByWord */ + (byWordFolded ? -200 /* CaseFold */ : 0) + -700 /* NotStart */ +
1744
- (wordAdjacent ? 0 : -1100 /* Gap */), byWord, word);
1744
+ return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0) + -700 /* Penalty.NotStart */ +
1745
+ (wordAdjacent ? 0 : -1100 /* Penalty.Gap */), byWord, word);
1745
1746
  return chars.length == 2 ? false
1746
- : this.result((any[0] ? -700 /* NotStart */ : 0) + -200 /* CaseFold */ + -1100 /* Gap */, any, word);
1747
+ : this.result((any[0] ? -700 /* Penalty.NotStart */ : 0) + -200 /* Penalty.CaseFold */ + -1100 /* Penalty.Gap */, any, word);
1747
1748
  }
1748
1749
  result(score, positions, word) {
1749
1750
  let result = [], i = 0;
@@ -1790,7 +1791,7 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
1790
1791
  function joinClass(a, b) {
1791
1792
  return a ? b ? a + " " + b : a : b;
1792
1793
  }
1793
- function defaultPositionInfo(view, list, option, info, space) {
1794
+ function defaultPositionInfo(view, list, option, info, space, tooltip) {
1794
1795
  let rtl = view.textDirection == view_.Direction.RTL, left = rtl, narrow = false;
1795
1796
  let side = "top", offset, maxWidth;
1796
1797
  let spaceLeft = list.left - space.left, spaceRight = space.right - list.right;
@@ -1801,11 +1802,11 @@ function defaultPositionInfo(view, list, option, info, space) {
1801
1802
  left = true;
1802
1803
  if (infoWidth <= (left ? spaceLeft : spaceRight)) {
1803
1804
  offset = Math.max(space.top, Math.min(option.top, space.bottom - infoHeight)) - list.top;
1804
- maxWidth = Math.min(400 /* Width */, left ? spaceLeft : spaceRight);
1805
+ maxWidth = Math.min(400 /* Info.Width */, left ? spaceLeft : spaceRight);
1805
1806
  }
1806
1807
  else {
1807
1808
  narrow = true;
1808
- maxWidth = Math.min(400 /* Width */, (rtl ? list.right : space.right - list.left) - 30 /* Margin */);
1809
+ maxWidth = Math.min(400 /* Info.Width */, (rtl ? list.right : space.right - list.left) - 30 /* Info.Margin */);
1809
1810
  let spaceBelow = space.bottom - list.bottom;
1810
1811
  if (spaceBelow >= infoHeight || spaceBelow > list.top) { // Below the completion
1811
1812
  offset = option.bottom - list.top;
@@ -1815,8 +1816,10 @@ function defaultPositionInfo(view, list, option, info, space) {
1815
1816
  offset = list.bottom - option.top;
1816
1817
  }
1817
1818
  }
1819
+ let scaleY = (list.bottom - list.top) / tooltip.offsetHeight;
1820
+ let scaleX = (list.right - list.left) / tooltip.offsetWidth;
1818
1821
  return {
1819
- style: `${side}: ${offset}px; max-width: ${maxWidth}px`,
1822
+ style: `${side}: ${offset / scaleY}px; max-width: ${maxWidth / scaleX}px`,
1820
1823
  class: "cm-completionInfo-" + (narrow ? (rtl ? "left-narrow" : "right-narrow") : left ? "left" : "right")
1821
1824
  };
1822
1825
  }
@@ -2036,7 +2039,7 @@ class CompletionTooltip {
2036
2039
  if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 ||
2037
2040
  selRect.bottom < Math.max(space.top, listRect.top) + 10)
2038
2041
  return null;
2039
- return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space);
2042
+ return this.view.state.facet(completionConfig).positionInfo(this.view, listRect, selRect, infoRect, space, this.dom);
2040
2043
  }
2041
2044
  placeInfo(pos) {
2042
2045
  if (this.info) {
@@ -2110,10 +2113,11 @@ function completionTooltip(stateField, applyCompletion) {
2110
2113
  function scrollIntoView(container, element) {
2111
2114
  let parent = container.getBoundingClientRect();
2112
2115
  let self = element.getBoundingClientRect();
2116
+ let scaleY = parent.height / container.offsetHeight;
2113
2117
  if (self.top < parent.top)
2114
- container.scrollTop -= parent.top - self.top;
2118
+ container.scrollTop -= (parent.top - self.top) / scaleY;
2115
2119
  else if (self.bottom > parent.bottom)
2116
- container.scrollTop += self.bottom - parent.bottom;
2120
+ container.scrollTop += (self.bottom - parent.bottom) / scaleY;
2117
2121
  }
2118
2122
 
2119
2123
  // Used to pick a preferred option when two options with the same
@@ -2196,7 +2200,7 @@ class CompletionDialog {
2196
2200
  static build(active, state, id, prev, conf) {
2197
2201
  let options = sortOptions(active, state);
2198
2202
  if (!options.length) {
2199
- return prev && active.some(a => a.state == 1 /* Pending */) ?
2203
+ return prev && active.some(a => a.state == 1 /* State.Pending */) ?
2200
2204
  new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
2201
2205
  }
2202
2206
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
@@ -2233,7 +2237,7 @@ class CompletionState {
2233
2237
  state.languageDataAt("autocomplete", cur(state)).map(asSource);
2234
2238
  let active = sources.map(source => {
2235
2239
  let value = this.active.find(s => s.source == source) ||
2236
- new ActiveSource(source, this.active.some(a => a.state != 0 /* Inactive */) ? 1 /* Pending */ : 0 /* Inactive */);
2240
+ new ActiveSource(source, this.active.some(a => a.state != 0 /* State.Inactive */) ? 1 /* State.Pending */ : 0 /* State.Inactive */);
2237
2241
  return value.update(tr, conf);
2238
2242
  });
2239
2243
  if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
@@ -2244,10 +2248,10 @@ class CompletionState {
2244
2248
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
2245
2249
  !sameResults(active, this.active))
2246
2250
  open = CompletionDialog.build(active, state, this.id, open, conf);
2247
- else if (open && open.disabled && !active.some(a => a.state == 1 /* Pending */))
2251
+ else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
2248
2252
  open = null;
2249
- if (!open && active.every(a => a.state != 1 /* Pending */) && active.some(a => a.hasResult()))
2250
- active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* Inactive */) : a);
2253
+ if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
2254
+ active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
2251
2255
  for (let effect of tr.effects)
2252
2256
  if (effect.is(setSelectedEffect))
2253
2257
  open = open && open.setSelected(effect.value, this.id);
@@ -2301,13 +2305,13 @@ class ActiveSource {
2301
2305
  value = value.handleUserEvent(tr, event, conf);
2302
2306
  else if (tr.docChanged)
2303
2307
  value = value.handleChange(tr);
2304
- else if (tr.selection && value.state != 0 /* Inactive */)
2305
- value = new ActiveSource(value.source, 0 /* Inactive */);
2308
+ else if (tr.selection && value.state != 0 /* State.Inactive */)
2309
+ value = new ActiveSource(value.source, 0 /* State.Inactive */);
2306
2310
  for (let effect of tr.effects) {
2307
2311
  if (effect.is(startCompletionEffect))
2308
- value = new ActiveSource(value.source, 1 /* Pending */, effect.value ? cur(tr.state) : -1);
2312
+ value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
2309
2313
  else if (effect.is(closeCompletionEffect))
2310
- value = new ActiveSource(value.source, 0 /* Inactive */);
2314
+ value = new ActiveSource(value.source, 0 /* State.Inactive */);
2311
2315
  else if (effect.is(setActiveEffect))
2312
2316
  for (let active of effect.value)
2313
2317
  if (active.source == value.source)
@@ -2316,10 +2320,10 @@ class ActiveSource {
2316
2320
  return value;
2317
2321
  }
2318
2322
  handleUserEvent(tr, type, conf) {
2319
- return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* Pending */);
2323
+ return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(this.source, 1 /* State.Pending */);
2320
2324
  }
2321
2325
  handleChange(tr) {
2322
- return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* Inactive */) : this.map(tr.changes);
2326
+ return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
2323
2327
  }
2324
2328
  map(changes) {
2325
2329
  return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
@@ -2327,7 +2331,7 @@ class ActiveSource {
2327
2331
  }
2328
2332
  class ActiveResult extends ActiveSource {
2329
2333
  constructor(source, explicitPos, result, from, to) {
2330
- super(source, 2 /* Result */, explicitPos);
2334
+ super(source, 2 /* State.Result */, explicitPos);
2331
2335
  this.result = result;
2332
2336
  this.from = from;
2333
2337
  this.to = to;
@@ -2340,17 +2344,17 @@ class ActiveResult extends ActiveSource {
2340
2344
  if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
2341
2345
  pos > to ||
2342
2346
  type == "delete" && cur(tr.startState) == this.from)
2343
- return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* Pending */ : 0 /* Inactive */);
2347
+ return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */);
2344
2348
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated;
2345
2349
  if (checkValid(this.result.validFor, tr.state, from, to))
2346
2350
  return new ActiveResult(this.source, explicitPos, this.result, from, to);
2347
2351
  if (this.result.update &&
2348
2352
  (updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
2349
2353
  return new ActiveResult(this.source, explicitPos, updated, updated.from, (_a = updated.to) !== null && _a !== void 0 ? _a : cur(tr.state));
2350
- return new ActiveSource(this.source, 1 /* Pending */, explicitPos);
2354
+ return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
2351
2355
  }
2352
2356
  handleChange(tr) {
2353
- return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* Inactive */) : this.map(tr.changes);
2357
+ return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
2354
2358
  }
2355
2359
  map(mapping) {
2356
2360
  return mapping.empty ? this :
@@ -2436,7 +2440,7 @@ Close the currently active completion.
2436
2440
  */
2437
2441
  const closeCompletion = (view) => {
2438
2442
  let cState = view.state.field(completionState, false);
2439
- if (!cState || !cState.active.some(a => a.state != 0 /* Inactive */))
2443
+ if (!cState || !cState.active.some(a => a.state != 0 /* State.Inactive */))
2440
2444
  return false;
2441
2445
  view.dispatch({ effects: closeCompletionEffect.of(null) });
2442
2446
  return true;
@@ -2459,9 +2463,9 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2459
2463
  this.debounceUpdate = -1;
2460
2464
  this.running = [];
2461
2465
  this.debounceAccept = -1;
2462
- this.composing = 0 /* None */;
2466
+ this.composing = 0 /* CompositionState.None */;
2463
2467
  for (let active of view.state.field(completionState).active)
2464
- if (active.state == 1 /* Pending */)
2468
+ if (active.state == 1 /* State.Pending */)
2465
2469
  this.startQuery(active);
2466
2470
  }
2467
2471
  update(update) {
@@ -2492,21 +2496,21 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2492
2496
  }
2493
2497
  if (this.debounceUpdate > -1)
2494
2498
  clearTimeout(this.debounceUpdate);
2495
- this.debounceUpdate = cState.active.some(a => a.state == 1 /* Pending */ && !this.running.some(q => q.active.source == a.source))
2499
+ this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
2496
2500
  ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
2497
- if (this.composing != 0 /* None */)
2501
+ if (this.composing != 0 /* CompositionState.None */)
2498
2502
  for (let tr of update.transactions) {
2499
2503
  if (getUserEvent(tr) == "input")
2500
- this.composing = 2 /* Changed */;
2501
- else if (this.composing == 2 /* Changed */ && tr.selection)
2502
- this.composing = 3 /* ChangedAndMoved */;
2504
+ this.composing = 2 /* CompositionState.Changed */;
2505
+ else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
2506
+ this.composing = 3 /* CompositionState.ChangedAndMoved */;
2503
2507
  }
2504
2508
  }
2505
2509
  startUpdate() {
2506
2510
  this.debounceUpdate = -1;
2507
2511
  let { state } = this.view, cState = state.field(completionState);
2508
2512
  for (let active of cState.active) {
2509
- if (active.state == 1 /* Pending */ && !this.running.some(r => r.active.source == active.source))
2513
+ if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source))
2510
2514
  this.startQuery(active);
2511
2515
  }
2512
2516
  }
@@ -2557,14 +2561,14 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2557
2561
  }
2558
2562
  }
2559
2563
  let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
2560
- if (current && current.state == 1 /* Pending */) {
2564
+ if (current && current.state == 1 /* State.Pending */) {
2561
2565
  if (query.done == null) {
2562
2566
  // Explicitly failed. Should clear the pending status if it
2563
2567
  // hasn't been re-set in the meantime.
2564
- let active = new ActiveSource(query.active.source, 0 /* Inactive */);
2568
+ let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
2565
2569
  for (let tr of query.updates)
2566
2570
  active = active.update(tr, conf);
2567
- if (active.state != 1 /* Pending */)
2571
+ if (active.state != 1 /* State.Pending */)
2568
2572
  updated.push(active);
2569
2573
  }
2570
2574
  else {
@@ -2587,15 +2591,15 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2587
2591
  }
2588
2592
  },
2589
2593
  compositionstart() {
2590
- this.composing = 1 /* Started */;
2594
+ this.composing = 1 /* CompositionState.Started */;
2591
2595
  },
2592
2596
  compositionend() {
2593
- if (this.composing == 3 /* ChangedAndMoved */) {
2597
+ if (this.composing == 3 /* CompositionState.ChangedAndMoved */) {
2594
2598
  // Safari fires compositionend events synchronously, possibly
2595
2599
  // from inside an update, so dispatch asynchronously to avoid reentrancy
2596
2600
  setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
2597
2601
  }
2598
- this.composing = 0 /* None */;
2602
+ this.composing = 0 /* CompositionState.None */;
2599
2603
  }
2600
2604
  }
2601
2605
  });
@@ -2655,13 +2659,13 @@ const dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
2655
2659
  position: "absolute",
2656
2660
  padding: "3px 9px",
2657
2661
  width: "max-content",
2658
- maxWidth: `${400 /* Width */}px`,
2662
+ maxWidth: `${400 /* Info.Width */}px`,
2659
2663
  boxSizing: "border-box"
2660
2664
  },
2661
2665
  ".cm-completionInfo.cm-completionInfo-left": { right: "100%" },
2662
2666
  ".cm-completionInfo.cm-completionInfo-right": { left: "100%" },
2663
- ".cm-completionInfo.cm-completionInfo-left-narrow": { right: `${30 /* Margin */}px` },
2664
- ".cm-completionInfo.cm-completionInfo-right-narrow": { left: `${30 /* Margin */}px` },
2667
+ ".cm-completionInfo.cm-completionInfo-left-narrow": { right: `${30 /* Info.Margin */}px` },
2668
+ ".cm-completionInfo.cm-completionInfo-right-narrow": { left: `${30 /* Info.Margin */}px` },
2665
2669
  "&light .cm-snippetField": { backgroundColor: "#00000022" },
2666
2670
  "&dark .cm-snippetField": { backgroundColor: "#ffffff22" },
2667
2671
  ".cm-snippetFieldPosition": {
@@ -2912,7 +2916,8 @@ function moveField(dir) {
2912
2916
  let next = active.active + dir, last = dir > 0 && !active.ranges.some(r => r.field == next + dir);
2913
2917
  dispatch(state.update({
2914
2918
  selection: fieldSelection(active.ranges, next),
2915
- effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next))
2919
+ effects: setActive.of(last ? null : new ActiveSnippet(active.ranges, next)),
2920
+ scrollIntoView: true
2916
2921
  }));
2917
2922
  return true;
2918
2923
  };
@@ -2984,7 +2989,9 @@ const snippetPointerHandler = /*@__PURE__*/view_.EditorView.domEventHandlers({
2984
2989
  return false;
2985
2990
  view.dispatch({
2986
2991
  selection: fieldSelection(active.ranges, match.field),
2987
- effects: setActive.of(active.ranges.some(r => r.field > match.field) ? new ActiveSnippet(active.ranges, match.field) : null)
2992
+ effects: setActive.of(active.ranges.some(r => r.field > match.field)
2993
+ ? new ActiveSnippet(active.ranges, match.field) : null),
2994
+ scrollIntoView: true
2988
2995
  });
2989
2996
  return true;
2990
2997
  }
@@ -3014,7 +3021,7 @@ function storeWords(doc, wordRE, result, seen, ignoreAt) {
3014
3021
  if (!seen[m[0]] && pos + m.index != ignoreAt) {
3015
3022
  result.push({ type: "text", label: m[0] });
3016
3023
  seen[m[0]] = true;
3017
- if (result.length >= 2000 /* MaxList */)
3024
+ if (result.length >= 2000 /* C.MaxList */)
3018
3025
  return;
3019
3026
  }
3020
3027
  }
@@ -3022,7 +3029,7 @@ function storeWords(doc, wordRE, result, seen, ignoreAt) {
3022
3029
  }
3023
3030
  }
3024
3031
  function collectWords(doc, cache, wordRE, to, ignoreAt) {
3025
- let big = doc.length >= 1000 /* MinCacheLen */;
3032
+ let big = doc.length >= 1000 /* C.MinCacheLen */;
3026
3033
  let cached = big && cache.get(doc);
3027
3034
  if (cached)
3028
3035
  return cached;
@@ -3030,7 +3037,7 @@ function collectWords(doc, cache, wordRE, to, ignoreAt) {
3030
3037
  if (doc.children) {
3031
3038
  let pos = 0;
3032
3039
  for (let ch of doc.children) {
3033
- if (ch.length >= 1000 /* MinCacheLen */) {
3040
+ if (ch.length >= 1000 /* C.MinCacheLen */) {
3034
3041
  for (let c of collectWords(ch, cache, wordRE, to - pos, ignoreAt - pos)) {
3035
3042
  if (!seen[c.label]) {
3036
3043
  seen[c.label] = true;
@@ -3047,7 +3054,7 @@ function collectWords(doc, cache, wordRE, to, ignoreAt) {
3047
3054
  else {
3048
3055
  storeWords(doc, wordRE, result, seen, ignoreAt);
3049
3056
  }
3050
- if (big && result.length < 2000 /* MaxList */)
3057
+ if (big && result.length < 2000 /* C.MaxList */)
3051
3058
  cache.set(doc, result);
3052
3059
  return result;
3053
3060
  }
@@ -3063,7 +3070,7 @@ const completeAnyWord = context => {
3063
3070
  if (!token && !context.explicit)
3064
3071
  return null;
3065
3072
  let from = token ? token.from : context.pos;
3066
- let options = collectWords(context.state.doc, wordCache(wordChars), re, 50000 /* Range */, from);
3073
+ let options = collectWords(context.state.doc, wordCache(wordChars), re, 50000 /* C.Range */, from);
3067
3074
  return { from, options, validFor: mapRE(re, s => "^" + s) };
3068
3075
  };
3069
3076
 
@@ -3355,8 +3362,8 @@ returns `null`.
3355
3362
  */
3356
3363
  function completionStatus(state) {
3357
3364
  let cState = state.field(completionState, false);
3358
- return cState && cState.active.some(a => a.state == 1 /* Pending */) ? "pending"
3359
- : cState && cState.active.some(a => a.state != 0 /* Inactive */) ? "active" : null;
3365
+ return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
3366
+ : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
3360
3367
  }
3361
3368
  const completionArrayCache = /*@__PURE__*/new WeakMap;
3362
3369
  /**
@@ -3867,10 +3874,11 @@ class LintPanel {
3867
3874
  key: this,
3868
3875
  read: () => ({ sel: newSelectedItem.dom.getBoundingClientRect(), panel: this.list.getBoundingClientRect() }),
3869
3876
  write: ({ sel, panel }) => {
3877
+ let scaleY = panel.height / this.list.offsetHeight;
3870
3878
  if (sel.top < panel.top)
3871
- this.list.scrollTop -= panel.top - sel.top;
3879
+ this.list.scrollTop -= (panel.top - sel.top) / scaleY;
3872
3880
  else if (sel.bottom > panel.bottom)
3873
- this.list.scrollTop += sel.bottom - panel.bottom;
3881
+ this.list.scrollTop += (sel.bottom - panel.bottom) / scaleY;
3874
3882
  }
3875
3883
  });
3876
3884
  }
@@ -4237,6 +4245,9 @@ var basicSetup = function basicSetup(options) {
4237
4245
  if (options === void 0) {
4238
4246
  options = {};
4239
4247
  }
4248
+ var {
4249
+ crosshairCursor: initCrosshairCursor = false
4250
+ } = options;
4240
4251
  var keymaps = [];
4241
4252
  if (options.closeBracketsKeymap !== false) {
4242
4253
  keymaps = keymaps.concat(closeBracketsKeymap);
@@ -4276,7 +4287,7 @@ var basicSetup = function basicSetup(options) {
4276
4287
  if (options.closeBrackets !== false) extensions.push(closeBrackets());
4277
4288
  if (options.autocompletion !== false) extensions.push(autocompletion());
4278
4289
  if (options.rectangularSelection !== false) extensions.push((0,view_.rectangularSelection)());
4279
- if (options.crosshairCursor !== false) extensions.push((0,view_.crosshairCursor)());
4290
+ if (initCrosshairCursor !== false) extensions.push((0,view_.crosshairCursor)());
4280
4291
  if (options.highlightActiveLine !== false) extensions.push((0,view_.highlightActiveLine)());
4281
4292
  if (options.highlightSelectionMatches !== false) extensions.push(highlightSelectionMatches());
4282
4293
  if (options.tabSize && typeof options.tabSize === 'number') extensions.push(language_dist/* indentUnit */.c.of(' '.repeat(options.tabSize)));
@@ -7723,14 +7734,14 @@ class LanguageState {
7723
7734
  // state updates with parse work beyond the viewport.
7724
7735
  let upto = this.context.treeLen == tr.startState.doc.length ? undefined
7725
7736
  : Math.max(tr.changes.mapPos(this.context.treeLen), newCx.viewport.to);
7726
- if (!newCx.work(20 /* Apply */, upto))
7737
+ if (!newCx.work(20 /* Work.Apply */, upto))
7727
7738
  newCx.takeTree();
7728
7739
  return new LanguageState(newCx);
7729
7740
  }
7730
7741
  static init(state) {
7731
- let vpTo = Math.min(3000 /* InitViewport */, state.doc.length);
7742
+ let vpTo = Math.min(3000 /* Work.InitViewport */, state.doc.length);
7732
7743
  let parseState = ParseContext.create(state.facet(language).parser, state, { from: 0, to: vpTo });
7733
- if (!parseState.work(20 /* Apply */, vpTo))
7744
+ if (!parseState.work(20 /* Work.Apply */, vpTo))
7734
7745
  parseState.takeTree();
7735
7746
  return new LanguageState(parseState);
7736
7747
  }
@@ -7747,14 +7758,14 @@ Language.state = /*@__PURE__*/state_.StateField.define({
7747
7758
  }
7748
7759
  });
7749
7760
  let requestIdle = (callback) => {
7750
- let timeout = setTimeout(() => callback(), 500 /* MaxPause */);
7761
+ let timeout = setTimeout(() => callback(), 500 /* Work.MaxPause */);
7751
7762
  return () => clearTimeout(timeout);
7752
7763
  };
7753
7764
  if (typeof requestIdleCallback != "undefined")
7754
7765
  requestIdle = (callback) => {
7755
7766
  let idle = -1, timeout = setTimeout(() => {
7756
- idle = requestIdleCallback(callback, { timeout: 500 /* MaxPause */ - 100 /* MinPause */ });
7757
- }, 100 /* MinPause */);
7767
+ idle = requestIdleCallback(callback, { timeout: 500 /* Work.MaxPause */ - 100 /* Work.MinPause */ });
7768
+ }, 100 /* Work.MinPause */);
7758
7769
  return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
7759
7770
  };
7760
7771
  const isInputPending = typeof navigator != "undefined" && ((_a = navigator.scheduling) === null || _a === void 0 ? void 0 : _a.isInputPending)
@@ -7775,9 +7786,9 @@ const parseWorker = /*@__PURE__*/view_.ViewPlugin.fromClass(class ParseWorker {
7775
7786
  let cx = this.view.state.field(Language.state).context;
7776
7787
  if (cx.updateViewport(update.view.viewport) || this.view.viewport.to > cx.treeLen)
7777
7788
  this.scheduleWork();
7778
- if (update.docChanged) {
7789
+ if (update.docChanged || update.selectionSet) {
7779
7790
  if (this.view.hasFocus)
7780
- this.chunkBudget += 50 /* ChangeBonus */;
7791
+ this.chunkBudget += 50 /* Work.ChangeBonus */;
7781
7792
  this.scheduleWork();
7782
7793
  }
7783
7794
  this.checkAsyncSchedule(cx);
@@ -7793,19 +7804,19 @@ const parseWorker = /*@__PURE__*/view_.ViewPlugin.fromClass(class ParseWorker {
7793
7804
  this.working = null;
7794
7805
  let now = Date.now();
7795
7806
  if (this.chunkEnd < now && (this.chunkEnd < 0 || this.view.hasFocus)) { // Start a new chunk
7796
- this.chunkEnd = now + 30000 /* ChunkTime */;
7797
- this.chunkBudget = 3000 /* ChunkBudget */;
7807
+ this.chunkEnd = now + 30000 /* Work.ChunkTime */;
7808
+ this.chunkBudget = 3000 /* Work.ChunkBudget */;
7798
7809
  }
7799
7810
  if (this.chunkBudget <= 0)
7800
7811
  return; // No more budget
7801
7812
  let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
7802
- if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* MaxParseAhead */))
7813
+ if (field.tree == field.context.tree && field.context.isDone(vpTo + 100000 /* Work.MaxParseAhead */))
7803
7814
  return;
7804
- let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Slice */, deadline && !isInputPending ? Math.max(25 /* MinSlice */, deadline.timeRemaining() - 5) : 1e9);
7815
+ let endTime = Date.now() + Math.min(this.chunkBudget, 100 /* Work.Slice */, deadline && !isInputPending ? Math.max(25 /* Work.MinSlice */, deadline.timeRemaining() - 5) : 1e9);
7805
7816
  let viewportFirst = field.context.treeLen < vpTo && state.doc.length > vpTo + 1000;
7806
7817
  let done = field.context.work(() => {
7807
7818
  return isInputPending && isInputPending() || Date.now() > endTime;
7808
- }, vpTo + (viewportFirst ? 0 : 100000 /* MaxParseAhead */));
7819
+ }, vpTo + (viewportFirst ? 0 : 100000 /* Work.MaxParseAhead */));
7809
7820
  this.chunkBudget -= Date.now() - now;
7810
7821
  if (done || this.chunkBudget <= 0) {
7811
7822
  field.context.takeTree();
@@ -8181,7 +8192,24 @@ indicates that no definitive indentation can be determined.
8181
8192
  const indentNodeProp = /*@__PURE__*/new dist/* NodeProp */.md();
8182
8193
  // Compute the indentation for a given position from the syntax tree.
8183
8194
  function syntaxIndentation(cx, ast, pos) {
8184
- return indentFrom(ast.resolveInner(pos).enterUnfinishedNodesBefore(pos), pos, cx);
8195
+ let stack = ast.resolveStack(pos);
8196
+ let inner = stack.node.enterUnfinishedNodesBefore(pos);
8197
+ if (inner != stack.node) {
8198
+ let add = [];
8199
+ for (let cur = inner; cur != stack.node; cur = cur.parent)
8200
+ add.push(cur);
8201
+ for (let i = add.length - 1; i >= 0; i--)
8202
+ stack = { node: add[i], next: stack };
8203
+ }
8204
+ return indentFor(stack, cx, pos);
8205
+ }
8206
+ function indentFor(stack, cx, pos) {
8207
+ for (let cur = stack; cur; cur = cur.next) {
8208
+ let strategy = indentStrategy(cur.node);
8209
+ if (strategy)
8210
+ return strategy(TreeIndentContext.create(cx, pos, cur));
8211
+ }
8212
+ return 0;
8185
8213
  }
8186
8214
  function ignoreClosed(cx) {
8187
8215
  return cx.pos == cx.options.simulateBreak && cx.options.simulateDoubleBreak;
@@ -8197,14 +8225,6 @@ function indentStrategy(tree) {
8197
8225
  }
8198
8226
  return tree.parent == null ? topIndent : null;
8199
8227
  }
8200
- function indentFrom(node, pos, base) {
8201
- for (; node; node = node.parent) {
8202
- let strategy = indentStrategy(node);
8203
- if (strategy)
8204
- return strategy(TreeIndentContext.create(base, pos, node));
8205
- }
8206
- return null;
8207
- }
8208
8228
  function topIndent() { return 0; }
8209
8229
  /**
8210
8230
  Objects of this type provide context information and helper
@@ -8217,20 +8237,24 @@ class TreeIndentContext extends IndentContext {
8217
8237
  */
8218
8238
  pos,
8219
8239
  /**
8220
- The syntax tree node to which the indentation strategy
8221
- applies.
8240
+ @internal
8222
8241
  */
8223
- node) {
8242
+ context) {
8224
8243
  super(base.state, base.options);
8225
8244
  this.base = base;
8226
8245
  this.pos = pos;
8227
- this.node = node;
8246
+ this.context = context;
8228
8247
  }
8229
8248
  /**
8249
+ The syntax tree node to which the indentation strategy
8250
+ applies.
8251
+ */
8252
+ get node() { return this.context.node; }
8253
+ /**
8230
8254
  @internal
8231
8255
  */
8232
- static create(base, pos, node) {
8233
- return new TreeIndentContext(base, pos, node);
8256
+ static create(base, pos, context) {
8257
+ return new TreeIndentContext(base, pos, context);
8234
8258
  }
8235
8259
  /**
8236
8260
  Get the text directly after `this.pos`, either the entire line
@@ -8271,8 +8295,7 @@ class TreeIndentContext extends IndentContext {
8271
8295
  and return the result of that.
8272
8296
  */
8273
8297
  continue() {
8274
- let parent = this.node.parent;
8275
- return parent ? indentFrom(parent, this.pos, this.base) : 0;
8298
+ return indentFor(this.context.next, this.base, this.pos);
8276
8299
  }
8277
8300
  }
8278
8301
  function isParent(parent, of) {
@@ -8414,9 +8437,10 @@ function syntaxFolding(state, start, end) {
8414
8437
  let tree = syntaxTree(state);
8415
8438
  if (tree.length < end)
8416
8439
  return null;
8417
- let inner = tree.resolveInner(end, 1);
8440
+ let stack = tree.resolveStack(end, 1);
8418
8441
  let found = null;
8419
- for (let cur = inner; cur; cur = cur.parent) {
8442
+ for (let iter = stack; iter; iter = iter.next) {
8443
+ let cur = iter.node;
8420
8444
  if (cur.to <= end || cur.from > end)
8421
8445
  continue;
8422
8446
  if (found && cur.from < start)
@@ -9407,7 +9431,7 @@ class StreamLanguage extends (/* unused pure expression or super */ null && (Lan
9407
9431
  state = this.streamParser.startState(cx.unit);
9408
9432
  statePos = 0;
9409
9433
  }
9410
- if (pos - statePos > 10000 /* MaxIndentScanDist */)
9434
+ if (pos - statePos > 10000 /* C.MaxIndentScanDist */)
9411
9435
  return null;
9412
9436
  while (statePos < pos) {
9413
9437
  let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
@@ -9489,7 +9513,7 @@ class Parse {
9489
9513
  this.chunks.push(tree.children[i]);
9490
9514
  this.chunkPos.push(tree.positions[i]);
9491
9515
  }
9492
- if (context && this.parsedPos < context.viewport.from - 100000 /* MaxDistanceBeforeViewport */) {
9516
+ if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */) {
9493
9517
  this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
9494
9518
  context.skipUntilInView(this.parsedPos, context.viewport.from);
9495
9519
  this.parsedPos = context.viewport.from;
@@ -9499,7 +9523,7 @@ class Parse {
9499
9523
  advance() {
9500
9524
  let context = ParseContext.get();
9501
9525
  let parseEnd = this.stoppedAt == null ? this.to : Math.min(this.to, this.stoppedAt);
9502
- let end = Math.min(parseEnd, this.chunkStart + 2048 /* ChunkSize */);
9526
+ let end = Math.min(parseEnd, this.chunkStart + 2048 /* C.ChunkSize */);
9503
9527
  if (context)
9504
9528
  end = Math.min(end, context.viewport.to);
9505
9529
  while (this.parsedPos < end)
@@ -9583,7 +9607,7 @@ class Parse {
9583
9607
  let token = readToken(streamParser.token, stream, this.state);
9584
9608
  if (token)
9585
9609
  offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, 4, offset);
9586
- if (stream.start > 10000 /* MaxLineLength */)
9610
+ if (stream.start > 10000 /* C.MaxLineLength */)
9587
9611
  break;
9588
9612
  }
9589
9613
  }
@@ -9599,7 +9623,7 @@ class Parse {
9599
9623
  length: this.parsedPos - this.chunkStart,
9600
9624
  nodeSet,
9601
9625
  topID: 0,
9602
- maxBufferLength: 2048 /* ChunkSize */,
9626
+ maxBufferLength: 2048 /* C.ChunkSize */,
9603
9627
  reused: this.chunkReused
9604
9628
  });
9605
9629
  tree = new Tree(tree.type, tree.children, tree.positions, tree.length, [[this.lang.stateAfter, this.lang.streamParser.copyState(this.state)]]);
@@ -9712,8 +9736,6 @@ function docID(data) {
9712
9736
  /* harmony export */ vj: () => (/* binding */ IterMode)
9713
9737
  /* harmony export */ });
9714
9738
  /* unused harmony exports DefaultBufferLength, MountedTree, NodeWeakMap, TreeBuffer, TreeCursor, parseMixed */
9715
- // FIXME profile adding a per-Tree TreeNode cache, validating it by
9716
- // parent pointer
9717
9739
  /**
9718
9740
  The default maximum length of a `TreeBuffer` node.
9719
9741
  */
@@ -9828,6 +9850,12 @@ class MountedTree {
9828
9850
  this.overlay = overlay;
9829
9851
  this.parser = parser;
9830
9852
  }
9853
+ /**
9854
+ @internal
9855
+ */
9856
+ static get(tree) {
9857
+ return tree && tree.props && tree.props[NodeProp.mounted.id];
9858
+ }
9831
9859
  }
9832
9860
  const noProps = Object.create(null);
9833
9861
  /**
@@ -10083,7 +10111,7 @@ class Tree {
10083
10111
  @internal
10084
10112
  */
10085
10113
  toString() {
10086
- let mounted = this.prop(NodeProp.mounted);
10114
+ let mounted = MountedTree.get(this);
10087
10115
  if (mounted && !mounted.overlay)
10088
10116
  return mounted.tree.toString();
10089
10117
  let children = "";
@@ -10155,6 +10183,16 @@ class Tree {
10155
10183
  return node;
10156
10184
  }
10157
10185
  /**
10186
+ In some situations, it can be useful to iterate through all
10187
+ nodes around a position, including those in overlays that don't
10188
+ directly cover the position. This method gives you an iterator
10189
+ that will produce all nodes, from small to big, around the given
10190
+ position.
10191
+ */
10192
+ resolveStack(pos, side = 0) {
10193
+ return stackIterator(this, pos, side);
10194
+ }
10195
+ /**
10158
10196
  Iterate over the tree and its children, calling `enter` for any
10159
10197
  node that touches the `from`/`to` region (if given) before
10160
10198
  running over such a node's children, and `leave` (if given) when
@@ -10333,22 +10371,6 @@ function checkSide(side, pos, from, to) {
10333
10371
  case 4 /* Side.DontCare */: return true;
10334
10372
  }
10335
10373
  }
10336
- function enterUnfinishedNodesBefore(node, pos) {
10337
- let scan = node.childBefore(pos);
10338
- while (scan) {
10339
- let last = scan.lastChild;
10340
- if (!last || last.to != scan.to)
10341
- break;
10342
- if (last.type.isError && last.from == last.to) {
10343
- node = scan;
10344
- scan = last.prevSibling;
10345
- }
10346
- else {
10347
- scan = last;
10348
- }
10349
- }
10350
- return node;
10351
- }
10352
10374
  function resolveNode(node, pos, side, overlays) {
10353
10375
  var _a;
10354
10376
  // Move up to a node that actually holds the position, if possible
@@ -10374,10 +10396,48 @@ function resolveNode(node, pos, side, overlays) {
10374
10396
  node = inner;
10375
10397
  }
10376
10398
  }
10377
- class TreeNode {
10399
+ class BaseNode {
10400
+ cursor(mode = 0) { return new TreeCursor(this, mode); }
10401
+ getChild(type, before = null, after = null) {
10402
+ let r = getChildren(this, type, before, after);
10403
+ return r.length ? r[0] : null;
10404
+ }
10405
+ getChildren(type, before = null, after = null) {
10406
+ return getChildren(this, type, before, after);
10407
+ }
10408
+ resolve(pos, side = 0) {
10409
+ return resolveNode(this, pos, side, false);
10410
+ }
10411
+ resolveInner(pos, side = 0) {
10412
+ return resolveNode(this, pos, side, true);
10413
+ }
10414
+ matchContext(context) {
10415
+ return matchNodeContext(this, context);
10416
+ }
10417
+ enterUnfinishedNodesBefore(pos) {
10418
+ let scan = this.childBefore(pos), node = this;
10419
+ while (scan) {
10420
+ let last = scan.lastChild;
10421
+ if (!last || last.to != scan.to)
10422
+ break;
10423
+ if (last.type.isError && last.from == last.to) {
10424
+ node = scan;
10425
+ scan = last.prevSibling;
10426
+ }
10427
+ else {
10428
+ scan = last;
10429
+ }
10430
+ }
10431
+ return node;
10432
+ }
10433
+ get node() { return this; }
10434
+ get next() { return this.parent; }
10435
+ }
10436
+ class TreeNode extends BaseNode {
10378
10437
  constructor(_tree, from,
10379
10438
  // Index in parent node, set to -1 if the node is not a direct child of _parent.node (overlay)
10380
10439
  index, _parent) {
10440
+ super();
10381
10441
  this._tree = _tree;
10382
10442
  this.from = from;
10383
10443
  this.index = index;
@@ -10401,8 +10461,7 @@ class TreeNode {
10401
10461
  }
10402
10462
  else if ((mode & IterMode.IncludeAnonymous) || (!next.type.isAnonymous || hasChild(next))) {
10403
10463
  let mounted;
10404
- if (!(mode & IterMode.IgnoreMounts) &&
10405
- next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
10464
+ if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay)
10406
10465
  return new TreeNode(mounted.tree, start, i, parent);
10407
10466
  let inner = new TreeNode(next, start, i, parent);
10408
10467
  return (mode & IterMode.IncludeAnonymous) || !inner.type.isAnonymous ? inner
@@ -10426,7 +10485,7 @@ class TreeNode {
10426
10485
  childBefore(pos) { return this.nextChild(this._tree.children.length - 1, -1, pos, -2 /* Side.Before */); }
10427
10486
  enter(pos, side, mode = 0) {
10428
10487
  let mounted;
10429
- if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
10488
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = MountedTree.get(this._tree)) && mounted.overlay) {
10430
10489
  let rPos = pos - this.from;
10431
10490
  for (let { from, to } of mounted.overlay) {
10432
10491
  if ((side > 0 ? from <= rPos : from < rPos) &&
@@ -10451,29 +10510,12 @@ class TreeNode {
10451
10510
  get prevSibling() {
10452
10511
  return this._parent && this.index >= 0 ? this._parent.nextChild(this.index - 1, -1, 0, 4 /* Side.DontCare */) : null;
10453
10512
  }
10454
- cursor(mode = 0) { return new TreeCursor(this, mode); }
10455
10513
  get tree() { return this._tree; }
10456
10514
  toTree() { return this._tree; }
10457
- resolve(pos, side = 0) {
10458
- return resolveNode(this, pos, side, false);
10459
- }
10460
- resolveInner(pos, side = 0) {
10461
- return resolveNode(this, pos, side, true);
10462
- }
10463
- enterUnfinishedNodesBefore(pos) { return enterUnfinishedNodesBefore(this, pos); }
10464
- getChild(type, before = null, after = null) {
10465
- let r = getChildren(this, type, before, after);
10466
- return r.length ? r[0] : null;
10467
- }
10468
- getChildren(type, before = null, after = null) {
10469
- return getChildren(this, type, before, after);
10470
- }
10471
10515
  /**
10472
10516
  @internal
10473
10517
  */
10474
10518
  toString() { return this._tree.toString(); }
10475
- get node() { return this; }
10476
- matchContext(context) { return matchNodeContext(this, context); }
10477
10519
  }
10478
10520
  function getChildren(node, type, before, after) {
10479
10521
  let cur = node.cursor(), result = [];
@@ -10512,11 +10554,12 @@ class BufferContext {
10512
10554
  this.start = start;
10513
10555
  }
10514
10556
  }
10515
- class BufferNode {
10557
+ class BufferNode extends BaseNode {
10516
10558
  get name() { return this.type.name; }
10517
10559
  get from() { return this.context.start + this.context.buffer.buffer[this.index + 1]; }
10518
10560
  get to() { return this.context.start + this.context.buffer.buffer[this.index + 2]; }
10519
10561
  constructor(context, _parent, index) {
10562
+ super();
10520
10563
  this.context = context;
10521
10564
  this._parent = _parent;
10522
10565
  this.index = index;
@@ -10558,7 +10601,6 @@ class BufferNode {
10558
10601
  return this.externalSibling(-1);
10559
10602
  return new BufferNode(this.context, this._parent, buffer.findChild(parentStart, this.index, -1, 0, 4 /* Side.DontCare */));
10560
10603
  }
10561
- cursor(mode = 0) { return new TreeCursor(this, mode); }
10562
10604
  get tree() { return null; }
10563
10605
  toTree() {
10564
10606
  let children = [], positions = [];
@@ -10571,26 +10613,57 @@ class BufferNode {
10571
10613
  }
10572
10614
  return new Tree(this.type, children, positions, this.to - this.from);
10573
10615
  }
10574
- resolve(pos, side = 0) {
10575
- return resolveNode(this, pos, side, false);
10576
- }
10577
- resolveInner(pos, side = 0) {
10578
- return resolveNode(this, pos, side, true);
10579
- }
10580
- enterUnfinishedNodesBefore(pos) { return enterUnfinishedNodesBefore(this, pos); }
10581
10616
  /**
10582
10617
  @internal
10583
10618
  */
10584
10619
  toString() { return this.context.buffer.childString(this.index); }
10585
- getChild(type, before = null, after = null) {
10586
- let r = getChildren(this, type, before, after);
10587
- return r.length ? r[0] : null;
10620
+ }
10621
+ function iterStack(heads) {
10622
+ if (!heads.length)
10623
+ return null;
10624
+ if (heads.length == 1)
10625
+ return heads[0];
10626
+ let pick = 0, picked = heads[0];
10627
+ for (let i = 1; i < heads.length; i++) {
10628
+ let node = heads[i];
10629
+ if (node.from > picked.from || node.to < picked.to) {
10630
+ picked = node;
10631
+ pick = i;
10632
+ }
10633
+ }
10634
+ let next = picked instanceof TreeNode && picked.index < 0 ? null : picked.parent;
10635
+ let newHeads = heads.slice();
10636
+ if (next)
10637
+ newHeads[pick] = next;
10638
+ else
10639
+ newHeads.splice(pick, 1);
10640
+ return new StackIterator(newHeads, picked);
10641
+ }
10642
+ class StackIterator {
10643
+ constructor(heads, node) {
10644
+ this.heads = heads;
10645
+ this.node = node;
10588
10646
  }
10589
- getChildren(type, before = null, after = null) {
10590
- return getChildren(this, type, before, after);
10647
+ get next() { return iterStack(this.heads); }
10648
+ }
10649
+ function stackIterator(tree, pos, side) {
10650
+ let inner = tree.resolveInner(pos, side), layers = null;
10651
+ for (let scan = inner instanceof TreeNode ? inner : inner.context.parent; scan; scan = scan.parent) {
10652
+ if (scan.index < 0) { // This is an overlay root
10653
+ let parent = scan.parent;
10654
+ (layers || (layers = [inner])).push(parent.resolve(pos, side));
10655
+ scan = parent;
10656
+ }
10657
+ else {
10658
+ let mount = MountedTree.get(scan.tree);
10659
+ // Relevant overlay branching off
10660
+ if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
10661
+ let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, 0, null);
10662
+ (layers || (layers = [inner])).push(resolveNode(root, pos, side, false));
10663
+ }
10664
+ }
10591
10665
  }
10592
- get node() { return this; }
10593
- matchContext(context) { return matchNodeContext(this, context); }
10666
+ return layers ? iterStack(layers) : inner;
10594
10667
  }
10595
10668
  /**
10596
10669
  A tree cursor object focuses on a given node in a syntax tree, and