@uiw/react-codemirror 4.23.5 → 4.23.7

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.
@@ -140,19 +140,20 @@ class SearchCursor {
140
140
  let str = (0,state_.fromCodePoint)(next), start = this.bufferStart + this.bufferPos;
141
141
  this.bufferPos += (0,state_.codePointSize)(next);
142
142
  let norm = this.normalize(str);
143
- for (let i = 0, pos = start;; i++) {
144
- let code = norm.charCodeAt(i);
145
- let match = this.match(code, pos, this.bufferPos + this.bufferStart);
146
- if (i == norm.length - 1) {
147
- if (match) {
148
- this.value = match;
149
- return this;
143
+ if (norm.length)
144
+ for (let i = 0, pos = start;; i++) {
145
+ let code = norm.charCodeAt(i);
146
+ let match = this.match(code, pos, this.bufferPos + this.bufferStart);
147
+ if (i == norm.length - 1) {
148
+ if (match) {
149
+ this.value = match;
150
+ return this;
151
+ }
152
+ break;
150
153
  }
151
- break;
154
+ if (pos == start && i < str.length && str.charCodeAt(i) == code)
155
+ pos++;
152
156
  }
153
- if (pos == start && i < str.length && str.charCodeAt(i) == code)
154
- pos++;
155
- }
156
157
  }
157
158
  }
158
159
  match(code, pos, end) {
@@ -709,9 +710,11 @@ class StringQuery extends QueryType {
709
710
  }
710
711
  nextMatch(state, curFrom, curTo) {
711
712
  let cursor = stringCursor(this.spec, state, curTo, state.doc.length).nextOverlapping();
712
- if (cursor.done)
713
- cursor = stringCursor(this.spec, state, 0, curFrom).nextOverlapping();
714
- return cursor.done ? null : cursor.value;
713
+ if (cursor.done) {
714
+ let end = Math.min(state.doc.length, curFrom + this.spec.unquoted.length);
715
+ cursor = stringCursor(this.spec, state, 0, end).nextOverlapping();
716
+ }
717
+ return cursor.done || cursor.value.from == curFrom && cursor.value.to == curTo ? null : cursor.value;
715
718
  }
716
719
  // Searching in reverse is, rather than implementing an inverted search
717
720
  // cursor, done by scanning chunk after chunk forward.
@@ -729,8 +732,10 @@ class StringQuery extends QueryType {
729
732
  }
730
733
  }
731
734
  prevMatch(state, curFrom, curTo) {
732
- return this.prevMatchInRange(state, 0, curFrom) ||
733
- this.prevMatchInRange(state, curTo, state.doc.length);
735
+ let found = this.prevMatchInRange(state, 0, curFrom);
736
+ if (!found)
737
+ found = this.prevMatchInRange(state, Math.max(0, curTo - this.spec.unquoted.length), state.doc.length);
738
+ return found && (found.from != curFrom || found.to != curTo) ? found : null;
734
739
  }
735
740
  getReplacement(_result) { return this.spec.unquote(this.spec.replace); }
736
741
  matchAll(state, limit) {
@@ -974,9 +979,10 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
974
979
  let { state } = view, { from, to } = state.selection.main;
975
980
  if (state.readOnly)
976
981
  return false;
977
- let next = query.nextMatch(state, from, from);
978
- if (!next)
982
+ let match = query.nextMatch(state, from, from);
983
+ if (!match)
979
984
  return false;
985
+ let next = match;
980
986
  let changes = [], selection, replacement;
981
987
  let effects = [];
982
988
  if (next.from == from && next.to == to) {
@@ -986,7 +992,7 @@ const replaceNext = /*@__PURE__*/searchCommand((view, { query }) => {
986
992
  effects.push(view_.EditorView.announce.of(state.phrase("replaced match on line $", state.doc.lineAt(from).number) + "."));
987
993
  }
988
994
  if (next) {
989
- let off = changes.length == 0 || changes[0].from >= next.to ? 0 : next.to - next.from - replacement.length;
995
+ let off = changes.length == 0 || changes[0].from >= match.to ? 0 : match.to - match.from - replacement.length;
990
996
  selection = state_.EditorSelection.single(next.from - off, next.to - off);
991
997
  effects.push(announceMatch(view, next));
992
998
  effects.push(state.facet(searchConfigFacet).scrollToMatch(selection.main, view));
@@ -2098,12 +2104,12 @@ class CompletionDialog {
2098
2104
  return selected == this.selected || selected >= this.options.length ? this
2099
2105
  : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
2100
2106
  }
2101
- static build(active, state, id, prev, conf) {
2107
+ static build(active, state, id, prev, conf, didSetActive) {
2108
+ if (prev && !didSetActive && active.some(s => s.isPending))
2109
+ return prev.setDisabled();
2102
2110
  let options = sortOptions(active, state);
2103
- if (!options.length) {
2104
- return prev && active.some(a => a.state == 1 /* State.Pending */) ?
2105
- new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
2106
- }
2111
+ if (!options.length)
2112
+ return prev && active.some(a => a.isPending) ? prev.setDisabled() : null;
2107
2113
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
2108
2114
  if (prev && prev.selected != selected && prev.selected != -1) {
2109
2115
  let selectedValue = prev.options[prev.selected].completion;
@@ -2122,6 +2128,9 @@ class CompletionDialog {
2122
2128
  map(changes) {
2123
2129
  return new CompletionDialog(this.options, this.attrs, Object.assign(Object.assign({}, this.tooltip), { pos: changes.mapPos(this.tooltip.pos) }), this.timestamp, this.selected, this.disabled);
2124
2130
  }
2131
+ setDisabled() {
2132
+ return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
2133
+ }
2125
2134
  }
2126
2135
  class CompletionState {
2127
2136
  constructor(active, id, open) {
@@ -2143,15 +2152,15 @@ class CompletionState {
2143
2152
  });
2144
2153
  if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
2145
2154
  active = this.active;
2146
- let open = this.open;
2155
+ let open = this.open, didSet = tr.effects.some(e => e.is(setActiveEffect));
2147
2156
  if (open && tr.docChanged)
2148
2157
  open = open.map(tr.changes);
2149
2158
  if (tr.selection || active.some(a => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
2150
- !sameResults(active, this.active))
2151
- open = CompletionDialog.build(active, state, this.id, open, conf);
2152
- else if (open && open.disabled && !active.some(a => a.state == 1 /* State.Pending */))
2159
+ !sameResults(active, this.active) || didSet)
2160
+ open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
2161
+ else if (open && open.disabled && !active.some(a => a.isPending))
2153
2162
  open = null;
2154
- if (!open && active.every(a => a.state != 1 /* State.Pending */) && active.some(a => a.hasResult()))
2163
+ if (!open && active.every(a => !a.isPending) && active.some(a => a.hasResult()))
2155
2164
  active = active.map(a => a.hasResult() ? new ActiveSource(a.source, 0 /* State.Inactive */) : a);
2156
2165
  for (let effect of tr.effects)
2157
2166
  if (effect.is(setSelectedEffect))
@@ -2165,9 +2174,9 @@ function sameResults(a, b) {
2165
2174
  if (a == b)
2166
2175
  return true;
2167
2176
  for (let iA = 0, iB = 0;;) {
2168
- while (iA < a.length && !a[iA].hasResult)
2177
+ while (iA < a.length && !a[iA].hasResult())
2169
2178
  iA++;
2170
- while (iB < b.length && !b[iB].hasResult)
2179
+ while (iB < b.length && !b[iB].hasResult())
2171
2180
  iB++;
2172
2181
  let endA = iA == a.length, endB = iB == b.length;
2173
2182
  if (endA || endB)
@@ -2205,12 +2214,13 @@ function getUpdateType(tr, conf) {
2205
2214
  : tr.docChanged ? 16 /* UpdateType.ResetIfTouching */ : 0 /* UpdateType.None */;
2206
2215
  }
2207
2216
  class ActiveSource {
2208
- constructor(source, state, explicitPos = -1) {
2217
+ constructor(source, state, explicit = false) {
2209
2218
  this.source = source;
2210
2219
  this.state = state;
2211
- this.explicitPos = explicitPos;
2220
+ this.explicit = explicit;
2212
2221
  }
2213
2222
  hasResult() { return false; }
2223
+ get isPending() { return this.state == 1 /* State.Pending */; }
2214
2224
  update(tr, conf) {
2215
2225
  let type = getUpdateType(tr, conf), value = this;
2216
2226
  if ((type & 8 /* UpdateType.Reset */) || (type & 16 /* UpdateType.ResetIfTouching */) && this.touches(tr))
@@ -2220,7 +2230,7 @@ class ActiveSource {
2220
2230
  value = value.updateFor(tr, type);
2221
2231
  for (let effect of tr.effects) {
2222
2232
  if (effect.is(startCompletionEffect))
2223
- value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value ? cur(tr.state) : -1);
2233
+ value = new ActiveSource(value.source, 1 /* State.Pending */, effect.value);
2224
2234
  else if (effect.is(closeCompletionEffect))
2225
2235
  value = new ActiveSource(value.source, 0 /* State.Inactive */);
2226
2236
  else if (effect.is(setActiveEffect))
@@ -2231,16 +2241,15 @@ class ActiveSource {
2231
2241
  return value;
2232
2242
  }
2233
2243
  updateFor(tr, type) { return this.map(tr.changes); }
2234
- map(changes) {
2235
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
2236
- }
2244
+ map(changes) { return this; }
2237
2245
  touches(tr) {
2238
2246
  return tr.changes.touchesRange(cur(tr.state));
2239
2247
  }
2240
2248
  }
2241
2249
  class ActiveResult extends ActiveSource {
2242
- constructor(source, explicitPos, result, from, to) {
2243
- super(source, 2 /* State.Result */, explicitPos);
2250
+ constructor(source, explicit, limit, result, from, to) {
2251
+ super(source, 3 /* State.Result */, explicit);
2252
+ this.limit = limit;
2244
2253
  this.result = result;
2245
2254
  this.from = from;
2246
2255
  this.to = to;
@@ -2255,17 +2264,16 @@ class ActiveResult extends ActiveSource {
2255
2264
  result = result.map(result, tr.changes);
2256
2265
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
2257
2266
  let pos = cur(tr.state);
2258
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
2259
- pos > to || !result ||
2260
- (type & 2 /* UpdateType.Backspacing */) && cur(tr.startState) == this.from)
2267
+ if (pos > to || !result ||
2268
+ (type & 2 /* UpdateType.Backspacing */) && (cur(tr.startState) == this.from || pos < this.limit))
2261
2269
  return new ActiveSource(this.source, type & 4 /* UpdateType.Activate */ ? 1 /* State.Pending */ : 0 /* State.Inactive */);
2262
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
2270
+ let limit = tr.changes.mapPos(this.limit);
2263
2271
  if (checkValid(result.validFor, tr.state, from, to))
2264
- return new ActiveResult(this.source, explicitPos, result, from, to);
2272
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to);
2265
2273
  if (result.update &&
2266
- (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
2267
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
2268
- return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
2274
+ (result = result.update(result, from, to, new CompletionContext(tr.state, pos, false))))
2275
+ return new ActiveResult(this.source, this.explicit, limit, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
2276
+ return new ActiveSource(this.source, 1 /* State.Pending */, this.explicit);
2269
2277
  }
2270
2278
  map(mapping) {
2271
2279
  if (mapping.empty)
@@ -2273,7 +2281,7 @@ class ActiveResult extends ActiveSource {
2273
2281
  let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
2274
2282
  if (!result)
2275
2283
  return new ActiveSource(this.source, 0 /* State.Inactive */);
2276
- return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
2284
+ return new ActiveResult(this.source, this.explicit, mapping.mapPos(this.limit), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
2277
2285
  }
2278
2286
  touches(tr) {
2279
2287
  return tr.changes.touchesRange(this.from, this.to);
@@ -2385,7 +2393,7 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2385
2393
  this.pendingStart = false;
2386
2394
  this.composing = 0 /* CompositionState.None */;
2387
2395
  for (let active of view.state.field(completionState).active)
2388
- if (active.state == 1 /* State.Pending */)
2396
+ if (active.isPending)
2389
2397
  this.startQuery(active);
2390
2398
  }
2391
2399
  update(update) {
@@ -2422,7 +2430,7 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2422
2430
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
2423
2431
  this.pendingStart = true;
2424
2432
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
2425
- this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
2433
+ this.debounceUpdate = cState.active.some(a => a.isPending && !this.running.some(q => q.active.source == a.source))
2426
2434
  ? setTimeout(() => this.startUpdate(), delay) : -1;
2427
2435
  if (this.composing != 0 /* CompositionState.None */)
2428
2436
  for (let tr of update.transactions) {
@@ -2437,13 +2445,15 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2437
2445
  this.pendingStart = false;
2438
2446
  let { state } = this.view, cState = state.field(completionState);
2439
2447
  for (let active of cState.active) {
2440
- if (active.state == 1 /* State.Pending */ && !this.running.some(r => r.active.source == active.source))
2448
+ if (active.isPending && !this.running.some(r => r.active.source == active.source))
2441
2449
  this.startQuery(active);
2442
2450
  }
2451
+ if (this.running.length && cState.open && cState.open.disabled)
2452
+ this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
2443
2453
  }
2444
2454
  startQuery(active) {
2445
2455
  let { state } = this.view, pos = cur(state);
2446
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
2456
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
2447
2457
  let pending = new RunningQuery(active, context);
2448
2458
  this.running.push(pending);
2449
2459
  Promise.resolve(active.source(context)).then(result => {
@@ -2470,14 +2480,16 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2470
2480
  clearTimeout(this.debounceAccept);
2471
2481
  this.debounceAccept = -1;
2472
2482
  let updated = [];
2473
- let conf = this.view.state.facet(completionConfig);
2483
+ let conf = this.view.state.facet(completionConfig), cState = this.view.state.field(completionState);
2474
2484
  for (let i = 0; i < this.running.length; i++) {
2475
2485
  let query = this.running[i];
2476
2486
  if (query.done === undefined)
2477
2487
  continue;
2478
2488
  this.running.splice(i--, 1);
2479
2489
  if (query.done) {
2480
- let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : cur(query.updates.length ? query.updates[0].startState : this.view.state));
2490
+ let pos = cur(query.updates.length ? query.updates[0].startState : this.view.state);
2491
+ let limit = Math.min(pos, query.done.from + (query.active.explicit ? 0 : 1));
2492
+ let active = new ActiveResult(query.active.source, query.active.explicit, limit, query.done, query.done.from, (_a = query.done.to) !== null && _a !== void 0 ? _a : pos);
2481
2493
  // Replay the transactions that happened since the start of
2482
2494
  // the request and see if that preserves the result
2483
2495
  for (let tr of query.updates)
@@ -2487,15 +2499,15 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2487
2499
  continue;
2488
2500
  }
2489
2501
  }
2490
- let current = this.view.state.field(completionState).active.find(a => a.source == query.active.source);
2491
- if (current && current.state == 1 /* State.Pending */) {
2502
+ let current = cState.active.find(a => a.source == query.active.source);
2503
+ if (current && current.isPending) {
2492
2504
  if (query.done == null) {
2493
2505
  // Explicitly failed. Should clear the pending status if it
2494
2506
  // hasn't been re-set in the meantime.
2495
2507
  let active = new ActiveSource(query.active.source, 0 /* State.Inactive */);
2496
2508
  for (let tr of query.updates)
2497
2509
  active = active.update(tr, conf);
2498
- if (active.state != 1 /* State.Pending */)
2510
+ if (!active.isPending)
2499
2511
  updated.push(active);
2500
2512
  }
2501
2513
  else {
@@ -2504,7 +2516,7 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2504
2516
  }
2505
2517
  }
2506
2518
  }
2507
- if (updated.length)
2519
+ if (updated.length || cState.open && cState.open.disabled)
2508
2520
  this.view.dispatch({ effects: setActiveEffect.of(updated) });
2509
2521
  }
2510
2522
  }, {
@@ -3306,7 +3318,7 @@ returns `null`.
3306
3318
  */
3307
3319
  function completionStatus(state) {
3308
3320
  let cState = state.field(completionState, false);
3309
- return cState && cState.active.some(a => a.state == 1 /* State.Pending */) ? "pending"
3321
+ return cState && cState.active.some(a => a.isPending) ? "pending"
3310
3322
  : cState && cState.active.some(a => a.state != 0 /* State.Inactive */) ? "active" : null;
3311
3323
  }
3312
3324
  const completionArrayCache = /*@__PURE__*/new WeakMap;
@@ -3374,28 +3386,70 @@ class LintState {
3374
3386
  let diagnosticFilter = state.facet(lintConfig).markerFilter;
3375
3387
  if (diagnosticFilter)
3376
3388
  markedDiagnostics = diagnosticFilter(markedDiagnostics, state);
3377
- let ranges = view_.Decoration.set(markedDiagnostics.map((d) => {
3378
- // For zero-length ranges or ranges covering only a line break, create a widget
3379
- return d.from == d.to || (d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from)
3380
- ? view_.Decoration.widget({
3381
- widget: new DiagnosticWidget(d),
3382
- diagnostic: d
3383
- }).range(d.from)
3384
- : view_.Decoration.mark({
3385
- attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
3386
- diagnostic: d
3387
- }).range(d.from, d.to);
3388
- }), true);
3389
- return new LintState(ranges, panel, findDiagnostic(ranges));
3389
+ let sorted = diagnostics.slice().sort((a, b) => a.from - b.from || a.to - b.to);
3390
+ let deco = new state_.RangeSetBuilder(), active = [], pos = 0;
3391
+ for (let i = 0;;) {
3392
+ let next = i == sorted.length ? null : sorted[i];
3393
+ if (!next && !active.length)
3394
+ break;
3395
+ let from, to;
3396
+ if (active.length) {
3397
+ from = pos;
3398
+ to = active.reduce((p, d) => Math.min(p, d.to), next && next.from > from ? next.from : 1e8);
3399
+ }
3400
+ else {
3401
+ from = next.from;
3402
+ to = next.to;
3403
+ active.push(next);
3404
+ i++;
3405
+ }
3406
+ while (i < sorted.length) {
3407
+ let next = sorted[i];
3408
+ if (next.from == from && (next.to > next.from || next.to == from)) {
3409
+ active.push(next);
3410
+ i++;
3411
+ to = Math.min(next.to, to);
3412
+ }
3413
+ else {
3414
+ to = Math.min(next.from, to);
3415
+ break;
3416
+ }
3417
+ }
3418
+ let sev = maxSeverity(active);
3419
+ if (active.some(d => d.from == d.to || (d.from == d.to - 1 && state.doc.lineAt(d.from).to == d.from))) {
3420
+ deco.add(from, from, view_.Decoration.widget({
3421
+ widget: new DiagnosticWidget(sev),
3422
+ diagnostics: active.slice()
3423
+ }));
3424
+ }
3425
+ else {
3426
+ let markClass = active.reduce((c, d) => d.markClass ? c + " " + d.markClass : c, "");
3427
+ deco.add(from, to, view_.Decoration.mark({
3428
+ class: "cm-lintRange cm-lintRange-" + sev + markClass,
3429
+ diagnostics: active.slice(),
3430
+ inclusiveEnd: active.some(a => a.to > to)
3431
+ }));
3432
+ }
3433
+ pos = to;
3434
+ for (let i = 0; i < active.length; i++)
3435
+ if (active[i].to <= pos)
3436
+ active.splice(i--, 1);
3437
+ }
3438
+ let set = deco.finish();
3439
+ return new LintState(set, panel, findDiagnostic(set));
3390
3440
  }
3391
3441
  }
3392
3442
  function findDiagnostic(diagnostics, diagnostic = null, after = 0) {
3393
3443
  let found = null;
3394
3444
  diagnostics.between(after, 1e9, (from, to, { spec }) => {
3395
- if (diagnostic && spec.diagnostic != diagnostic)
3445
+ if (diagnostic && spec.diagnostics.indexOf(diagnostic) < 0)
3396
3446
  return;
3397
- found = new SelectedDiagnostic(from, to, spec.diagnostic);
3398
- return false;
3447
+ if (!found)
3448
+ found = new SelectedDiagnostic(from, to, diagnostic || spec.diagnostics[0]);
3449
+ else if (spec.diagnostics.indexOf(found.diagnostic) < 0)
3450
+ return false;
3451
+ else
3452
+ found = new SelectedDiagnostic(found.from, to, found.diagnostic);
3399
3453
  });
3400
3454
  return found;
3401
3455
  }
@@ -3469,24 +3523,25 @@ function diagnosticCount(state) {
3469
3523
  const activeMark = /*@__PURE__*/view_.Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
3470
3524
  function lintTooltip(view, pos, side) {
3471
3525
  let { diagnostics } = view.state.field(lintState);
3472
- let found = [], stackStart = 2e8, stackEnd = 0;
3526
+ let found, start = -1, end = -1;
3473
3527
  diagnostics.between(pos - (side < 0 ? 1 : 0), pos + (side > 0 ? 1 : 0), (from, to, { spec }) => {
3474
3528
  if (pos >= from && pos <= to &&
3475
3529
  (from == to || ((pos > from || side > 0) && (pos < to || side < 0)))) {
3476
- found.push(spec.diagnostic);
3477
- stackStart = Math.min(from, stackStart);
3478
- stackEnd = Math.max(to, stackEnd);
3530
+ found = spec.diagnostics;
3531
+ start = from;
3532
+ end = to;
3533
+ return false;
3479
3534
  }
3480
3535
  });
3481
3536
  let diagnosticFilter = view.state.facet(lintConfig).tooltipFilter;
3482
- if (diagnosticFilter)
3537
+ if (found && diagnosticFilter)
3483
3538
  found = diagnosticFilter(found, view.state);
3484
- if (!found.length)
3539
+ if (!found)
3485
3540
  return null;
3486
3541
  return {
3487
- pos: stackStart,
3488
- end: stackEnd,
3489
- above: view.state.doc.lineAt(stackStart).to < stackEnd,
3542
+ pos: start,
3543
+ end: end,
3544
+ above: view.state.doc.lineAt(start).to < end,
3490
3545
  create() {
3491
3546
  return { dom: diagnosticsTooltip(view, found) };
3492
3547
  }
@@ -3623,7 +3678,7 @@ function batchResults(promises, sink, error) {
3623
3678
  if (collected.length == promises.length)
3624
3679
  sink(collected);
3625
3680
  else
3626
- setTimeout(() => sink(collected), 200);
3681
+ timeout = setTimeout(() => sink(collected), 200);
3627
3682
  }, error);
3628
3683
  }
3629
3684
  const lintConfig = /*@__PURE__*/state_.Facet.define({
@@ -3703,13 +3758,13 @@ function renderDiagnostic(view, diagnostic, inPanel) {
3703
3758
  }), diagnostic.source && crelt("div", { class: "cm-diagnosticSource" }, diagnostic.source));
3704
3759
  }
3705
3760
  class DiagnosticWidget extends view_.WidgetType {
3706
- constructor(diagnostic) {
3761
+ constructor(sev) {
3707
3762
  super();
3708
- this.diagnostic = diagnostic;
3763
+ this.sev = sev;
3709
3764
  }
3710
- eq(other) { return other.diagnostic == this.diagnostic; }
3765
+ eq(other) { return other.sev == this.sev; }
3711
3766
  toDOM() {
3712
- return crelt("span", { class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity });
3767
+ return crelt("span", { class: "cm-lintPoint cm-lintPoint-" + this.sev });
3713
3768
  }
3714
3769
  }
3715
3770
  class PanelItem {
@@ -3792,35 +3847,41 @@ class LintPanel {
3792
3847
  update() {
3793
3848
  let { diagnostics, selected } = this.view.state.field(lintState);
3794
3849
  let i = 0, needsSync = false, newSelectedItem = null;
3850
+ let seen = new Set();
3795
3851
  diagnostics.between(0, this.view.state.doc.length, (_start, _end, { spec }) => {
3796
- let found = -1, item;
3797
- for (let j = i; j < this.items.length; j++)
3798
- if (this.items[j].diagnostic == spec.diagnostic) {
3799
- found = j;
3800
- break;
3801
- }
3802
- if (found < 0) {
3803
- item = new PanelItem(this.view, spec.diagnostic);
3804
- this.items.splice(i, 0, item);
3805
- needsSync = true;
3806
- }
3807
- else {
3808
- item = this.items[found];
3809
- if (found > i) {
3810
- this.items.splice(i, found - i);
3852
+ for (let diagnostic of spec.diagnostics) {
3853
+ if (seen.has(diagnostic))
3854
+ continue;
3855
+ seen.add(diagnostic);
3856
+ let found = -1, item;
3857
+ for (let j = i; j < this.items.length; j++)
3858
+ if (this.items[j].diagnostic == diagnostic) {
3859
+ found = j;
3860
+ break;
3861
+ }
3862
+ if (found < 0) {
3863
+ item = new PanelItem(this.view, diagnostic);
3864
+ this.items.splice(i, 0, item);
3811
3865
  needsSync = true;
3812
3866
  }
3813
- }
3814
- if (selected && item.diagnostic == selected.diagnostic) {
3815
- if (!item.dom.hasAttribute("aria-selected")) {
3816
- item.dom.setAttribute("aria-selected", "true");
3817
- newSelectedItem = item;
3867
+ else {
3868
+ item = this.items[found];
3869
+ if (found > i) {
3870
+ this.items.splice(i, found - i);
3871
+ needsSync = true;
3872
+ }
3818
3873
  }
3874
+ if (selected && item.diagnostic == selected.diagnostic) {
3875
+ if (!item.dom.hasAttribute("aria-selected")) {
3876
+ item.dom.setAttribute("aria-selected", "true");
3877
+ newSelectedItem = item;
3878
+ }
3879
+ }
3880
+ else if (item.dom.hasAttribute("aria-selected")) {
3881
+ item.dom.removeAttribute("aria-selected");
3882
+ }
3883
+ i++;
3819
3884
  }
3820
- else if (item.dom.hasAttribute("aria-selected")) {
3821
- item.dom.removeAttribute("aria-selected");
3822
- }
3823
- i++;
3824
3885
  });
3825
3886
  while (i < this.items.length && !(this.items.length == 1 && this.items[0].diagnostic.from < 0)) {
3826
3887
  needsSync = true;
@@ -3989,11 +4050,22 @@ const lint_dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
3989
4050
  function severityWeight(sev) {
3990
4051
  return sev == "error" ? 4 : sev == "warning" ? 3 : sev == "info" ? 2 : 1;
3991
4052
  }
4053
+ function maxSeverity(diagnostics) {
4054
+ let sev = "hint", weight = 1;
4055
+ for (let d of diagnostics) {
4056
+ let w = severityWeight(d.severity);
4057
+ if (w > weight) {
4058
+ weight = w;
4059
+ sev = d.severity;
4060
+ }
4061
+ }
4062
+ return sev;
4063
+ }
3992
4064
  class LintGutterMarker extends view_.GutterMarker {
3993
4065
  constructor(diagnostics) {
3994
4066
  super();
3995
4067
  this.diagnostics = diagnostics;
3996
- this.severity = diagnostics.reduce((max, d) => severityWeight(max) < severityWeight(d.severity) ? d.severity : max, "hint");
4068
+ this.severity = maxSeverity(diagnostics);
3997
4069
  }
3998
4070
  toDOM(view) {
3999
4071
  let elt = document.createElement("div");
@@ -4031,6 +4103,7 @@ function gutterMarkerMouseOver(view, marker, diagnostics) {
4031
4103
  view.dispatch({ effects: setLintGutterTooltip.of({
4032
4104
  pos: line.from,
4033
4105
  above: false,
4106
+ clip: false,
4034
4107
  create() {
4035
4108
  return {
4036
4109
  dom: diagnosticsTooltip(view, diagnostics),
@@ -4071,7 +4144,8 @@ const lintGutterExtension = /*@__PURE__*/(0,view_.gutter)({
4071
4144
  widgetMarker: (view, widget, block) => {
4072
4145
  let diagnostics = [];
4073
4146
  view.state.field(lintGutterMarkers).between(block.from, block.to, (from, to, value) => {
4074
- diagnostics.push(...value.diagnostics);
4147
+ if (from > block.from && from < block.to)
4148
+ diagnostics.push(...value.diagnostics);
4075
4149
  });
4076
4150
  return diagnostics.length ? new LintGutterMarker(diagnostics) : null;
4077
4151
  }
@@ -4162,9 +4236,25 @@ arguments hold the diagnostic's current position.
4162
4236
  */
4163
4237
  function forEachDiagnostic(state, f) {
4164
4238
  let lState = state.field(lintState, false);
4165
- if (lState && lState.diagnostics.size)
4166
- for (let iter = RangeSet.iter([lState.diagnostics]); iter.value; iter.next())
4167
- f(iter.value.spec.diagnostic, iter.from, iter.to);
4239
+ if (lState && lState.diagnostics.size) {
4240
+ let pending = [], pendingStart = [], lastEnd = -1;
4241
+ for (let iter = RangeSet.iter([lState.diagnostics]);; iter.next()) {
4242
+ for (let i = 0; i < pending.length; i++)
4243
+ if (!iter.value || iter.value.spec.diagnostics.indexOf(pending[i]) < 0) {
4244
+ f(pending[i], pendingStart[i], lastEnd);
4245
+ pending.splice(i, 1);
4246
+ pendingStart.splice(i--, 1);
4247
+ }
4248
+ if (!iter.value)
4249
+ break;
4250
+ for (let d of iter.value.spec.diagnostics)
4251
+ if (pending.indexOf(d) < 0) {
4252
+ pending.push(d);
4253
+ pendingStart.push(iter.from);
4254
+ }
4255
+ lastEnd = iter.to;
4256
+ }
4257
+ }
4168
4258
  }
4169
4259
 
4170
4260
 
@@ -4620,7 +4710,7 @@ function _objectWithoutProperties(e, t) {
4620
4710
  /* harmony export */ cL: () => (/* binding */ historyKeymap),
4621
4711
  /* harmony export */ pw: () => (/* binding */ defaultKeymap)
4622
4712
  /* harmony export */ });
4623
- /* unused harmony exports blockComment, blockUncomment, copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineBoundaryLeft, cursorLineBoundaryRight, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, deleteCharBackward, deleteCharBackwardStrict, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteLineBoundaryBackward, deleteLineBoundaryForward, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, historyField, indentLess, indentMore, indentSelection, insertBlankLine, insertNewline, insertNewlineAndIndent, insertNewlineKeepIndent, insertTab, invertedEffects, isolateHistory, lineComment, lineUncomment, moveLineDown, moveLineUp, redo, redoDepth, redoSelection, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineBoundaryLeft, selectLineBoundaryRight, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, temporarilySetTabFocusMode, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, toggleTabFocusMode, transposeChars, undo, undoDepth, undoSelection */
4713
+ /* unused harmony exports blockComment, blockUncomment, copyLineDown, copyLineUp, cursorCharBackward, cursorCharBackwardLogical, cursorCharForward, cursorCharForwardLogical, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineBoundaryLeft, cursorLineBoundaryRight, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, deleteCharBackward, deleteCharBackwardStrict, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteLineBoundaryBackward, deleteLineBoundaryForward, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, historyField, indentLess, indentMore, indentSelection, insertBlankLine, insertNewline, insertNewlineAndIndent, insertNewlineKeepIndent, insertTab, invertedEffects, isolateHistory, lineComment, lineUncomment, moveLineDown, moveLineUp, redo, redoDepth, redoSelection, selectAll, selectCharBackward, selectCharBackwardLogical, selectCharForward, selectCharForwardLogical, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineBoundaryLeft, selectLineBoundaryRight, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, temporarilySetTabFocusMode, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, toggleTabFocusMode, transposeChars, undo, undoDepth, undoSelection */
4624
4714
  /* harmony import */ var _codemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(60);
4625
4715
  /* harmony import */ var _codemirror_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(730);
4626
4716
  /* harmony import */ var _codemirror_language__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(194);
@@ -4727,6 +4817,8 @@ function selectedLineRanges(state) {
4727
4817
  for (let r of state.selection.ranges) {
4728
4818
  let fromLine = state.doc.lineAt(r.from);
4729
4819
  let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
4820
+ if (toLine.from > fromLine.from && toLine.from == r.to)
4821
+ toLine = r.to == fromLine.to + 1 ? fromLine : state.doc.lineAt(r.to - 1);
4730
4822
  let last = ranges.length - 1;
4731
4823
  if (last >= 0 && ranges[last].to > fromLine.from)
4732
4824
  ranges[last].to = toLine.to;
@@ -5218,6 +5310,27 @@ const cursorCharForward = view => cursorByChar(view, true);
5218
5310
  Move the selection one character backward.
5219
5311
  */
5220
5312
  const cursorCharBackward = view => cursorByChar(view, false);
5313
+ function byCharLogical(state, range, forward) {
5314
+ let pos = range.head, line = state.doc.lineAt(pos);
5315
+ if (pos == (forward ? line.to : line.from))
5316
+ pos = forward ? Math.min(state.doc.length, line.to + 1) : Math.max(0, line.from - 1);
5317
+ else
5318
+ pos = line.from + findClusterBreak(line.text, pos - line.from, forward);
5319
+ return EditorSelection.cursor(pos, forward ? -1 : 1);
5320
+ }
5321
+ function moveByCharLogical(target, forward) {
5322
+ return moveSel(target, range => range.empty ? byCharLogical(target.state, range, forward) : rangeEnd(range, forward));
5323
+ }
5324
+ /**
5325
+ Move the selection one character forward, in logical
5326
+ (non-text-direction-aware) string index order.
5327
+ */
5328
+ const cursorCharForwardLogical = target => moveByCharLogical(target, true);
5329
+ /**
5330
+ Move the selection one character backward, in logical string index
5331
+ order.
5332
+ */
5333
+ const cursorCharBackwardLogical = target => moveByCharLogical(target, false);
5221
5334
  function cursorByGroup(view, forward) {
5222
5335
  return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
5223
5336
  }
@@ -5468,14 +5581,14 @@ Extend the selection to the bracket matching the one the selection
5468
5581
  head is currently on, if any.
5469
5582
  */
5470
5583
  const selectMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch, true);
5471
- function extendSel(view, how) {
5472
- let selection = updateSel(view.state.selection, range => {
5584
+ function extendSel(target, how) {
5585
+ let selection = updateSel(target.state.selection, range => {
5473
5586
  let head = how(range);
5474
5587
  return _codemirror_state__WEBPACK_IMPORTED_MODULE_0__.EditorSelection.range(range.anchor, head.head, head.goalColumn, head.bidiLevel || undefined);
5475
5588
  });
5476
- if (selection.eq(view.state.selection))
5589
+ if (selection.eq(target.state.selection))
5477
5590
  return false;
5478
- view.dispatch(setSel(view.state, selection));
5591
+ target.dispatch(setSel(target.state, selection));
5479
5592
  return true;
5480
5593
  }
5481
5594
  function selectByChar(view, forward) {
@@ -5498,6 +5611,16 @@ const selectCharForward = view => selectByChar(view, true);
5498
5611
  Move the selection head one character backward.
5499
5612
  */
5500
5613
  const selectCharBackward = view => selectByChar(view, false);
5614
+ /**
5615
+ Move the selection head one character forward by logical
5616
+ (non-direction aware) string index order.
5617
+ */
5618
+ const selectCharForwardLogical = target => extendSel(target, range => byCharLogical(target.state, range, true));
5619
+ /**
5620
+ Move the selection head one character backward by logical string
5621
+ index order.
5622
+ */
5623
+ const selectCharBackwardLogical = target => extendSel(target, range => byCharLogical(target.state, range, false));
5501
5624
  function selectByGroup(view, forward) {
5502
5625
  return extendSel(view, range => view.moveByGroup(range, forward));
5503
5626
  }
@@ -6217,7 +6340,7 @@ property changed to `mac`.)
6217
6340
  - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift)
6218
6341
  - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
6219
6342
  - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
6220
- - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
6343
+ - Enter and Shift-Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
6221
6344
  - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll)
6222
6345
  - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
6223
6346
  - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
@@ -6245,7 +6368,7 @@ const standardKeymap = /*@__PURE__*/[
6245
6368
  { key: "Mod-Home", run: cursorDocStart, shift: selectDocStart },
6246
6369
  { key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true },
6247
6370
  { key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd },
6248
- { key: "Enter", run: insertNewlineAndIndent },
6371
+ { key: "Enter", run: insertNewlineAndIndent, shift: insertNewlineAndIndent },
6249
6372
  { key: "Mod-a", run: selectAll },
6250
6373
  { key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward },
6251
6374
  { key: "Delete", run: deleteCharForward },
@@ -9628,8 +9751,8 @@ class StreamLanguage extends Language {
9628
9751
  return new Parse(self, input, fragments, ranges);
9629
9752
  }
9630
9753
  };
9631
- super(data, impl, [indentService.of((cx, pos) => this.getIndent(cx, pos))], parser.name);
9632
- this.topNode = docID(data);
9754
+ super(data, impl, [], parser.name);
9755
+ this.topNode = docID(data, this);
9633
9756
  self = this;
9634
9757
  this.streamParser = p;
9635
9758
  this.stateAfter = new dist/* NodeProp */.uY({ perNode: true });
@@ -9639,20 +9762,18 @@ class StreamLanguage extends Language {
9639
9762
  Define a stream language.
9640
9763
  */
9641
9764
  static define(spec) { return new StreamLanguage(spec); }
9642
- getIndent(cx, pos) {
9643
- let tree = syntaxTree(cx.state), at = tree.resolve(pos);
9644
- while (at && at.type != this.topNode)
9645
- at = at.parent;
9646
- if (!at)
9647
- return null;
9765
+ /**
9766
+ @internal
9767
+ */
9768
+ getIndent(cx) {
9648
9769
  let from = undefined;
9649
9770
  let { overrideIndentation } = cx.options;
9650
9771
  if (overrideIndentation) {
9651
9772
  from = IndentedFrom.get(cx.state);
9652
- if (from != null && from < pos - 1e4)
9773
+ if (from != null && from < cx.pos - 1e4)
9653
9774
  from = undefined;
9654
9775
  }
9655
- let start = findState(this, tree, 0, at.from, from !== null && from !== void 0 ? from : pos), statePos, state;
9776
+ let start = findState(this, cx.node.tree, 0, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
9656
9777
  if (start) {
9657
9778
  state = start.state;
9658
9779
  statePos = start.pos + 1;
@@ -9661,10 +9782,10 @@ class StreamLanguage extends Language {
9661
9782
  state = this.streamParser.startState(cx.unit);
9662
9783
  statePos = 0;
9663
9784
  }
9664
- if (pos - statePos > 10000 /* C.MaxIndentScanDist */)
9785
+ if (cx.pos - statePos > 10000 /* C.MaxIndentScanDist */)
9665
9786
  return null;
9666
- while (statePos < pos) {
9667
- let line = cx.state.doc.lineAt(statePos), end = Math.min(pos, line.to);
9787
+ while (statePos < cx.pos) {
9788
+ let line = cx.state.doc.lineAt(statePos), end = Math.min(cx.pos, line.to);
9668
9789
  if (line.length) {
9669
9790
  let indentation = overrideIndentation ? overrideIndentation(line.from) : -1;
9670
9791
  let stream = new StringStream(line.text, cx.state.tabSize, cx.unit, indentation < 0 ? undefined : indentation);
@@ -9674,11 +9795,11 @@ class StreamLanguage extends Language {
9674
9795
  else {
9675
9796
  this.streamParser.blankLine(state, cx.unit);
9676
9797
  }
9677
- if (end == pos)
9798
+ if (end == cx.pos)
9678
9799
  break;
9679
9800
  statePos = line.to + 1;
9680
9801
  }
9681
- let line = cx.lineAt(pos);
9802
+ let line = cx.lineAt(cx.pos);
9682
9803
  if (overrideIndentation && from == null)
9683
9804
  IndentedFrom.set(cx.state, line.from);
9684
9805
  return this.streamParser.indent(state, /^\s*(.*)/.exec(line.text)[1], cx);
@@ -9700,7 +9821,7 @@ function findState(lang, tree, off, startPos, before) {
9700
9821
  function cutTree(lang, tree, from, to, inside) {
9701
9822
  if (inside && from <= 0 && to >= tree.length)
9702
9823
  return tree;
9703
- if (!inside && tree.type == lang.topNode)
9824
+ if (!inside && from == 0 && tree.type == lang.topNode)
9704
9825
  inside = true;
9705
9826
  for (let i = tree.children.length - 1; i >= 0; i--) {
9706
9827
  let pos = tree.positions[i], child = tree.children[i], inner;
@@ -9713,11 +9834,11 @@ function cutTree(lang, tree, from, to, inside) {
9713
9834
  }
9714
9835
  return null;
9715
9836
  }
9716
- function findStartInFragments(lang, fragments, startPos, editorState) {
9837
+ function findStartInFragments(lang, fragments, startPos, endPos, editorState) {
9717
9838
  for (let f of fragments) {
9718
9839
  let from = f.from + (f.openStart ? 25 : 0), to = f.to - (f.openEnd ? 25 : 0);
9719
9840
  let found = from <= startPos && to > startPos && findState(lang, f.tree, 0 - f.offset, startPos, to), tree;
9720
- if (found && (tree = cutTree(lang, f.tree, startPos + f.offset, found.pos + f.offset, false)))
9841
+ if (found && found.pos <= endPos && (tree = cutTree(lang, f.tree, startPos + f.offset, found.pos + f.offset, false)))
9721
9842
  return { state: found.state, tree };
9722
9843
  }
9723
9844
  return { state: lang.streamParser.startState(editorState ? getIndentUnit(editorState) : 4), tree: dist/* Tree */.PH.empty };
@@ -9736,14 +9857,15 @@ class Parse {
9736
9857
  this.rangeIndex = 0;
9737
9858
  this.to = ranges[ranges.length - 1].to;
9738
9859
  let context = ParseContext.get(), from = ranges[0].from;
9739
- let { state, tree } = findStartInFragments(lang, fragments, from, context === null || context === void 0 ? void 0 : context.state);
9860
+ let { state, tree } = findStartInFragments(lang, fragments, from, this.to, context === null || context === void 0 ? void 0 : context.state);
9740
9861
  this.state = state;
9741
9862
  this.parsedPos = this.chunkStart = from + tree.length;
9742
9863
  for (let i = 0; i < tree.children.length; i++) {
9743
9864
  this.chunks.push(tree.children[i]);
9744
9865
  this.chunkPos.push(tree.positions[i]);
9745
9866
  }
9746
- if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */) {
9867
+ if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */ &&
9868
+ ranges.some(r => r.from <= context.viewport.from && r.to >= context.viewport.from)) {
9747
9869
  this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
9748
9870
  context.skipUntilInView(this.parsedPos, context.viewport.from);
9749
9871
  this.parsedPos = context.viewport.from;
@@ -9814,7 +9936,8 @@ class Parse {
9814
9936
  while (this.ranges[this.rangeIndex].to < this.parsedPos)
9815
9937
  this.rangeIndex++;
9816
9938
  }
9817
- emitToken(id, from, to, size, offset) {
9939
+ emitToken(id, from, to, offset) {
9940
+ let size = 4;
9818
9941
  if (this.ranges.length > 1) {
9819
9942
  offset = this.skipGapsTo(from, offset, 1);
9820
9943
  from += offset;
@@ -9823,7 +9946,11 @@ class Parse {
9823
9946
  to += offset;
9824
9947
  size += this.chunk.length - len0;
9825
9948
  }
9826
- this.chunk.push(id, from, to, size);
9949
+ let last = this.chunk.length - 4;
9950
+ if (size == 4 && last >= 0 && this.chunk[last] == id && this.chunk[last + 2] == from)
9951
+ this.chunk[last + 2] = to;
9952
+ else
9953
+ this.chunk.push(id, from, to, size);
9827
9954
  return offset;
9828
9955
  }
9829
9956
  parseLine(context) {
@@ -9836,7 +9963,7 @@ class Parse {
9836
9963
  while (!stream.eol()) {
9837
9964
  let token = readToken(streamParser.token, stream, this.state);
9838
9965
  if (token)
9839
- offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, 4, offset);
9966
+ offset = this.emitToken(this.lang.tokenTable.resolve(token), this.parsedPos + stream.start, this.parsedPos + stream.pos, offset);
9840
9967
  if (stream.start > 10000 /* C.MaxLineLength */)
9841
9968
  break;
9842
9969
  }
@@ -9953,8 +10080,11 @@ function createTokenType(extra, tagStr) {
9953
10080
  typeArray.push(type);
9954
10081
  return type.id;
9955
10082
  }
9956
- function docID(data) {
9957
- let type = dist/* NodeType */.Z6.define({ id: typeArray.length, name: "Document", props: [languageDataProp.add(() => data)], top: true });
10083
+ function docID(data, lang) {
10084
+ let type = dist/* NodeType */.Z6.define({ id: typeArray.length, name: "Document", props: [
10085
+ languageDataProp.add(() => data),
10086
+ indentNodeProp.add(() => cx => lang.getIndent(cx))
10087
+ ], top: true });
9958
10088
  typeArray.push(type);
9959
10089
  return type;
9960
10090
  }
@@ -11245,7 +11375,7 @@ class TreeCursor {
11245
11375
  */
11246
11376
  next(enter = true) { return this.move(1, enter); }
11247
11377
  /**
11248
- Move to the next node in a last-to-first pre-order traveral. A
11378
+ Move to the next node in a last-to-first pre-order traversal. A
11249
11379
  node is followed by its last child or, if it has none, its
11250
11380
  previous sibling or the previous sibling of the first parent
11251
11381
  node that has one.
@@ -11321,10 +11451,10 @@ class TreeCursor {
11321
11451
  if (mustLeave && leave)
11322
11452
  leave(this);
11323
11453
  mustLeave = this.type.isAnonymous;
11324
- if (this.nextSibling())
11325
- break;
11326
11454
  if (!depth)
11327
11455
  return;
11456
+ if (this.nextSibling())
11457
+ break;
11328
11458
  this.parent();
11329
11459
  depth--;
11330
11460
  mustLeave = true;
@@ -12335,37 +12465,37 @@ function enterFragments(mounts, ranges) {
12335
12465
  var __webpack_exports__ = {};
12336
12466
  __webpack_require__.r(__webpack_exports__);
12337
12467
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
12338
- /* harmony export */ basicSetup: () => (/* reexport safe */ _uiw_codemirror_extensions_basic_setup__WEBPACK_IMPORTED_MODULE_5__.o),
12339
- /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
12340
- /* harmony export */ getStatistics: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_7__.m),
12341
- /* harmony export */ minimalSetup: () => (/* reexport safe */ _uiw_codemirror_extensions_basic_setup__WEBPACK_IMPORTED_MODULE_5__.V),
12342
- /* harmony export */ useCodeMirror: () => (/* reexport safe */ _useCodeMirror__WEBPACK_IMPORTED_MODULE_1__.q)
12468
+ /* harmony export */ basicSetup: () => (/* reexport safe */ src_uiw_codemirror_extensions_basic_setup_WEBPACK_IMPORTED_MODULE_5_.o),
12469
+ /* harmony export */ "default": () => (src),
12470
+ /* harmony export */ getStatistics: () => (/* reexport safe */ src_utils_WEBPACK_IMPORTED_MODULE_7_.m),
12471
+ /* harmony export */ minimalSetup: () => (/* reexport safe */ src_uiw_codemirror_extensions_basic_setup_WEBPACK_IMPORTED_MODULE_5_.V),
12472
+ /* harmony export */ useCodeMirror: () => (/* reexport safe */ src_useCodeMirror_WEBPACK_IMPORTED_MODULE_1_.q)
12343
12473
  /* harmony export */ });
12344
- /* harmony import */ var _home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(957);
12345
- /* harmony import */ var _home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectWithoutProperties_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(644);
12346
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(442);
12347
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
12348
- /* harmony import */ var _useCodeMirror__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(695);
12349
- /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(742);
12350
- /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__);
12351
- /* harmony import */ var _codemirror_view__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(730);
12352
- /* harmony import */ var _codemirror_view__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_codemirror_view__WEBPACK_IMPORTED_MODULE_3__);
12353
- /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
12354
- /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _codemirror_view__WEBPACK_IMPORTED_MODULE_3__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _codemirror_view__WEBPACK_IMPORTED_MODULE_3__[__WEBPACK_IMPORT_KEY__]
12355
- /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
12356
- /* harmony import */ var _codemirror_state__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(60);
12357
- /* harmony import */ var _codemirror_state__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_codemirror_state__WEBPACK_IMPORTED_MODULE_4__);
12358
- /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
12359
- /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _codemirror_state__WEBPACK_IMPORTED_MODULE_4__) if(__WEBPACK_IMPORT_KEY__ !== "default") __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _codemirror_state__WEBPACK_IMPORTED_MODULE_4__[__WEBPACK_IMPORT_KEY__]
12360
- /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
12361
- /* harmony import */ var _uiw_codemirror_extensions_basic_setup__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(368);
12362
- /* harmony import */ var _getDefaultExtensions__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(89);
12363
- /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
12364
- /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in _getDefaultExtensions__WEBPACK_IMPORTED_MODULE_6__) if(["default","basicSetup","minimalSetup","useCodeMirror"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = () => _getDefaultExtensions__WEBPACK_IMPORTED_MODULE_6__[__WEBPACK_IMPORT_KEY__]
12365
- /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
12366
- /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(369);
12367
- var _excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var ReactCodeMirror=/*#__PURE__*/(0,react__WEBPACK_IMPORTED_MODULE_0__.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=(0,_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectWithoutProperties_js__WEBPACK_IMPORTED_MODULE_8__/* ["default"] */ .A)(props,_excluded);var editor=(0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);var _useCodeMirror=(0,_useCodeMirror__WEBPACK_IMPORTED_MODULE_1__/* .useCodeMirror */ .q)({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container;(0,react__WEBPACK_IMPORTED_MODULE_0__.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
12368
- if(typeof value!=='string'){throw new Error("value must be typeof string but got ".concat(typeof value));}var defaultClassNames=typeof theme==='string'?"cm-theme-".concat(theme):'cm-theme';return/*#__PURE__*/(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_2__.jsx)("div",(0,_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectSpread2_js__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .A)({ref:editor,className:"".concat(defaultClassNames).concat(className?" ".concat(className):'')},other));});ReactCodeMirror.displayName='CodeMirror';/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ReactCodeMirror);
12474
+ /* harmony import */ var src_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectSpread2_js_WEBPACK_IMPORTED_MODULE_9_ = __webpack_require__(957);
12475
+ /* harmony import */ var src_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectWithoutProperties_js_WEBPACK_IMPORTED_MODULE_8_ = __webpack_require__(644);
12476
+ /* harmony import */ var src_react_WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(442);
12477
+ /* harmony import */ var src_react_WEBPACK_IMPORTED_MODULE_0_default = /*#__PURE__*/__webpack_require__.n(src_react_WEBPACK_IMPORTED_MODULE_0_);
12478
+ /* harmony import */ var src_useCodeMirror_WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(695);
12479
+ /* harmony import */ var src_react_jsx_runtime_WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(742);
12480
+ /* harmony import */ var src_react_jsx_runtime_WEBPACK_IMPORTED_MODULE_2_default = /*#__PURE__*/__webpack_require__.n(src_react_jsx_runtime_WEBPACK_IMPORTED_MODULE_2_);
12481
+ /* harmony import */ var src_codemirror_view_WEBPACK_IMPORTED_MODULE_3_ = __webpack_require__(730);
12482
+ /* harmony import */ var src_codemirror_view_WEBPACK_IMPORTED_MODULE_3_default = /*#__PURE__*/__webpack_require__.n(src_codemirror_view_WEBPACK_IMPORTED_MODULE_3_);
12483
+ /* harmony reexport (unknown) */ var src_WEBPACK_REEXPORT_OBJECT_ = {};
12484
+ /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in src_codemirror_view_WEBPACK_IMPORTED_MODULE_3_) if(__WEBPACK_IMPORT_KEY__ !== "default") src_WEBPACK_REEXPORT_OBJECT_[__WEBPACK_IMPORT_KEY__] = () => src_codemirror_view_WEBPACK_IMPORTED_MODULE_3_[__WEBPACK_IMPORT_KEY__]
12485
+ /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, src_WEBPACK_REEXPORT_OBJECT_);
12486
+ /* harmony import */ var src_codemirror_state_WEBPACK_IMPORTED_MODULE_4_ = __webpack_require__(60);
12487
+ /* harmony import */ var src_codemirror_state_WEBPACK_IMPORTED_MODULE_4_default = /*#__PURE__*/__webpack_require__.n(src_codemirror_state_WEBPACK_IMPORTED_MODULE_4_);
12488
+ /* harmony reexport (unknown) */ var src_WEBPACK_REEXPORT_OBJECT_ = {};
12489
+ /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in src_codemirror_state_WEBPACK_IMPORTED_MODULE_4_) if(__WEBPACK_IMPORT_KEY__ !== "default") src_WEBPACK_REEXPORT_OBJECT_[__WEBPACK_IMPORT_KEY__] = () => src_codemirror_state_WEBPACK_IMPORTED_MODULE_4_[__WEBPACK_IMPORT_KEY__]
12490
+ /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, src_WEBPACK_REEXPORT_OBJECT_);
12491
+ /* harmony import */ var src_uiw_codemirror_extensions_basic_setup_WEBPACK_IMPORTED_MODULE_5_ = __webpack_require__(368);
12492
+ /* harmony import */ var src_getDefaultExtensions_WEBPACK_IMPORTED_MODULE_6_ = __webpack_require__(89);
12493
+ /* harmony reexport (unknown) */ var src_WEBPACK_REEXPORT_OBJECT_ = {};
12494
+ /* harmony reexport (unknown) */ for(const __WEBPACK_IMPORT_KEY__ in src_getDefaultExtensions_WEBPACK_IMPORTED_MODULE_6_) if(["default","basicSetup","minimalSetup","useCodeMirror"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) src_WEBPACK_REEXPORT_OBJECT_[__WEBPACK_IMPORT_KEY__] = () => src_getDefaultExtensions_WEBPACK_IMPORTED_MODULE_6_[__WEBPACK_IMPORT_KEY__]
12495
+ /* harmony reexport (unknown) */ __webpack_require__.d(__webpack_exports__, src_WEBPACK_REEXPORT_OBJECT_);
12496
+ /* harmony import */ var src_utils_WEBPACK_IMPORTED_MODULE_7_ = __webpack_require__(369);
12497
+ var src_excluded=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"];var src_ReactCodeMirror=/*#__PURE__*/(0,src_react_WEBPACK_IMPORTED_MODULE_0_.forwardRef)(function(props,ref){var className=props.className,_props$value=props.value,value=_props$value===void 0?'':_props$value,selection=props.selection,_props$extensions=props.extensions,extensions=_props$extensions===void 0?[]:_props$extensions,onChange=props.onChange,onStatistics=props.onStatistics,onCreateEditor=props.onCreateEditor,onUpdate=props.onUpdate,autoFocus=props.autoFocus,_props$theme=props.theme,theme=_props$theme===void 0?'light':_props$theme,height=props.height,minHeight=props.minHeight,maxHeight=props.maxHeight,width=props.width,minWidth=props.minWidth,maxWidth=props.maxWidth,basicSetup=props.basicSetup,placeholder=props.placeholder,indentWithTab=props.indentWithTab,editable=props.editable,readOnly=props.readOnly,root=props.root,initialState=props.initialState,other=(0,src_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectWithoutProperties_js_WEBPACK_IMPORTED_MODULE_8_/* ["default"] */ .A)(props,src_excluded);var editor=(0,src_react_WEBPACK_IMPORTED_MODULE_0_.useRef)(null);var _useCodeMirror=(0,src_useCodeMirror_WEBPACK_IMPORTED_MODULE_1_/* .useCodeMirror */ .q)({container:editor.current,root:root,value:value,autoFocus:autoFocus,theme:theme,height:height,minHeight:minHeight,maxHeight:maxHeight,width:width,minWidth:minWidth,maxWidth:maxWidth,basicSetup:basicSetup,placeholder:placeholder,indentWithTab:indentWithTab,editable:editable,readOnly:readOnly,selection:selection,onChange:onChange,onStatistics:onStatistics,onCreateEditor:onCreateEditor,onUpdate:onUpdate,extensions:extensions,initialState:initialState}),state=_useCodeMirror.state,view=_useCodeMirror.view,container=_useCodeMirror.container;(0,src_react_WEBPACK_IMPORTED_MODULE_0_.useImperativeHandle)(ref,function(){return{editor:editor.current,state:state,view:view};},[editor,container,state,view]);// check type of value
12498
+ if(typeof value!=='string'){throw new Error("value must be typeof string but got ".concat(typeof value));}var defaultClassNames=typeof theme==='string'?"cm-theme-".concat(theme):'cm-theme';return/*#__PURE__*/(0,src_react_jsx_runtime_WEBPACK_IMPORTED_MODULE_2_.jsx)("div",(0,src_home_runner_work_react_codemirror_react_codemirror_node_modules_babel_runtime_helpers_esm_objectSpread2_js_WEBPACK_IMPORTED_MODULE_9_/* ["default"] */ .A)({ref:editor,className:"".concat(defaultClassNames).concat(className?" ".concat(className):'')},other));});src_ReactCodeMirror.displayName='CodeMirror';/* harmony default export */ const src = (src_ReactCodeMirror);
12369
12499
  /******/ return __webpack_exports__;
12370
12500
  /******/ })()
12371
12501
  ;