@uiw/react-codemirror 4.12.2 → 4.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -114,6 +114,7 @@ export default function App() {
114
114
  ```
115
115
 
116
116
  - ~~`@codemirror/legacy-modes/mode/cpp`~~ => [`@codemirror/lang-cpp`](https://www.npmjs.com/package/@codemirror/lang-cpp)
117
+ - ~~`@codemirror/legacy-modes/mode/css`~~ => [`@codemirror/lang-css`](https://www.npmjs.com/package/@codemirror/lang-css)
117
118
  - ~~`@codemirror/legacy-modes/mode/html`~~ => [`@codemirror/lang-html`](https://www.npmjs.com/package/@codemirror/lang-html)
118
119
  - ~~`@codemirror/legacy-modes/mode/java`~~ => [`@codemirror/lang-java`](https://www.npmjs.com/package/@codemirror/lang-java)
119
120
  - ~~`@codemirror/legacy-modes/mode/javascript`~~ => [`@codemirror/lang-javascript`](https://www.npmjs.com/package/@codemirror/lang-javascript)
@@ -125,6 +126,7 @@ export default function App() {
125
126
  - ~~`@codemirror/legacy-modes/mode/rust`~~ => [`@codemirror/lang-rust`](https://www.npmjs.com/package/@codemirror/lang-rust)
126
127
  - ~~`@codemirror/legacy-modes/mode/sql`~~ => [`@codemirror/lang-sql`](https://www.npmjs.com/package/@codemirror/lang-sql)
127
128
  - ~~`@codemirror/legacy-modes/mode/xml`~~ => [`@codemirror/lang-xml`](https://www.npmjs.com/package/@codemirror/lang-xml)
129
+ - ~~`@codemirror/legacy-modes/mode/wast`~~ => [`@codemirror/lang-wast`](https://www.npmjs.com/package/@codemirror/lang-wast)
128
130
 
129
131
  ### Markdown Example
130
132
 
package/dist/mdeditor.js CHANGED
@@ -2314,6 +2314,8 @@ class Rule {
2314
2314
  this.context = context;
2315
2315
  this.next = next;
2316
2316
  }
2317
+ get opaque() { return this.mode == 0 /* Opaque */; }
2318
+ get inherit() { return this.mode == 1 /* Inherit */; }
2317
2319
  sort(other) {
2318
2320
  if (!other || other.depth < this.depth) {
2319
2321
  this.next = other;
@@ -2324,6 +2326,7 @@ class Rule {
2324
2326
  }
2325
2327
  get depth() { return this.context ? this.context.length : 0; }
2326
2328
  }
2329
+ Rule.empty = new Rule([], 2 /* Normal */, null);
2327
2330
  /// Define a [highlighter](#highlight.Highlighter) from an array of
2328
2331
  /// tag/class pairs. Classes associated with more specific tags will
2329
2332
  /// take precedence.
@@ -2351,7 +2354,7 @@ function tagHighlighter(tags, options) {
2351
2354
  }
2352
2355
  return cls;
2353
2356
  },
2354
- scope: scope
2357
+ scope
2355
2358
  };
2356
2359
  }
2357
2360
  function highlightTags(highlighters, tags) {
@@ -2404,25 +2407,17 @@ class HighlightBuilder {
2404
2407
  if (type.isTop)
2405
2408
  highlighters = this.highlighters.filter(h => !h.scope || h.scope(type));
2406
2409
  let cls = inheritedClass;
2407
- let rule = type.prop(ruleNodeProp), opaque = false;
2408
- while (rule) {
2409
- if (!rule.context || cursor.matchContext(rule.context)) {
2410
- let tagCls = highlightTags(highlighters, rule.tags);
2411
- if (tagCls) {
2412
- if (cls)
2413
- cls += " ";
2414
- cls += tagCls;
2415
- if (rule.mode == 1 /* Inherit */)
2416
- inheritedClass += (inheritedClass ? " " : "") + tagCls;
2417
- else if (rule.mode == 0 /* Opaque */)
2418
- opaque = true;
2419
- }
2420
- break;
2421
- }
2422
- rule = rule.next;
2410
+ let rule = getStyleTags(cursor) || Rule.empty;
2411
+ let tagCls = highlightTags(highlighters, rule.tags);
2412
+ if (tagCls) {
2413
+ if (cls)
2414
+ cls += " ";
2415
+ cls += tagCls;
2416
+ if (rule.mode == 1 /* Inherit */)
2417
+ inheritedClass += (inheritedClass ? " " : "") + tagCls;
2423
2418
  }
2424
2419
  this.startSpan(cursor.from, cls);
2425
- if (opaque)
2420
+ if (rule.opaque)
2426
2421
  return;
2427
2422
  let mounted = cursor.tree && cursor.tree.prop(dist_NodeProp.mounted);
2428
2423
  if (mounted && mounted.overlay) {
@@ -2465,6 +2460,15 @@ class HighlightBuilder {
2465
2460
  }
2466
2461
  }
2467
2462
  }
2463
+ /// Match a syntax node's [highlight rules](#highlight.styleTags). If
2464
+ /// there's a match, return its set of tags, and whether it is
2465
+ /// opaque (uses a `!`) or applies to all child nodes (`/...`).
2466
+ function getStyleTags(node) {
2467
+ let rule = node.type.prop(ruleNodeProp);
2468
+ while (rule && rule.context && !node.matchContext(rule.context))
2469
+ rule = rule.next;
2470
+ return rule || null;
2471
+ }
2468
2472
  const t = Tag.define;
2469
2473
  const comment = t(), dist_name = t(), typeName = t(dist_name), propertyName = t(dist_name), literal = t(), string = t(literal), number = t(literal), content = t(), heading = t(content), keyword = t(), operator = t(), punctuation = t(), bracket = t(punctuation), meta = t();
2470
2474
  /// The default set of highlighting [tags](#highlight.Tag).
@@ -2565,7 +2569,7 @@ const tags = {
2565
2569
  moduleKeyword: t(keyword),
2566
2570
  /// An operator.
2567
2571
  operator,
2568
- /// An [operator](#highlight.tags.operator) that defines something.
2572
+ /// An [operator](#highlight.tags.operator) that dereferences something.
2569
2573
  derefOperator: t(operator),
2570
2574
  /// Arithmetic-related [operator](#highlight.tags.operator).
2571
2575
  arithmeticOperator: t(operator),
@@ -5319,35 +5323,35 @@ The line comment syntax is taken from the
5319
5323
  [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
5320
5324
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
5321
5325
  */
5322
- const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* Toggle */);
5326
+ const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* CommentOption.Toggle */);
5323
5327
  /**
5324
5328
  Comment the current selection using line comments.
5325
5329
  */
5326
- const lineComment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeLineComment, 1 /* Comment */)));
5330
+ const lineComment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeLineComment, 1 /* CommentOption.Comment */)));
5327
5331
  /**
5328
5332
  Uncomment the current selection using line comments.
5329
5333
  */
5330
- const lineUncomment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeLineComment, 2 /* Uncomment */)));
5334
+ const lineUncomment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeLineComment, 2 /* CommentOption.Uncomment */)));
5331
5335
  /**
5332
5336
  Comment or uncomment the current selection using block comments.
5333
5337
  The block comment syntax is taken from the
5334
5338
  [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
5335
5339
  data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
5336
5340
  */
5337
- const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* Toggle */);
5341
+ const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* CommentOption.Toggle */);
5338
5342
  /**
5339
5343
  Comment the current selection using block comments.
5340
5344
  */
5341
- const blockComment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeBlockComment, 1 /* Comment */)));
5345
+ const blockComment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeBlockComment, 1 /* CommentOption.Comment */)));
5342
5346
  /**
5343
5347
  Uncomment the current selection using block comments.
5344
5348
  */
5345
- const blockUncomment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeBlockComment, 2 /* Uncomment */)));
5349
+ const blockUncomment = /*@__PURE__*/(/* unused pure expression or super */ null && (command(changeBlockComment, 2 /* CommentOption.Uncomment */)));
5346
5350
  /**
5347
5351
  Comment or uncomment the lines around the current selection using
5348
5352
  block comments.
5349
5353
  */
5350
- const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* Toggle */);
5354
+ const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* CommentOption.Toggle */);
5351
5355
  function getConfig(state, pos = state.selection.main.head) {
5352
5356
  let data = state.languageDataAt("commentTokens", pos);
5353
5357
  return data.length ? data[0] : {};
@@ -5406,14 +5410,14 @@ function changeBlockComment(option, state, ranges = state.selection.ranges) {
5406
5410
  if (!tokens.every(c => c))
5407
5411
  return null;
5408
5412
  let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
5409
- if (option != 2 /* Uncomment */ && !comments.every(c => c)) {
5413
+ if (option != 2 /* CommentOption.Uncomment */ && !comments.every(c => c)) {
5410
5414
  return { changes: state.changes(ranges.map((range, i) => {
5411
5415
  if (comments[i])
5412
5416
  return [];
5413
5417
  return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }];
5414
5418
  })) };
5415
5419
  }
5416
- else if (option != 1 /* Comment */ && comments.some(c => c)) {
5420
+ else if (option != 1 /* CommentOption.Comment */ && comments.some(c => c)) {
5417
5421
  let changes = [];
5418
5422
  for (let i = 0, comment; i < comments.length; i++)
5419
5423
  if (comment = comments[i]) {
@@ -5453,7 +5457,7 @@ function changeLineComment(option, state, ranges = state.selection.ranges) {
5453
5457
  if (lines.length == startI + 1)
5454
5458
  lines[startI].single = true;
5455
5459
  }
5456
- if (option != 2 /* Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
5460
+ if (option != 2 /* CommentOption.Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
5457
5461
  let changes = [];
5458
5462
  for (let { line, token, indent, empty, single } of lines)
5459
5463
  if (single || !empty)
@@ -5461,7 +5465,7 @@ function changeLineComment(option, state, ranges = state.selection.ranges) {
5461
5465
  let changeSet = state.changes(changes);
5462
5466
  return { changes: changeSet, selection: state.selection.map(changeSet, 1) };
5463
5467
  }
5464
- else if (option != 1 /* Comment */ && lines.some(l => l.comment >= 0)) {
5468
+ else if (option != 1 /* CommentOption.Comment */ && lines.some(l => l.comment >= 0)) {
5465
5469
  let changes = [];
5466
5470
  for (let { line, comment, token } of lines)
5467
5471
  if (comment >= 0) {
@@ -5515,12 +5519,12 @@ const historyField_ = /*@__PURE__*/state_.StateField.define({
5515
5519
  if (fromHist) {
5516
5520
  let selection = tr.docChanged ? state_.EditorSelection.single(changeEnd(tr.changes)) : undefined;
5517
5521
  let item = HistEvent.fromTransaction(tr, selection), from = fromHist.side;
5518
- let other = from == 0 /* Done */ ? state.undone : state.done;
5522
+ let other = from == 0 /* BranchName.Done */ ? state.undone : state.done;
5519
5523
  if (item)
5520
5524
  other = updateBranch(other, other.length, config.minDepth, item);
5521
5525
  else
5522
5526
  other = addSelection(other, tr.startState.selection);
5523
- return new HistoryState(from == 0 /* Done */ ? fromHist.rest : other, from == 0 /* Done */ ? other : fromHist.rest);
5527
+ return new HistoryState(from == 0 /* BranchName.Done */ ? fromHist.rest : other, from == 0 /* BranchName.Done */ ? other : fromHist.rest);
5524
5528
  }
5525
5529
  let isolate = tr.annotation(isolateHistory);
5526
5530
  if (isolate == "full" || isolate == "before")
@@ -5588,37 +5592,37 @@ function cmd(side, selection) {
5588
5592
  Undo a single group of history events. Returns false if no group
5589
5593
  was available.
5590
5594
  */
5591
- const undo = /*@__PURE__*/cmd(0 /* Done */, false);
5595
+ const undo = /*@__PURE__*/cmd(0 /* BranchName.Done */, false);
5592
5596
  /**
5593
5597
  Redo a group of history events. Returns false if no group was
5594
5598
  available.
5595
5599
  */
5596
- const redo = /*@__PURE__*/cmd(1 /* Undone */, false);
5600
+ const redo = /*@__PURE__*/cmd(1 /* BranchName.Undone */, false);
5597
5601
  /**
5598
5602
  Undo a change or selection change.
5599
5603
  */
5600
- const undoSelection = /*@__PURE__*/cmd(0 /* Done */, true);
5604
+ const undoSelection = /*@__PURE__*/cmd(0 /* BranchName.Done */, true);
5601
5605
  /**
5602
5606
  Redo a change or selection change.
5603
5607
  */
5604
- const redoSelection = /*@__PURE__*/cmd(1 /* Undone */, true);
5608
+ const redoSelection = /*@__PURE__*/cmd(1 /* BranchName.Undone */, true);
5605
5609
  function depth(side) {
5606
5610
  return function (state) {
5607
5611
  let histState = state.field(historyField_, false);
5608
5612
  if (!histState)
5609
5613
  return 0;
5610
- let branch = side == 0 /* Done */ ? histState.done : histState.undone;
5614
+ let branch = side == 0 /* BranchName.Done */ ? histState.done : histState.undone;
5611
5615
  return branch.length - (branch.length && !branch[0].changes ? 1 : 0);
5612
5616
  };
5613
5617
  }
5614
5618
  /**
5615
5619
  The amount of undoable change events available in a given state.
5616
5620
  */
5617
- const undoDepth = /*@__PURE__*/(/* unused pure expression or super */ null && (depth(0 /* Done */)));
5621
+ const undoDepth = /*@__PURE__*/(/* unused pure expression or super */ null && (depth(0 /* BranchName.Done */)));
5618
5622
  /**
5619
5623
  The amount of redoable change events available in a given state.
5620
5624
  */
5621
- const redoDepth = /*@__PURE__*/(/* unused pure expression or super */ null && (depth(1 /* Undone */)));
5625
+ const redoDepth = /*@__PURE__*/(/* unused pure expression or super */ null && (depth(1 /* BranchName.Undone */)));
5622
5626
  // History events store groups of changes or effects that need to be
5623
5627
  // undone/redone together.
5624
5628
  class HistEvent {
@@ -5796,7 +5800,7 @@ class HistoryState {
5796
5800
  return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
5797
5801
  }
5798
5802
  pop(side, state, selection) {
5799
- let branch = side == 0 /* Done */ ? this.done : this.undone;
5803
+ let branch = side == 0 /* BranchName.Done */ ? this.done : this.undone;
5800
5804
  if (branch.length == 0)
5801
5805
  return null;
5802
5806
  let event = branch[branch.length - 1];
@@ -5804,7 +5808,7 @@ class HistoryState {
5804
5808
  return state.update({
5805
5809
  selection: event.selectionsAfter[event.selectionsAfter.length - 1],
5806
5810
  annotations: fromHistory.of({ side, rest: popSelection(branch) }),
5807
- userEvent: side == 0 /* Done */ ? "select.undo" : "select.redo",
5811
+ userEvent: side == 0 /* BranchName.Done */ ? "select.undo" : "select.redo",
5808
5812
  scrollIntoView: true
5809
5813
  });
5810
5814
  }
@@ -5821,7 +5825,7 @@ class HistoryState {
5821
5825
  effects: event.effects,
5822
5826
  annotations: fromHistory.of({ side, rest }),
5823
5827
  filter: false,
5824
- userEvent: side == 0 /* Done */ ? "undo" : "redo",
5828
+ userEvent: side == 0 /* BranchName.Done */ ? "undo" : "redo",
5825
5829
  scrollIntoView: true
5826
5830
  });
5827
5831
  }
@@ -6288,26 +6292,34 @@ const simplifySelection = ({ state, dispatch }) => {
6288
6292
  dispatch(setSel(state, selection));
6289
6293
  return true;
6290
6294
  };
6291
- function deleteBy({ state, dispatch }, by) {
6292
- if (state.readOnly)
6295
+ function deleteBy(target, by) {
6296
+ if (target.state.readOnly)
6293
6297
  return false;
6294
- let event = "delete.selection";
6298
+ let event = "delete.selection", { state } = target;
6295
6299
  let changes = state.changeByRange(range => {
6296
6300
  let { from, to } = range;
6297
6301
  if (from == to) {
6298
6302
  let towards = by(from);
6299
- if (towards < from)
6303
+ if (towards < from) {
6300
6304
  event = "delete.backward";
6301
- else if (towards > from)
6305
+ towards = skipAtomic(target, towards, false);
6306
+ }
6307
+ else if (towards > from) {
6302
6308
  event = "delete.forward";
6309
+ towards = skipAtomic(target, towards, true);
6310
+ }
6303
6311
  from = Math.min(from, towards);
6304
6312
  to = Math.max(to, towards);
6305
6313
  }
6314
+ else {
6315
+ from = skipAtomic(target, from, false);
6316
+ to = skipAtomic(target, from, true);
6317
+ }
6306
6318
  return from == to ? { range } : { changes: { from, to }, range: state_.EditorSelection.cursor(from) };
6307
6319
  });
6308
6320
  if (changes.changes.empty)
6309
6321
  return false;
6310
- dispatch(state.update(changes, {
6322
+ target.dispatch(state.update(changes, {
6311
6323
  scrollIntoView: true,
6312
6324
  userEvent: event,
6313
6325
  effects: event == "delete.selection" ? view_.EditorView.announce.of(state.phrase("Selection deleted")) : undefined
@@ -6339,7 +6351,7 @@ const deleteByChar = (target, forward) => deleteBy(target, pos => {
6339
6351
  if (targetPos == pos && line.number != (forward ? state.doc.lines : 1))
6340
6352
  targetPos += forward ? 1 : -1;
6341
6353
  }
6342
- return skipAtomic(target, targetPos, forward);
6354
+ return targetPos;
6343
6355
  });
6344
6356
  /**
6345
6357
  Delete the selection, or, for cursor selections, the character
@@ -6368,7 +6380,7 @@ const deleteByGroup = (target, forward) => deleteBy(target, start => {
6368
6380
  cat = nextCat;
6369
6381
  pos = next;
6370
6382
  }
6371
- return skipAtomic(target, pos, forward);
6383
+ return pos;
6372
6384
  });
6373
6385
  /**
6374
6386
  Delete the selection or backward until the end of the next
@@ -6387,7 +6399,7 @@ line, delete the line break after it.
6387
6399
  */
6388
6400
  const deleteToLineEnd = view => deleteBy(view, pos => {
6389
6401
  let lineEnd = view.lineBlockAt(pos).to;
6390
- return skipAtomic(view, pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1), true);
6402
+ return pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1);
6391
6403
  });
6392
6404
  /**
6393
6405
  Delete the selection, or, if it is a cursor selection, delete to
@@ -6396,7 +6408,7 @@ line, delete the line break before it.
6396
6408
  */
6397
6409
  const deleteToLineStart = view => deleteBy(view, pos => {
6398
6410
  let lineStart = view.lineBlockAt(pos).from;
6399
- return skipAtomic(view, pos > lineStart ? lineStart : Math.max(0, pos - 1), false);
6411
+ return pos > lineStart ? lineStart : Math.max(0, pos - 1);
6400
6412
  });
6401
6413
  /**
6402
6414
  Delete all whitespace directly before a line end from the
@@ -7129,7 +7141,7 @@ class MultilineRegExpCursor {
7129
7141
  this.matchPos = toCharEnd(text, from);
7130
7142
  this.re = new RegExp(query, baseFlags + ((options === null || options === void 0 ? void 0 : options.ignoreCase) ? "i" : ""));
7131
7143
  this.test = options === null || options === void 0 ? void 0 : options.test;
7132
- this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Base */));
7144
+ this.flat = FlattenedDoc.get(text, from, this.chunkEnd(from + 5000 /* Chunk.Base */));
7133
7145
  }
7134
7146
  chunkEnd(pos) {
7135
7147
  return pos >= this.to ? this.to : this.text.lineAt(pos).to;
@@ -7509,10 +7521,10 @@ function stringWordTest(doc, categorizer) {
7509
7521
  bufPos = Math.max(0, from - 2);
7510
7522
  buf = doc.sliceString(bufPos, Math.min(doc.length, to + 2));
7511
7523
  }
7512
- return categorizer(charAfter(buf, from - bufPos)) != state_.CharCategory.Word ||
7513
- categorizer(charBefore(buf, to - bufPos)) != state_.CharCategory.Word ||
7514
- (categorizer(charBefore(buf, from - bufPos)) != state_.CharCategory.Word &&
7515
- categorizer(charAfter(buf, to - bufPos)) != state_.CharCategory.Word);
7524
+ return (categorizer(charBefore(buf, from - bufPos)) != state_.CharCategory.Word ||
7525
+ categorizer(charAfter(buf, from - bufPos)) != state_.CharCategory.Word) &&
7526
+ (categorizer(charAfter(buf, to - bufPos)) != state_.CharCategory.Word ||
7527
+ categorizer(charBefore(buf, to - bufPos)) != state_.CharCategory.Word);
7516
7528
  };
7517
7529
  }
7518
7530
  class StringQuery extends QueryType {
@@ -7529,7 +7541,7 @@ class StringQuery extends QueryType {
7529
7541
  // cursor, done by scanning chunk after chunk forward.
7530
7542
  prevMatchInRange(state, from, to) {
7531
7543
  for (let pos = to;;) {
7532
- let start = Math.max(from, pos - 10000 /* ChunkSize */ - this.spec.unquoted.length);
7544
+ let start = Math.max(from, pos - 10000 /* FindPrev.ChunkSize */ - this.spec.unquoted.length);
7533
7545
  let cursor = stringCursor(this.spec, state, start, pos), range = null;
7534
7546
  while (!cursor.nextOverlapping().done)
7535
7547
  range = cursor.value;
@@ -7537,7 +7549,7 @@ class StringQuery extends QueryType {
7537
7549
  return range;
7538
7550
  if (start == from)
7539
7551
  return null;
7540
- pos -= 10000 /* ChunkSize */;
7552
+ pos -= 10000 /* FindPrev.ChunkSize */;
7541
7553
  }
7542
7554
  }
7543
7555
  prevMatch(state, curFrom, curTo) {
@@ -7574,10 +7586,10 @@ function charAfter(str, index) {
7574
7586
  }
7575
7587
  function regexpWordTest(categorizer) {
7576
7588
  return (_from, _to, match) => !match[0].length ||
7577
- categorizer(charAfter(match.input, match.index)) != state_.CharCategory.Word ||
7578
- categorizer(charBefore(match.input, match.index + match[0].length)) != state_.CharCategory.Word ||
7579
- (categorizer(charBefore(match.input, match.index)) != state_.CharCategory.Word &&
7580
- categorizer(charAfter(match.input, match.index + match[0].length)) != state_.CharCategory.Word);
7589
+ (categorizer(charBefore(match.input, match.index)) != state_.CharCategory.Word ||
7590
+ categorizer(charAfter(match.input, match.index)) != state_.CharCategory.Word) &&
7591
+ (categorizer(charAfter(match.input, match.index + match[0].length)) != state_.CharCategory.Word ||
7592
+ categorizer(charBefore(match.input, match.index + match[0].length)) != state_.CharCategory.Word);
7581
7593
  }
7582
7594
  class RegExpQuery extends QueryType {
7583
7595
  nextMatch(state, curFrom, curTo) {
@@ -7588,7 +7600,7 @@ class RegExpQuery extends QueryType {
7588
7600
  }
7589
7601
  prevMatchInRange(state, from, to) {
7590
7602
  for (let size = 1;; size++) {
7591
- let start = Math.max(from, to - size * 10000 /* ChunkSize */);
7603
+ let start = Math.max(from, to - size * 10000 /* FindPrev.ChunkSize */);
7592
7604
  let cursor = regexpCursor(this.spec, state, start, to), range = null;
7593
7605
  while (!cursor.next().done)
7594
7606
  range = cursor.value;
@@ -7618,7 +7630,7 @@ class RegExpQuery extends QueryType {
7618
7630
  return ranges;
7619
7631
  }
7620
7632
  highlight(state, from, to, add) {
7621
- let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* HighlightMargin */), Math.min(to + 250 /* HighlightMargin */, state.doc.length));
7633
+ let cursor = regexpCursor(this.spec, state, Math.max(0, from - 250 /* RegExp.HighlightMargin */), Math.min(to + 250 /* RegExp.HighlightMargin */, state.doc.length));
7622
7634
  while (!cursor.next().done)
7623
7635
  add(cursor.value.from, cursor.value.to);
7624
7636
  }
@@ -7685,7 +7697,7 @@ const searchHighlighter = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
7685
7697
  let builder = new state_.RangeSetBuilder();
7686
7698
  for (let i = 0, ranges = view.visibleRanges, l = ranges.length; i < l; i++) {
7687
7699
  let { from, to } = ranges[i];
7688
- while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* HighlightMargin */)
7700
+ while (i < l - 1 && to > ranges[i + 1].from - 2 * 250 /* RegExp.HighlightMargin */)
7689
7701
  to = ranges[++i].to;
7690
7702
  query.highlight(view.state, from, to, (from, to) => {
7691
7703
  let selected = view.state.selection.ranges.some(r => r.from == from && r.to == to);
@@ -8406,7 +8418,8 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
8406
8418
  aboveCursor: false,
8407
8419
  icons: true,
8408
8420
  addToOptions: [],
8409
- compareCompletions: (a, b) => a.label.localeCompare(b.label)
8421
+ compareCompletions: (a, b) => a.label.localeCompare(b.label),
8422
+ interactionDelay: 75
8410
8423
  }, {
8411
8424
  defaultKeymap: (a, b) => a && b,
8412
8425
  closeOnBlur: (a, b) => a && b,
@@ -8583,7 +8596,7 @@ class CompletionTooltip {
8583
8596
  let sel = this.dom.querySelector("[aria-selected]");
8584
8597
  if (!sel || !this.info)
8585
8598
  return null;
8586
- let win = this.dom.ownerDocument.defaultView;
8599
+ let win = this.dom.ownerDocument.defaultView || window;
8587
8600
  let listRect = this.dom.getBoundingClientRect();
8588
8601
  let infoRect = this.info.getBoundingClientRect();
8589
8602
  let selRect = sel.getBoundingClientRect();
@@ -8901,7 +8914,6 @@ const completionState = /*@__PURE__*/state_.StateField.define({
8901
8914
  ]
8902
8915
  });
8903
8916
 
8904
- const CompletionInteractMargin = 75;
8905
8917
  /**
8906
8918
  Returns a command that moves the completion selection forward or
8907
8919
  backward by the given amount.
@@ -8909,7 +8921,8 @@ backward by the given amount.
8909
8921
  function moveCompletionSelection(forward, by = "option") {
8910
8922
  return (view) => {
8911
8923
  let cState = view.state.field(completionState, false);
8912
- if (!cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin)
8924
+ if (!cState || !cState.open ||
8925
+ Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
8913
8926
  return false;
8914
8927
  let step = 1, tooltip;
8915
8928
  if (by == "page" && (tooltip = (0,view_.getTooltip)(view, cState.open.tooltip)))
@@ -8930,8 +8943,8 @@ Accept the current completion.
8930
8943
  */
8931
8944
  const acceptCompletion = (view) => {
8932
8945
  let cState = view.state.field(completionState, false);
8933
- if (view.state.readOnly || !cState || !cState.open || Date.now() - cState.open.timestamp < CompletionInteractMargin ||
8934
- cState.open.selected < 0)
8946
+ if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 ||
8947
+ Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
8935
8948
  return false;
8936
8949
  applyCompletion(view, cState.open.options[cState.open.selected]);
8937
8950
  return true;
@@ -9165,6 +9178,7 @@ const autocomplete_dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
9165
9178
  verticalAlign: "text-top",
9166
9179
  width: 0,
9167
9180
  height: "1.15em",
9181
+ display: "inline-block",
9168
9182
  margin: "0 -0.7px -.7em",
9169
9183
  borderLeft: "1.4px dotted #888"
9170
9184
  },
@@ -9548,7 +9562,8 @@ const completeAnyWord = context => {
9548
9562
 
9549
9563
  const defaults = {
9550
9564
  brackets: ["(", "[", "{", "'", '"'],
9551
- before: ")]}:;>"
9565
+ before: ")]}:;>",
9566
+ stringPrefixes: []
9552
9567
  };
9553
9568
  const closeBracketEffect = /*@__PURE__*/state_.StateEffect.define({
9554
9569
  map(value, mapping) {
@@ -9664,7 +9679,7 @@ function insertBracket(state, bracket) {
9664
9679
  for (let tok of tokens) {
9665
9680
  let closed = closing((0,state_.codePointAt)(tok, 0));
9666
9681
  if (bracket == tok)
9667
- return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1)
9682
+ return closed == tok ? handleSame(state, tok, tokens.indexOf(tok + tok + tok) > -1, conf)
9668
9683
  : handleOpen(state, tok, closed, conf.before || defaults.before);
9669
9684
  if (bracket == closed && closedBracketAt(state, state.selection.main.from))
9670
9685
  return handleClose(state, tok, closed);
@@ -9719,13 +9734,14 @@ function handleClose(state, _open, close) {
9719
9734
  }
9720
9735
  // Handles cases where the open and close token are the same, and
9721
9736
  // possibly triple quotes (as in `"""abc"""`-style quoting).
9722
- function handleSame(state, token, allowTriple) {
9737
+ function handleSame(state, token, allowTriple, config) {
9738
+ let stringPrefixes = config.stringPrefixes || defaults.stringPrefixes;
9723
9739
  let dont = null, changes = state.changeByRange(range => {
9724
9740
  if (!range.empty)
9725
9741
  return { changes: [{ insert: token, from: range.from }, { insert: token, from: range.to }],
9726
9742
  effects: closeBracketEffect.of(range.to + token.length),
9727
9743
  range: state_.EditorSelection.range(range.anchor + token.length, range.head + token.length) };
9728
- let pos = range.head, next = nextChar(state.doc, pos);
9744
+ let pos = range.head, next = nextChar(state.doc, pos), start;
9729
9745
  if (next == token) {
9730
9746
  if (nodeStart(state, pos)) {
9731
9747
  return { changes: { insert: token + token, from: pos },
@@ -9739,14 +9755,14 @@ function handleSame(state, token, allowTriple) {
9739
9755
  }
9740
9756
  }
9741
9757
  else if (allowTriple && state.sliceDoc(pos - 2 * token.length, pos) == token + token &&
9742
- nodeStart(state, pos - 2 * token.length)) {
9758
+ (start = canStartStringAt(state, pos - 2 * token.length, stringPrefixes)) > -1 &&
9759
+ nodeStart(state, start)) {
9743
9760
  return { changes: { insert: token + token + token + token, from: pos },
9744
9761
  effects: closeBracketEffect.of(pos + token.length),
9745
9762
  range: state_.EditorSelection.cursor(pos + token.length) };
9746
9763
  }
9747
9764
  else if (state.charCategorizer(pos)(next) != state_.CharCategory.Word) {
9748
- let prev = state.sliceDoc(pos - 1, pos);
9749
- if (prev != token && state.charCategorizer(pos)(prev) != state_.CharCategory.Word && !probablyInString(state, pos, token))
9765
+ if (canStartStringAt(state, pos, stringPrefixes) > -1 && !probablyInString(state, pos, token, stringPrefixes))
9750
9766
  return { changes: { insert: token + token, from: pos },
9751
9767
  effects: closeBracketEffect.of(pos + token.length),
9752
9768
  range: state_.EditorSelection.cursor(pos + token.length) };
@@ -9762,12 +9778,15 @@ function nodeStart(state, pos) {
9762
9778
  let tree = dist_syntaxTree(state).resolveInner(pos + 1);
9763
9779
  return tree.parent && tree.from == pos;
9764
9780
  }
9765
- function probablyInString(state, pos, quoteToken) {
9781
+ function probablyInString(state, pos, quoteToken, prefixes) {
9766
9782
  let node = dist_syntaxTree(state).resolveInner(pos, -1);
9783
+ let maxPrefix = prefixes.reduce((m, p) => Math.max(m, p.length), 0);
9767
9784
  for (let i = 0; i < 5; i++) {
9768
- if (state.sliceDoc(node.from, node.from + quoteToken.length) == quoteToken) {
9785
+ let start = state.sliceDoc(node.from, Math.min(node.to, node.from + quoteToken.length + maxPrefix));
9786
+ let quotePos = start.indexOf(quoteToken);
9787
+ if (!quotePos || quotePos > -1 && prefixes.indexOf(start.slice(0, quotePos)) > -1) {
9769
9788
  let first = node.firstChild;
9770
- while (first && first.from == node.from && first.to - first.from > quoteToken.length) {
9789
+ while (first && first.from == node.from && first.to - first.from > quoteToken.length + quotePos) {
9771
9790
  if (state.sliceDoc(first.to - quoteToken.length, first.to) == quoteToken)
9772
9791
  return false;
9773
9792
  first = first.firstChild;
@@ -9781,6 +9800,17 @@ function probablyInString(state, pos, quoteToken) {
9781
9800
  }
9782
9801
  return false;
9783
9802
  }
9803
+ function canStartStringAt(state, pos, prefixes) {
9804
+ let charCat = state.charCategorizer(pos);
9805
+ if (charCat(state.sliceDoc(pos - 1, pos)) != state_.CharCategory.Word)
9806
+ return pos;
9807
+ for (let prefix of prefixes) {
9808
+ let start = pos - prefix.length;
9809
+ if (state.sliceDoc(start, pos) == prefix && charCat(state.sliceDoc(start - 1, start)) != state_.CharCategory.Word)
9810
+ return start;
9811
+ }
9812
+ return -1;
9813
+ }
9784
9814
 
9785
9815
  /**
9786
9816
  Returns an extension that enables autocompletion.