@uiw/react-codemirror 4.21.24 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,6 @@ export declare function useCodeMirror(props: UseCodeMirror): {
9
9
  setState: import("react").Dispatch<import("react").SetStateAction<EditorState | undefined>>;
10
10
  view: EditorView | undefined;
11
11
  setView: import("react").Dispatch<import("react").SetStateAction<EditorView | undefined>>;
12
- container: HTMLDivElement | undefined;
13
- setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | undefined>>;
12
+ container: HTMLDivElement | null | undefined;
13
+ setContainer: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null | undefined>>;
14
14
  };
@@ -1496,7 +1496,7 @@ class FuzzyMatcher {
1496
1496
  ret(score, matched) {
1497
1497
  this.score = score;
1498
1498
  this.matched = matched;
1499
- return true;
1499
+ return this;
1500
1500
  }
1501
1501
  // Matches a given word (completion) against the pattern (input).
1502
1502
  // Will return a boolean indicating whether there was a match and,
@@ -1509,7 +1509,7 @@ class FuzzyMatcher {
1509
1509
  if (this.pattern.length == 0)
1510
1510
  return this.ret(-100 /* Penalty.NotFull */, []);
1511
1511
  if (word.length < this.pattern.length)
1512
- return false;
1512
+ return null;
1513
1513
  let { chars, folded, any, precise, byWord } = this;
1514
1514
  // For single-character queries, only match when they occur right
1515
1515
  // at the start
@@ -1520,7 +1520,7 @@ class FuzzyMatcher {
1520
1520
  else if (first == folded[0])
1521
1521
  score += -200 /* Penalty.CaseFold */;
1522
1522
  else
1523
- return false;
1523
+ return null;
1524
1524
  return this.ret(score, [0, firstSize]);
1525
1525
  }
1526
1526
  let direct = word.indexOf(this.pattern);
@@ -1536,7 +1536,7 @@ class FuzzyMatcher {
1536
1536
  }
1537
1537
  // No match, exit immediately
1538
1538
  if (anyTo < len)
1539
- return false;
1539
+ return null;
1540
1540
  }
1541
1541
  // This tracks the extent of the precise (non-folded, not
1542
1542
  // necessarily adjacent) match
@@ -1589,7 +1589,7 @@ class FuzzyMatcher {
1589
1589
  if (byWordTo == len)
1590
1590
  return this.result(-100 /* Penalty.ByWord */ + (byWordFolded ? -200 /* Penalty.CaseFold */ : 0) + -700 /* Penalty.NotStart */ +
1591
1591
  (wordAdjacent ? 0 : -1100 /* Penalty.Gap */), byWord, word);
1592
- return chars.length == 2 ? false
1592
+ return chars.length == 2 ? null
1593
1593
  : this.result((any[0] ? -700 /* Penalty.NotStart */ : 0) + -200 /* Penalty.CaseFold */ + -1100 /* Penalty.Gap */, any, word);
1594
1594
  }
1595
1595
  result(score, positions, word) {
@@ -1606,11 +1606,31 @@ class FuzzyMatcher {
1606
1606
  return this.ret(score - word.length, result);
1607
1607
  }
1608
1608
  }
1609
+ class StrictMatcher {
1610
+ constructor(pattern) {
1611
+ this.pattern = pattern;
1612
+ this.matched = [];
1613
+ this.score = 0;
1614
+ this.folded = pattern.toLowerCase();
1615
+ }
1616
+ match(word) {
1617
+ if (word.length < this.pattern.length)
1618
+ return null;
1619
+ let start = word.slice(0, this.pattern.length);
1620
+ let match = start == this.pattern ? 0 : start.toLowerCase() == this.folded ? -200 /* Penalty.CaseFold */ : null;
1621
+ if (match == null)
1622
+ return null;
1623
+ this.matched = [0, start.length];
1624
+ this.score = match + (word.length == this.pattern.length ? 0 : -100 /* Penalty.NotFull */);
1625
+ return this;
1626
+ }
1627
+ }
1609
1628
 
1610
1629
  const completionConfig = /*@__PURE__*/state_.Facet.define({
1611
1630
  combine(configs) {
1612
1631
  return (0,state_.combineConfig)(configs, {
1613
1632
  activateOnTyping: true,
1633
+ activateOnCompletion: () => false,
1614
1634
  activateOnTypingDelay: 100,
1615
1635
  selectOnOpen: true,
1616
1636
  override: null,
@@ -1623,6 +1643,7 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
1623
1643
  icons: true,
1624
1644
  addToOptions: [],
1625
1645
  positionInfo: defaultPositionInfo,
1646
+ filterStrict: false,
1626
1647
  compareCompletions: (a, b) => a.label.localeCompare(b.label),
1627
1648
  interactionDelay: 75,
1628
1649
  updateSyncTime: 100
@@ -1632,7 +1653,8 @@ const completionConfig = /*@__PURE__*/state_.Facet.define({
1632
1653
  icons: (a, b) => a && b,
1633
1654
  tooltipClass: (a, b) => c => joinClass(a(c), b(c)),
1634
1655
  optionClass: (a, b) => c => joinClass(a(c), b(c)),
1635
- addToOptions: (a, b) => a.concat(b)
1656
+ addToOptions: (a, b) => a.concat(b),
1657
+ filterStrict: (a, b) => a || b,
1636
1658
  });
1637
1659
  }
1638
1660
  });
@@ -1992,6 +2014,7 @@ function sortOptions(active, state) {
1992
2014
  sections.push(typeof section == "string" ? { name } : section);
1993
2015
  }
1994
2016
  };
2017
+ let conf = state.facet(completionConfig);
1995
2018
  for (let a of active)
1996
2019
  if (a.hasResult()) {
1997
2020
  let getMatch = a.result.getMatch;
@@ -2001,11 +2024,12 @@ function sortOptions(active, state) {
2001
2024
  }
2002
2025
  }
2003
2026
  else {
2004
- let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to));
2027
+ let pattern = state.sliceDoc(a.from, a.to), match;
2028
+ let matcher = conf.filterStrict ? new StrictMatcher(pattern) : new FuzzyMatcher(pattern);
2005
2029
  for (let option of a.result.options)
2006
- if (matcher.match(option.label)) {
2007
- let matched = !option.displayLabel ? matcher.matched : getMatch ? getMatch(option, matcher.matched) : [];
2008
- addOption(new Option(option, a.source, matched, matcher.score + (option.boost || 0)));
2030
+ if (match = matcher.match(option.label)) {
2031
+ let matched = !option.displayLabel ? match.matched : getMatch ? getMatch(option, match.matched) : [];
2032
+ addOption(new Option(option, a.source, matched, match.score + (option.boost || 0)));
2009
2033
  }
2010
2034
  }
2011
2035
  }
@@ -2023,7 +2047,7 @@ function sortOptions(active, state) {
2023
2047
  }
2024
2048
  }
2025
2049
  let result = [], prev = null;
2026
- let compare = state.facet(completionConfig).compareCompletions;
2050
+ let compare = conf.compareCompletions;
2027
2051
  for (let opt of options.sort((a, b) => (b.score - a.score) || compare(a.completion, b.completion))) {
2028
2052
  let cur = opt.completion;
2029
2053
  if (!prev || prev.label != cur.label || prev.detail != cur.detail ||
@@ -2141,7 +2165,12 @@ function makeAttrs(id, selected) {
2141
2165
  return result;
2142
2166
  }
2143
2167
  const none = [];
2144
- function getUserEvent(tr) {
2168
+ function getUserEvent(tr, conf) {
2169
+ if (tr.isUserEvent("input.complete")) {
2170
+ let completion = tr.annotation(pickedCompletion);
2171
+ if (completion && conf.activateOnCompletion(completion))
2172
+ return "input";
2173
+ }
2145
2174
  return tr.isUserEvent("input.type") ? "input" : tr.isUserEvent("delete.backward") ? "delete" : null;
2146
2175
  }
2147
2176
  class ActiveSource {
@@ -2152,7 +2181,7 @@ class ActiveSource {
2152
2181
  }
2153
2182
  hasResult() { return false; }
2154
2183
  update(tr, conf) {
2155
- let event = getUserEvent(tr), value = this;
2184
+ let event = getUserEvent(tr, conf), value = this;
2156
2185
  if (event)
2157
2186
  value = value.handleUserEvent(tr, event, conf);
2158
2187
  else if (tr.docChanged)
@@ -2191,26 +2220,33 @@ class ActiveResult extends ActiveSource {
2191
2220
  hasResult() { return true; }
2192
2221
  handleUserEvent(tr, type, conf) {
2193
2222
  var _a;
2223
+ let result = this.result;
2224
+ if (result.map && !tr.changes.empty)
2225
+ result = result.map(result, tr.changes);
2194
2226
  let from = tr.changes.mapPos(this.from), to = tr.changes.mapPos(this.to, 1);
2195
2227
  let pos = cur(tr.state);
2196
2228
  if ((this.explicitPos < 0 ? pos <= from : pos < this.from) ||
2197
- pos > to ||
2229
+ pos > to || !result ||
2198
2230
  type == "delete" && cur(tr.startState) == this.from)
2199
2231
  return new ActiveSource(this.source, type == "input" && conf.activateOnTyping ? 1 /* State.Pending */ : 0 /* State.Inactive */);
2200
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated;
2201
- if (checkValid(this.result.validFor, tr.state, from, to))
2202
- return new ActiveResult(this.source, explicitPos, this.result, from, to);
2203
- if (this.result.update &&
2204
- (updated = this.result.update(this.result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
2205
- return new ActiveResult(this.source, explicitPos, updated, updated.from, (_a = updated.to) !== null && _a !== void 0 ? _a : cur(tr.state));
2232
+ let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
2233
+ if (checkValid(result.validFor, tr.state, from, to))
2234
+ return new ActiveResult(this.source, explicitPos, result, from, to);
2235
+ if (result.update &&
2236
+ (result = result.update(result, from, to, new CompletionContext(tr.state, pos, explicitPos >= 0))))
2237
+ return new ActiveResult(this.source, explicitPos, result, result.from, (_a = result.to) !== null && _a !== void 0 ? _a : cur(tr.state));
2206
2238
  return new ActiveSource(this.source, 1 /* State.Pending */, explicitPos);
2207
2239
  }
2208
2240
  handleChange(tr) {
2209
2241
  return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(this.source, 0 /* State.Inactive */) : this.map(tr.changes);
2210
2242
  }
2211
2243
  map(mapping) {
2212
- return mapping.empty ? this :
2213
- new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
2244
+ if (mapping.empty)
2245
+ return this;
2246
+ let result = this.result.map ? this.result.map(this.result, mapping) : this.result;
2247
+ if (!result)
2248
+ return new ActiveSource(this.source, 0 /* State.Inactive */);
2249
+ return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
2214
2250
  }
2215
2251
  }
2216
2252
  function checkValid(validFor, state, from, to) {
@@ -2324,10 +2360,11 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2324
2360
  }
2325
2361
  update(update) {
2326
2362
  let cState = update.state.field(completionState);
2363
+ let conf = update.state.facet(completionConfig);
2327
2364
  if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
2328
2365
  return;
2329
2366
  let doesReset = update.transactions.some(tr => {
2330
- return (tr.selection || tr.docChanged) && !getUserEvent(tr);
2367
+ return (tr.selection || tr.docChanged) && !getUserEvent(tr, conf);
2331
2368
  });
2332
2369
  for (let i = 0; i < this.running.length; i++) {
2333
2370
  let query = this.running[i];
@@ -2352,12 +2389,12 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2352
2389
  clearTimeout(this.debounceUpdate);
2353
2390
  if (update.transactions.some(tr => tr.effects.some(e => e.is(startCompletionEffect))))
2354
2391
  this.pendingStart = true;
2355
- let delay = this.pendingStart ? 50 : update.state.facet(completionConfig).activateOnTypingDelay;
2392
+ let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
2356
2393
  this.debounceUpdate = cState.active.some(a => a.state == 1 /* State.Pending */ && !this.running.some(q => q.active.source == a.source))
2357
2394
  ? setTimeout(() => this.startUpdate(), delay) : -1;
2358
2395
  if (this.composing != 0 /* CompositionState.None */)
2359
2396
  for (let tr of update.transactions) {
2360
- if (getUserEvent(tr) == "input")
2397
+ if (getUserEvent(tr, conf) == "input")
2361
2398
  this.composing = 2 /* CompositionState.Changed */;
2362
2399
  else if (this.composing == 2 /* CompositionState.Changed */ && tr.selection)
2363
2400
  this.composing = 3 /* CompositionState.ChangedAndMoved */;
@@ -2461,6 +2498,21 @@ const completionPlugin = /*@__PURE__*/view_.ViewPlugin.fromClass(class {
2461
2498
  }
2462
2499
  }
2463
2500
  });
2501
+ const windows = typeof navigator == "object" && /*@__PURE__*//Win/.test(navigator.platform);
2502
+ const commitCharacters = /*@__PURE__*/state_.Prec.highest(/*@__PURE__*/view_.EditorView.domEventHandlers({
2503
+ keydown(event, view) {
2504
+ let field = view.state.field(completionState, false);
2505
+ if (!field || !field.open || field.open.disabled || field.open.selected < 0 ||
2506
+ event.key.length > 1 || event.ctrlKey && !(windows && event.altKey) || event.metaKey)
2507
+ return false;
2508
+ let option = field.open.options[field.open.selected];
2509
+ let result = field.active.find(a => a.source == option.source);
2510
+ let commitChars = option.completion.commitCharacters || result.result.commitCharacters;
2511
+ if (commitChars && commitChars.indexOf(event.key) > -1)
2512
+ applyCompletion(view, option);
2513
+ return false;
2514
+ }
2515
+ }));
2464
2516
 
2465
2517
  const dist_baseTheme = /*@__PURE__*/view_.EditorView.baseTheme({
2466
2518
  ".cm-tooltip.cm-tooltip-autocomplete": {
@@ -3182,6 +3234,7 @@ Returns an extension that enables autocompletion.
3182
3234
  */
3183
3235
  function autocompletion(config = {}) {
3184
3236
  return [
3237
+ commitCharacters,
3185
3238
  completionState,
3186
3239
  completionConfig.of(config),
3187
3240
  completionPlugin,
@@ -4432,7 +4485,7 @@ function toPrimitive(t, r) {
4432
4485
 
4433
4486
  function toPropertyKey(t) {
4434
4487
  var i = toPrimitive(t, "string");
4435
- return "symbol" == _typeof(i) ? i : String(i);
4488
+ return "symbol" == _typeof(i) ? i : i + "";
4436
4489
  }
4437
4490
  ;// CONCATENATED MODULE: ../node_modules/@babel/runtime/helpers/esm/defineProperty.js
4438
4491
 
@@ -4527,7 +4580,7 @@ function _objectWithoutProperties(source, excluded) {
4527
4580
  /* harmony export */ cL: () => (/* binding */ historyKeymap),
4528
4581
  /* harmony export */ pw: () => (/* binding */ defaultKeymap)
4529
4582
  /* harmony export */ });
4530
- /* 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, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteLineBoundaryBackward, deleteLineBoundaryForward, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, historyField, indentLess, indentMore, indentSelection, insertBlankLine, insertNewline, insertNewlineAndIndent, 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, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoDepth, undoSelection */
4583
+ /* 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, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoDepth, undoSelection */
4531
4584
  /* harmony import */ var _codemirror_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(60);
4532
4585
  /* harmony import */ var _codemirror_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(730);
4533
4586
  /* harmony import */ var _codemirror_language__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(194);
@@ -5614,9 +5667,9 @@ function skipAtomic(target, pos, forward) {
5614
5667
  });
5615
5668
  return pos;
5616
5669
  }
5617
- const deleteByChar = (target, forward) => deleteBy(target, range => {
5670
+ const deleteByChar = (target, forward, byIndentUnit) => deleteBy(target, range => {
5618
5671
  let pos = range.from, { state } = target, line = state.doc.lineAt(pos), before, targetPos;
5619
- if (!forward && pos > line.from && pos < line.from + 200 &&
5672
+ if (byIndentUnit && !forward && pos > line.from && pos < line.from + 200 &&
5620
5673
  !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
5621
5674
  if (before[before.length - 1] == "\t")
5622
5675
  return pos - 1;
@@ -5635,14 +5688,20 @@ const deleteByChar = (target, forward) => deleteBy(target, range => {
5635
5688
  return targetPos;
5636
5689
  });
5637
5690
  /**
5638
- Delete the selection, or, for cursor selections, the character
5639
- before the cursor.
5691
+ Delete the selection, or, for cursor selections, the character or
5692
+ indentation unit before the cursor.
5693
+ */
5694
+ const deleteCharBackward = view => deleteByChar(view, false, true);
5695
+ /**
5696
+ Delete the selection or the character before the cursor. Does not
5697
+ implement any extended behavior like deleting whole indentation
5698
+ units in one go.
5640
5699
  */
5641
- const deleteCharBackward = view => deleteByChar(view, false);
5700
+ const deleteCharBackwardStrict = view => deleteByChar(view, false, false);
5642
5701
  /**
5643
5702
  Delete the selection or the character after the cursor.
5644
5703
  */
5645
- const deleteCharForward = view => deleteByChar(view, true);
5704
+ const deleteCharForward = view => deleteByChar(view, true, false);
5646
5705
  const deleteByGroup = (target, forward) => deleteBy(target, range => {
5647
5706
  let pos = range.head, { state } = target, line = state.doc.lineAt(pos);
5648
5707
  let categorize = state.charCategorizer(pos);
@@ -5859,7 +5918,15 @@ const deleteLine = view => {
5859
5918
  to++;
5860
5919
  return { from, to };
5861
5920
  }));
5862
- let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes);
5921
+ let selection = updateSel(state.selection, range => {
5922
+ let dist = undefined;
5923
+ if (view.lineWrapping) {
5924
+ let block = view.lineBlockAt(range.head), pos = view.coordsAtPos(range.head, range.assoc || 1);
5925
+ if (pos)
5926
+ dist = (block.bottom + view.documentTop) - pos.bottom + view.defaultLineHeight / 2;
5927
+ }
5928
+ return view.moveVertically(range, true, dist);
5929
+ }).map(changes);
5863
5930
  view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" });
5864
5931
  return true;
5865
5932
  };
@@ -5870,6 +5937,20 @@ const insertNewline = ({ state, dispatch }) => {
5870
5937
  dispatch(state.update(state.replaceSelection(state.lineBreak), { scrollIntoView: true, userEvent: "input" }));
5871
5938
  return true;
5872
5939
  };
5940
+ /**
5941
+ Replace the selection with a newline and the same amount of
5942
+ indentation as the line above.
5943
+ */
5944
+ const insertNewlineKeepIndent = ({ state, dispatch }) => {
5945
+ dispatch(state.update(state.changeByRange(range => {
5946
+ let indent = /^\s*/.exec(state.doc.lineAt(range.from).text)[0];
5947
+ return {
5948
+ changes: { from: range.from, to: range.to, insert: state.lineBreak + indent },
5949
+ range: EditorSelection.cursor(range.from + indent.length + 1)
5950
+ };
5951
+ }), { scrollIntoView: true, userEvent: "input" }));
5952
+ return true;
5953
+ };
5873
5954
  function isBetweenBrackets(state, pos) {
5874
5955
  if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1)))
5875
5956
  return { from: pos, to: pos };
@@ -7167,7 +7248,7 @@ class StyleModule {
7167
7248
  let set = root[SET], nonce = options && options.nonce
7168
7249
  if (!set) set = new StyleSet(root, nonce)
7169
7250
  else if (nonce) set.setNonce(nonce)
7170
- set.mount(Array.isArray(modules) ? modules : [modules])
7251
+ set.mount(Array.isArray(modules) ? modules : [modules], root)
7171
7252
  }
7172
7253
  }
7173
7254
 
@@ -7178,24 +7259,18 @@ class StyleSet {
7178
7259
  let doc = root.ownerDocument || root, win = doc.defaultView
7179
7260
  if (!root.head && root.adoptedStyleSheets && win.CSSStyleSheet) {
7180
7261
  let adopted = adoptedSet.get(doc)
7181
- if (adopted) {
7182
- root.adoptedStyleSheets = [adopted.sheet, ...root.adoptedStyleSheets]
7183
- return root[SET] = adopted
7184
- }
7262
+ if (adopted) return root[SET] = adopted
7185
7263
  this.sheet = new win.CSSStyleSheet
7186
- root.adoptedStyleSheets = [this.sheet, ...root.adoptedStyleSheets]
7187
7264
  adoptedSet.set(doc, this)
7188
7265
  } else {
7189
7266
  this.styleTag = doc.createElement("style")
7190
7267
  if (nonce) this.styleTag.setAttribute("nonce", nonce)
7191
- let target = root.head || root
7192
- target.insertBefore(this.styleTag, target.firstChild)
7193
7268
  }
7194
7269
  this.modules = []
7195
7270
  root[SET] = this
7196
7271
  }
7197
7272
 
7198
- mount(modules) {
7273
+ mount(modules, root) {
7199
7274
  let sheet = this.sheet
7200
7275
  let pos = 0 /* Current rule offset */, j = 0 /* Index into this.modules */
7201
7276
  for (let i = 0; i < modules.length; i++) {
@@ -7216,11 +7291,17 @@ class StyleSet {
7216
7291
  }
7217
7292
  }
7218
7293
 
7219
- if (!sheet) {
7294
+ if (sheet) {
7295
+ if (root.adoptedStyleSheets.indexOf(this.sheet) < 0)
7296
+ root.adoptedStyleSheets = [this.sheet, ...root.adoptedStyleSheets]
7297
+ } else {
7220
7298
  let text = ""
7221
7299
  for (let i = 0; i < this.modules.length; i++)
7222
7300
  text += this.modules[i].getRules() + "\n"
7223
7301
  this.styleTag.textContent = text
7302
+ let target = root.head || root
7303
+ if (this.styleTag.parentNode != target)
7304
+ target.insertBefore(this.styleTag, target.firstChild)
7224
7305
  }
7225
7306
  }
7226
7307