@electric-sql/pglite-repl 0.2.25 → 0.2.27

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.
@@ -31627,6 +31627,77 @@ function _objectWithoutPropertiesLoose(r, e2) {
31627
31627
  }
31628
31628
  return t2;
31629
31629
  }
31630
+ let rangeFrom = [], rangeTo = [];
31631
+ (() => {
31632
+ let numbers = "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((s) => s ? parseInt(s, 36) : 1);
31633
+ for (let i = 0, n = 0; i < numbers.length; i++)
31634
+ (i % 2 ? rangeTo : rangeFrom).push(n = n + numbers[i]);
31635
+ })();
31636
+ function isExtendingChar(code) {
31637
+ if (code < 768) return false;
31638
+ for (let from = 0, to2 = rangeFrom.length; ; ) {
31639
+ let mid = from + to2 >> 1;
31640
+ if (code < rangeFrom[mid]) to2 = mid;
31641
+ else if (code >= rangeTo[mid]) from = mid + 1;
31642
+ else return true;
31643
+ if (from == to2) return false;
31644
+ }
31645
+ }
31646
+ function isRegionalIndicator(code) {
31647
+ return code >= 127462 && code <= 127487;
31648
+ }
31649
+ const ZWJ = 8205;
31650
+ function findClusterBreak$1(str, pos, forward = true, includeExtending = true) {
31651
+ return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending);
31652
+ }
31653
+ function nextClusterBreak(str, pos, includeExtending) {
31654
+ if (pos == str.length) return pos;
31655
+ if (pos && surrogateLow$1(str.charCodeAt(pos)) && surrogateHigh$1(str.charCodeAt(pos - 1))) pos--;
31656
+ let prev = codePointAt$1(str, pos);
31657
+ pos += codePointSize$1(prev);
31658
+ while (pos < str.length) {
31659
+ let next = codePointAt$1(str, pos);
31660
+ if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {
31661
+ pos += codePointSize$1(next);
31662
+ prev = next;
31663
+ } else if (isRegionalIndicator(next)) {
31664
+ let countBefore = 0, i = pos - 2;
31665
+ while (i >= 0 && isRegionalIndicator(codePointAt$1(str, i))) {
31666
+ countBefore++;
31667
+ i -= 2;
31668
+ }
31669
+ if (countBefore % 2 == 0) break;
31670
+ else pos += 2;
31671
+ } else {
31672
+ break;
31673
+ }
31674
+ }
31675
+ return pos;
31676
+ }
31677
+ function prevClusterBreak(str, pos, includeExtending) {
31678
+ while (pos > 0) {
31679
+ let found = nextClusterBreak(str, pos - 2, includeExtending);
31680
+ if (found < pos) return found;
31681
+ pos--;
31682
+ }
31683
+ return 0;
31684
+ }
31685
+ function codePointAt$1(str, pos) {
31686
+ let code0 = str.charCodeAt(pos);
31687
+ if (!surrogateHigh$1(code0) || pos + 1 == str.length) return code0;
31688
+ let code1 = str.charCodeAt(pos + 1);
31689
+ if (!surrogateLow$1(code1)) return code0;
31690
+ return (code0 - 55296 << 10) + (code1 - 56320) + 65536;
31691
+ }
31692
+ function surrogateLow$1(ch) {
31693
+ return ch >= 56320 && ch < 57344;
31694
+ }
31695
+ function surrogateHigh$1(ch) {
31696
+ return ch >= 55296 && ch < 56320;
31697
+ }
31698
+ function codePointSize$1(code) {
31699
+ return code < 65536 ? 1 : 2;
31700
+ }
31630
31701
  class Text {
31631
31702
  /**
31632
31703
  Get the line description around the given position.
@@ -32177,58 +32248,8 @@ function clip(text, from, to2) {
32177
32248
  from = Math.max(0, Math.min(text.length, from));
32178
32249
  return [from, Math.max(from, Math.min(text.length, to2))];
32179
32250
  }
32180
- let extend = /* @__PURE__ */ "lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map((s) => s ? parseInt(s, 36) : 1);
32181
- for (let i = 1; i < extend.length; i++)
32182
- extend[i] += extend[i - 1];
32183
- function isExtendingChar(code) {
32184
- for (let i = 1; i < extend.length; i += 2)
32185
- if (extend[i] > code)
32186
- return extend[i - 1] <= code;
32187
- return false;
32188
- }
32189
- function isRegionalIndicator(code) {
32190
- return code >= 127462 && code <= 127487;
32191
- }
32192
- const ZWJ = 8205;
32193
32251
  function findClusterBreak(str, pos, forward = true, includeExtending = true) {
32194
- return (forward ? nextClusterBreak : prevClusterBreak)(str, pos, includeExtending);
32195
- }
32196
- function nextClusterBreak(str, pos, includeExtending) {
32197
- if (pos == str.length)
32198
- return pos;
32199
- if (pos && surrogateLow(str.charCodeAt(pos)) && surrogateHigh(str.charCodeAt(pos - 1)))
32200
- pos--;
32201
- let prev = codePointAt(str, pos);
32202
- pos += codePointSize(prev);
32203
- while (pos < str.length) {
32204
- let next = codePointAt(str, pos);
32205
- if (prev == ZWJ || next == ZWJ || includeExtending && isExtendingChar(next)) {
32206
- pos += codePointSize(next);
32207
- prev = next;
32208
- } else if (isRegionalIndicator(next)) {
32209
- let countBefore = 0, i = pos - 2;
32210
- while (i >= 0 && isRegionalIndicator(codePointAt(str, i))) {
32211
- countBefore++;
32212
- i -= 2;
32213
- }
32214
- if (countBefore % 2 == 0)
32215
- break;
32216
- else
32217
- pos += 2;
32218
- } else {
32219
- break;
32220
- }
32221
- }
32222
- return pos;
32223
- }
32224
- function prevClusterBreak(str, pos, includeExtending) {
32225
- while (pos > 0) {
32226
- let found = nextClusterBreak(str, pos - 2, includeExtending);
32227
- if (found < pos)
32228
- return found;
32229
- pos--;
32230
- }
32231
- return 0;
32252
+ return findClusterBreak$1(str, pos, forward, includeExtending);
32232
32253
  }
32233
32254
  function surrogateLow(ch) {
32234
32255
  return ch >= 56320 && ch < 57344;
@@ -32358,7 +32379,7 @@ class ChangeDesc {
32358
32379
  Map this description, which should start with the same document
32359
32380
  as `other`, over another set of changes, so that it can be
32360
32381
  applied after it. When `before` is true, map as if the changes
32361
- in `other` happened before the ones in `this`.
32382
+ in `this` happened before the ones in `other`.
32362
32383
  */
32363
32384
  mapDesc(other, before = false) {
32364
32385
  return other.empty ? this : mapSet(this, other, before);
@@ -32659,7 +32680,7 @@ function addSection(sections, len, ins, forceJoin = false) {
32659
32680
  let last = sections.length - 2;
32660
32681
  if (last >= 0 && ins <= 0 && ins == sections[last + 1])
32661
32682
  sections[last] += len;
32662
- else if (len == 0 && sections[last] == 0)
32683
+ else if (last >= 0 && len == 0 && sections[last] == 0)
32663
32684
  sections[last + 1] += ins;
32664
32685
  else if (forceJoin) {
32665
32686
  sections[last] += len;
@@ -32708,7 +32729,9 @@ function mapSet(setA, setB, before, mkSet = false) {
32708
32729
  let sections = [], insert2 = mkSet ? [] : null;
32709
32730
  let a = new SectionIter(setA), b = new SectionIter(setB);
32710
32731
  for (let inserted = -1; ; ) {
32711
- if (a.ins == -1 && b.ins == -1) {
32732
+ if (a.done && b.len || b.done && a.len) {
32733
+ throw new Error("Mismatched change set lengths");
32734
+ } else if (a.ins == -1 && b.ins == -1) {
32712
32735
  let len = Math.min(a.len, b.len);
32713
32736
  addSection(sections, len, -1);
32714
32737
  a.forward(len);
@@ -33305,6 +33328,11 @@ class StateField {
33305
33328
  return 1;
33306
33329
  },
33307
33330
  reconfigure: (state, oldState) => {
33331
+ let init = state.facet(initField), oldInit = oldState.facet(initField), reInit;
33332
+ if ((reInit = init.find((i) => i.field == this)) && reInit != oldInit.find((i) => i.field == this)) {
33333
+ state.values[idx] = reInit.create(state);
33334
+ return 1;
33335
+ }
33308
33336
  if (oldState.config.address[this.id] != null) {
33309
33337
  state.values[idx] = oldState.field(this);
33310
33338
  return 0;
@@ -34939,7 +34967,7 @@ function compare(a, startA, b, startB, length, comparator) {
34939
34967
  let endB = startB + length;
34940
34968
  let pos = startB, dPos = startB - startA;
34941
34969
  for (; ; ) {
34942
- let diff = a.to + dPos - b.to || a.endSide - b.endSide;
34970
+ let dEnd = a.to + dPos - b.to, diff = dEnd || a.endSide - b.endSide;
34943
34971
  let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
34944
34972
  if (a.point || b.point) {
34945
34973
  if (!(a.point && b.point && (a.point == b.point || a.point.eq(b.point)) && sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
@@ -34950,6 +34978,8 @@ function compare(a, startA, b, startB, length, comparator) {
34950
34978
  }
34951
34979
  if (end > endB)
34952
34980
  break;
34981
+ if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)
34982
+ comparator.boundChange(end);
34953
34983
  pos = end;
34954
34984
  if (diff <= 0)
34955
34985
  a.next();
@@ -34986,7 +35016,7 @@ function findMinIndex(value, array) {
34986
35016
  }
34987
35017
  function countColumn(string2, tabSize, to2 = string2.length) {
34988
35018
  let n = 0;
34989
- for (let i = 0; i < to2; ) {
35019
+ for (let i = 0; i < to2 && i < string2.length; ) {
34990
35020
  if (string2.charCodeAt(i) == 9) {
34991
35021
  n += tabSize - n % tabSize;
34992
35022
  i++;
@@ -35237,6 +35267,33 @@ function keyName(event) {
35237
35267
  if (name2 == "Down") name2 = "ArrowDown";
35238
35268
  return name2;
35239
35269
  }
35270
+ function crelt() {
35271
+ var elt = arguments[0];
35272
+ if (typeof elt == "string") elt = document.createElement(elt);
35273
+ var i = 1, next = arguments[1];
35274
+ if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
35275
+ for (var name2 in next) if (Object.prototype.hasOwnProperty.call(next, name2)) {
35276
+ var value = next[name2];
35277
+ if (typeof value == "string") elt.setAttribute(name2, value);
35278
+ else if (value != null) elt[name2] = value;
35279
+ }
35280
+ i++;
35281
+ }
35282
+ for (; i < arguments.length; i++) add(elt, arguments[i]);
35283
+ return elt;
35284
+ }
35285
+ function add(elt, child) {
35286
+ if (typeof child == "string") {
35287
+ elt.appendChild(document.createTextNode(child));
35288
+ } else if (child == null) ;
35289
+ else if (child.nodeType != null) {
35290
+ elt.appendChild(child);
35291
+ } else if (Array.isArray(child)) {
35292
+ for (var i = 0; i < child.length; i++) add(elt, child[i]);
35293
+ } else {
35294
+ throw new RangeError("Unsupported child node: " + child);
35295
+ }
35296
+ }
35240
35297
  function getSelection(root) {
35241
35298
  let target;
35242
35299
  if (root.nodeType == 11) {
@@ -35360,13 +35417,13 @@ function scrollRectIntoView(dom, rect, side, x, y2, xMargin, yMargin, ltr) {
35360
35417
  let moveX = 0, moveY = 0;
35361
35418
  if (y2 == "nearest") {
35362
35419
  if (rect.top < bounding.top) {
35363
- moveY = -(bounding.top - rect.top + yMargin);
35420
+ moveY = rect.top - (bounding.top + yMargin);
35364
35421
  if (side > 0 && rect.bottom > bounding.bottom + moveY)
35365
- moveY = rect.bottom - bounding.bottom + moveY + yMargin;
35422
+ moveY = rect.bottom - bounding.bottom + yMargin;
35366
35423
  } else if (rect.bottom > bounding.bottom) {
35367
35424
  moveY = rect.bottom - bounding.bottom + yMargin;
35368
35425
  if (side < 0 && rect.top - moveY < bounding.top)
35369
- moveY = -(bounding.top + moveY - rect.top + yMargin);
35426
+ moveY = rect.top - (bounding.top + yMargin);
35370
35427
  }
35371
35428
  } else {
35372
35429
  let rectHeight = rect.bottom - rect.top, boundingHeight = bounding.bottom - bounding.top;
@@ -35375,13 +35432,13 @@ function scrollRectIntoView(dom, rect, side, x, y2, xMargin, yMargin, ltr) {
35375
35432
  }
35376
35433
  if (x == "nearest") {
35377
35434
  if (rect.left < bounding.left) {
35378
- moveX = -(bounding.left - rect.left + xMargin);
35435
+ moveX = rect.left - (bounding.left + xMargin);
35379
35436
  if (side > 0 && rect.right > bounding.right + moveX)
35380
- moveX = rect.right - bounding.right + moveX + xMargin;
35437
+ moveX = rect.right - bounding.right + xMargin;
35381
35438
  } else if (rect.right > bounding.right) {
35382
35439
  moveX = rect.right - bounding.right + xMargin;
35383
35440
  if (side < 0 && rect.left < bounding.left + moveX)
35384
- moveX = -(bounding.left + moveX - rect.left + xMargin);
35441
+ moveX = rect.left - (bounding.left + xMargin);
35385
35442
  }
35386
35443
  } else {
35387
35444
  let targetLeft = x == "center" ? rect.left + (rect.right - rect.left) / 2 - (bounding.right - bounding.left) / 2 : x == "start" == ltr ? rect.left - xMargin : rect.right - (bounding.right - bounding.left) + xMargin;
@@ -35416,6 +35473,13 @@ function scrollRectIntoView(dom, rect, side, x, y2, xMargin, yMargin, ltr) {
35416
35473
  }
35417
35474
  if (top2)
35418
35475
  break;
35476
+ if (rect.top < bounding.top || rect.bottom > bounding.bottom || rect.left < bounding.left || rect.right > bounding.right)
35477
+ rect = {
35478
+ left: Math.max(rect.left, bounding.left),
35479
+ right: Math.min(rect.right, bounding.right),
35480
+ top: Math.max(rect.top, bounding.top),
35481
+ bottom: Math.min(rect.bottom, bounding.bottom)
35482
+ };
35419
35483
  cur2 = cur2.assignedSlot || cur2.parentNode;
35420
35484
  } else if (cur2.nodeType == 11) {
35421
35485
  cur2 = cur2.host;
@@ -36284,7 +36348,7 @@ function coordsInChildren(view, pos, side) {
36284
36348
  if (end >= pos2) {
36285
36349
  if (child.children.length) {
36286
36350
  scan(child, pos2 - off);
36287
- } else if ((!after || after.isHidden && side > 0) && (end > pos2 || off == end && child.getSide() > 0)) {
36351
+ } else if ((!after || after.isHidden && (side > 0 || onSameLine(after, child))) && (end > pos2 || off == end && child.getSide() > 0)) {
36288
36352
  after = child;
36289
36353
  afterPos = pos2 - off;
36290
36354
  } else if (off < pos2 || off == end && child.getSide() < 0 && !child.isHidden) {
@@ -36308,6 +36372,10 @@ function fallbackRect(view) {
36308
36372
  let rects = clientRectsFor(last);
36309
36373
  return rects[rects.length - 1] || null;
36310
36374
  }
36375
+ function onSameLine(a, b) {
36376
+ let posA = a.coordsAt(0, 1), posB = b.coordsAt(0, 1);
36377
+ return posA && posB && posB.top < posA.bottom;
36378
+ }
36311
36379
  function combineAttrs(source, target) {
36312
36380
  for (let name2 in source) {
36313
36381
  if (name2 == "class" && target.class)
@@ -37459,8 +37527,7 @@ function logException(state, exception, context) {
37459
37527
  let handler = state.facet(exceptionSink);
37460
37528
  if (handler.length)
37461
37529
  handler[0](exception);
37462
- else if (window.onerror)
37463
- window.onerror(String(exception), context, void 0, void 0, exception);
37530
+ else if (window.onerror && window.onerror(String(exception), context, void 0, void 0, exception)) ;
37464
37531
  else if (context)
37465
37532
  console.error(context + ":", exception);
37466
37533
  else
@@ -37468,14 +37535,30 @@ function logException(state, exception, context) {
37468
37535
  }
37469
37536
  const editable = /* @__PURE__ */ Facet.define({ combine: (values) => values.length ? values[0] : true });
37470
37537
  let nextPluginID = 0;
37471
- const viewPlugin = /* @__PURE__ */ Facet.define();
37538
+ const viewPlugin = /* @__PURE__ */ Facet.define({
37539
+ combine(plugins) {
37540
+ return plugins.filter((p, i) => {
37541
+ for (let j = 0; j < i; j++)
37542
+ if (plugins[j].plugin == p.plugin)
37543
+ return false;
37544
+ return true;
37545
+ });
37546
+ }
37547
+ });
37472
37548
  class ViewPlugin {
37473
37549
  constructor(id, create, domEventHandlers, domEventObservers, buildExtensions) {
37474
37550
  this.id = id;
37475
37551
  this.create = create;
37476
37552
  this.domEventHandlers = domEventHandlers;
37477
37553
  this.domEventObservers = domEventObservers;
37478
- this.extension = buildExtensions(this);
37554
+ this.baseExtensions = buildExtensions(this);
37555
+ this.extension = this.baseExtensions.concat(viewPlugin.of({ plugin: this, arg: void 0 }));
37556
+ }
37557
+ /**
37558
+ Create an extension for this plugin with the given argument.
37559
+ */
37560
+ of(arg) {
37561
+ return this.baseExtensions.concat(viewPlugin.of({ plugin: this, arg }));
37479
37562
  }
37480
37563
  /**
37481
37564
  Define a plugin from a constructor function that creates the
@@ -37484,7 +37567,7 @@ class ViewPlugin {
37484
37567
  static define(create, spec) {
37485
37568
  const { eventHandlers, eventObservers, provide, decorations: deco } = spec || {};
37486
37569
  return new ViewPlugin(nextPluginID++, create, eventHandlers, eventObservers, (plugin) => {
37487
- let ext = [viewPlugin.of(plugin)];
37570
+ let ext = [];
37488
37571
  if (deco)
37489
37572
  ext.push(decorations.of((view) => {
37490
37573
  let pluginInst = view.plugin(plugin);
@@ -37500,7 +37583,7 @@ class ViewPlugin {
37500
37583
  editor view as argument.
37501
37584
  */
37502
37585
  static fromClass(cls, spec) {
37503
- return ViewPlugin.define((view) => new cls(view), spec);
37586
+ return ViewPlugin.define((view, arg) => new cls(view, arg), spec);
37504
37587
  }
37505
37588
  }
37506
37589
  class PluginInstance {
@@ -37509,11 +37592,14 @@ class PluginInstance {
37509
37592
  this.mustUpdate = null;
37510
37593
  this.value = null;
37511
37594
  }
37595
+ get plugin() {
37596
+ return this.spec && this.spec.plugin;
37597
+ }
37512
37598
  update(view) {
37513
37599
  if (!this.value) {
37514
37600
  if (this.spec) {
37515
37601
  try {
37516
- this.value = this.spec.create(view);
37602
+ this.value = this.spec.plugin.create(view, this.spec.arg);
37517
37603
  } catch (e2) {
37518
37604
  logException(view.state, e2, "CodeMirror plugin crashed");
37519
37605
  this.deactivate();
@@ -37684,6 +37770,15 @@ class ViewUpdate {
37684
37770
  return (this.flags & 4) > 0;
37685
37771
  }
37686
37772
  /**
37773
+ Returns true when
37774
+ [`viewportChanged`](https://codemirror.net/6/docs/ref/#view.ViewUpdate.viewportChanged) is true
37775
+ and the viewport change is not just the result of mapping it in
37776
+ response to document changes.
37777
+ */
37778
+ get viewportMoved() {
37779
+ return (this.flags & 8) > 0;
37780
+ }
37781
+ /**
37687
37782
  Indicates whether the height of a block element in the editor
37688
37783
  changed in this update.
37689
37784
  */
@@ -37695,7 +37790,7 @@ class ViewUpdate {
37695
37790
  editor, or elements within the editor, changed.
37696
37791
  */
37697
37792
  get geometryChanged() {
37698
- return this.docChanged || (this.flags & (8 | 2)) > 0;
37793
+ return this.docChanged || (this.flags & (16 | 2)) > 0;
37699
37794
  }
37700
37795
  /**
37701
37796
  True when this update indicates a focus change.
@@ -37897,7 +37992,7 @@ class DocView extends ContentView {
37897
37992
  if (mustRead || !this.view.observer.selectionRange.focusNode)
37898
37993
  this.view.observer.readSelectionRange();
37899
37994
  let activeElt = this.view.root.activeElement, focused = activeElt == this.dom;
37900
- let selectionNotFocus = !focused && hasSelection(this.dom, this.view.observer.selectionRange) && !(activeElt && this.dom.contains(activeElt));
37995
+ let selectionNotFocus = !focused && !(this.view.state.facet(editable) || this.dom.tabIndex > -1) && hasSelection(this.dom, this.view.observer.selectionRange) && !(activeElt && this.dom.contains(activeElt));
37901
37996
  if (!(focused || fromPointer || selectionNotFocus))
37902
37997
  return;
37903
37998
  let force = this.forceSelection;
@@ -38295,6 +38390,9 @@ let DecorationComparator$1 = class DecorationComparator {
38295
38390
  comparePoint(from, to2) {
38296
38391
  addRange(from, to2, this.changes);
38297
38392
  }
38393
+ boundChange(pos) {
38394
+ addRange(pos, pos, this.changes);
38395
+ }
38298
38396
  };
38299
38397
  function findChangedDeco(a, b, diff) {
38300
38398
  let comp = new DecorationComparator$1();
@@ -38379,8 +38477,7 @@ function domPosAtCoords(parent, x, y2) {
38379
38477
  closestRect = rect;
38380
38478
  closestX = dx;
38381
38479
  closestY = dy;
38382
- let side = dy ? y2 < rect.top ? -1 : 1 : dx ? x < rect.left ? -1 : 1 : 0;
38383
- closestOverlap = !side || (side > 0 ? i < rects.length - 1 : i > 0);
38480
+ closestOverlap = !dx ? true : x < rect.left ? i > 0 : i < rects.length - 1;
38384
38481
  }
38385
38482
  if (dx == 0) {
38386
38483
  if (y2 > rect.bottom && (!aboveRect || aboveRect.bottom < rect.bottom)) {
@@ -38526,13 +38623,23 @@ function posAtCoordsImprecise(view, contentRect, block, x, y2) {
38526
38623
  return block.from + findColumn(content2, into, view.state.tabSize);
38527
38624
  }
38528
38625
  function isSuspiciousSafariCaretResult(node, offset, x) {
38529
- let len;
38626
+ let len, scan = node;
38530
38627
  if (node.nodeType != 3 || offset != (len = node.nodeValue.length))
38531
38628
  return false;
38532
- for (let next = node.nextSibling; next; next = next.nextSibling)
38533
- if (next.nodeType != 1 || next.nodeName != "BR")
38629
+ for (; ; ) {
38630
+ let next = scan.nextSibling;
38631
+ if (next) {
38632
+ if (next.nodeName == "BR")
38633
+ break;
38534
38634
  return false;
38535
- return textRange(node, len - 1, len).getBoundingClientRect().left > x;
38635
+ } else {
38636
+ let parent = scan.parentNode;
38637
+ if (!parent || parent.nodeName == "DIV")
38638
+ break;
38639
+ scan = parent;
38640
+ }
38641
+ }
38642
+ return textRange(node, len - 1, len).getBoundingClientRect().right > x;
38536
38643
  }
38537
38644
  function isSuspiciousChromeCaretResult(node, offset, x) {
38538
38645
  if (offset != 0)
@@ -38548,17 +38655,26 @@ function isSuspiciousChromeCaretResult(node, offset, x) {
38548
38655
  let rect = node.nodeType == 1 ? node.getBoundingClientRect() : textRange(node, 0, Math.max(node.nodeValue.length, 1)).getBoundingClientRect();
38549
38656
  return x - rect.left > 5;
38550
38657
  }
38551
- function blockAt(view, pos) {
38658
+ function blockAt(view, pos, side) {
38552
38659
  let line = view.lineBlockAt(pos);
38553
- if (Array.isArray(line.type))
38660
+ if (Array.isArray(line.type)) {
38661
+ let best;
38554
38662
  for (let l2 of line.type) {
38555
- if (l2.to > pos || l2.to == pos && (l2.to == line.to || l2.type == BlockType.Text))
38663
+ if (l2.from > pos)
38664
+ break;
38665
+ if (l2.to < pos)
38666
+ continue;
38667
+ if (l2.from < pos && l2.to > pos)
38556
38668
  return l2;
38669
+ if (!best || l2.type == BlockType.Text && (best.type != l2.type || (side < 0 ? l2.from < pos : l2.to > pos)))
38670
+ best = l2;
38557
38671
  }
38672
+ return best || line;
38673
+ }
38558
38674
  return line;
38559
38675
  }
38560
38676
  function moveToLineBoundary(view, start, forward, includeWrap) {
38561
- let line = blockAt(view, start.head);
38677
+ let line = blockAt(view, start.head, start.assoc || -1);
38562
38678
  let coords = !includeWrap || line.type != BlockType.Text || !(view.lineWrapping || line.widgetLineBreaks) ? null : view.coordsAtPos(start.assoc < 0 && start.head > line.from ? start.head - 1 : start.head);
38563
38679
  if (coords) {
38564
38680
  let editorRect = view.dom.getBoundingClientRect();
@@ -38650,6 +38766,28 @@ function skipAtomicRanges(atoms, pos, bias) {
38650
38766
  return pos;
38651
38767
  }
38652
38768
  }
38769
+ function skipAtomsForSelection(atoms, sel) {
38770
+ let ranges = null;
38771
+ for (let i = 0; i < sel.ranges.length; i++) {
38772
+ let range = sel.ranges[i], updated = null;
38773
+ if (range.empty) {
38774
+ let pos = skipAtomicRanges(atoms, range.from, 0);
38775
+ if (pos != range.from)
38776
+ updated = EditorSelection.cursor(pos, -1);
38777
+ } else {
38778
+ let from = skipAtomicRanges(atoms, range.from, -1);
38779
+ let to2 = skipAtomicRanges(atoms, range.to, 1);
38780
+ if (from != range.from || to2 != range.to)
38781
+ updated = EditorSelection.range(range.from == range.anchor ? from : to2, range.from == range.head ? from : to2);
38782
+ }
38783
+ if (updated) {
38784
+ if (!ranges)
38785
+ ranges = sel.ranges.slice();
38786
+ ranges[i] = updated;
38787
+ }
38788
+ }
38789
+ return ranges ? EditorSelection.create(ranges, sel.mainIndex) : sel;
38790
+ }
38653
38791
  function skipAtoms(view, oldPos, pos) {
38654
38792
  let newPos = skipAtomicRanges(view.state.facet(atomicRanges).map((f) => f(view)), pos.from, oldPos.head > pos.from ? -1 : 1);
38655
38793
  return newPos == pos.from ? pos : EditorSelection.cursor(newPos, newPos < pos.from ? 1 : -1);
@@ -38822,16 +38960,16 @@ function applyDOMChange(view, domChange) {
38822
38960
  return false;
38823
38961
  if (!change && domChange.typeOver && !sel.empty && newSel && newSel.main.empty) {
38824
38962
  change = { from: sel.from, to: sel.to, insert: view.state.doc.slice(sel.from, sel.to) };
38963
+ } else if ((browser.mac || browser.android) && change && change.from == change.to && change.from == sel.head - 1 && /^\. ?$/.test(change.insert.toString()) && view.contentDOM.getAttribute("autocorrect") == "off") {
38964
+ if (newSel && change.insert.length == 2)
38965
+ newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1);
38966
+ change = { from: change.from, to: change.to, insert: Text.of([change.insert.toString().replace(".", " ")]) };
38825
38967
  } else if (change && change.from >= sel.from && change.to <= sel.to && (change.from != sel.from || change.to != sel.to) && sel.to - sel.from - (change.to - change.from) <= 4) {
38826
38968
  change = {
38827
38969
  from: sel.from,
38828
38970
  to: sel.to,
38829
38971
  insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
38830
38972
  };
38831
- } else if ((browser.mac || browser.android) && change && change.from == change.to && change.from == sel.head - 1 && /^\. ?$/.test(change.insert.toString()) && view.contentDOM.getAttribute("autocorrect") == "off") {
38832
- if (newSel && change.insert.length == 2)
38833
- newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1);
38834
- change = { from: sel.from, to: sel.to, insert: Text.of([" "]) };
38835
38973
  } else if (browser.chrome && change && change.from == change.to && change.from == sel.head && change.insert.toString() == "\n " && view.lineWrapping) {
38836
38974
  if (newSel)
38837
38975
  newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1);
@@ -38845,6 +38983,8 @@ function applyDOMChange(view, domChange) {
38845
38983
  if (view.inputState.lastSelectionOrigin == "select")
38846
38984
  scrollIntoView2 = true;
38847
38985
  userEvent = view.inputState.lastSelectionOrigin;
38986
+ if (userEvent == "select.pointer")
38987
+ newSel = skipAtomsForSelection(view.state.facet(atomicRanges).map((f) => f(view)), newSel);
38848
38988
  }
38849
38989
  view.dispatch({ selection: newSel, scrollIntoView: scrollIntoView2, userEvent });
38850
38990
  return true;
@@ -39008,7 +39148,10 @@ class InputState {
39008
39148
  return;
39009
39149
  if (event.type == "keydown" && this.keydown(event))
39010
39150
  return;
39011
- this.runHandlers(event.type, event);
39151
+ if (this.view.updateState != 0)
39152
+ Promise.resolve().then(() => this.runHandlers(event.type, event));
39153
+ else
39154
+ this.runHandlers(event.type, event);
39012
39155
  }
39013
39156
  runHandlers(type, event) {
39014
39157
  let handlers2 = this.handlers[type];
@@ -39118,16 +39261,16 @@ function computeHandlers(plugins) {
39118
39261
  return result[type] || (result[type] = { observers: [], handlers: [] });
39119
39262
  }
39120
39263
  for (let plugin of plugins) {
39121
- let spec = plugin.spec;
39122
- if (spec && spec.domEventHandlers)
39123
- for (let type in spec.domEventHandlers) {
39124
- let f = spec.domEventHandlers[type];
39264
+ let spec = plugin.spec, handlers2 = spec && spec.plugin.domEventHandlers, observers2 = spec && spec.plugin.domEventObservers;
39265
+ if (handlers2)
39266
+ for (let type in handlers2) {
39267
+ let f = handlers2[type];
39125
39268
  if (f)
39126
39269
  record(type).handlers.push(bindHandler(plugin.value, f));
39127
39270
  }
39128
- if (spec && spec.domEventObservers)
39129
- for (let type in spec.domEventObservers) {
39130
- let f = spec.domEventObservers[type];
39271
+ if (observers2)
39272
+ for (let type in observers2) {
39273
+ let f = observers2[type];
39131
39274
  if (f)
39132
39275
  record(type).observers.push(bindHandler(plugin.value, f));
39133
39276
  }
@@ -39237,30 +39380,8 @@ class MouseSelection {
39237
39380
  if (this.dragging === false)
39238
39381
  this.select(this.lastEvent);
39239
39382
  }
39240
- skipAtoms(sel) {
39241
- let ranges = null;
39242
- for (let i = 0; i < sel.ranges.length; i++) {
39243
- let range = sel.ranges[i], updated = null;
39244
- if (range.empty) {
39245
- let pos = skipAtomicRanges(this.atoms, range.from, 0);
39246
- if (pos != range.from)
39247
- updated = EditorSelection.cursor(pos, -1);
39248
- } else {
39249
- let from = skipAtomicRanges(this.atoms, range.from, -1);
39250
- let to2 = skipAtomicRanges(this.atoms, range.to, 1);
39251
- if (from != range.from || to2 != range.to)
39252
- updated = EditorSelection.range(range.from == range.anchor ? from : to2, range.from == range.head ? from : to2);
39253
- }
39254
- if (updated) {
39255
- if (!ranges)
39256
- ranges = sel.ranges.slice();
39257
- ranges[i] = updated;
39258
- }
39259
- }
39260
- return ranges ? EditorSelection.create(ranges, sel.mainIndex) : sel;
39261
- }
39262
39383
  select(event) {
39263
- let { view } = this, selection2 = this.skipAtoms(this.style.get(event, this.extend, this.multiple));
39384
+ let { view } = this, selection2 = skipAtomsForSelection(this.atoms, this.style.get(event, this.extend, this.multiple));
39264
39385
  if (this.mustSelect || !selection2.eq(view.state.selection, this.dragging === false))
39265
39386
  this.view.dispatch({
39266
39387
  selection: selection2,
@@ -39407,6 +39528,8 @@ handlers.mousedown = (view, event) => {
39407
39528
  mouseSel.start(event);
39408
39529
  return mouseSel.dragging === false;
39409
39530
  }
39531
+ } else {
39532
+ view.inputState.setSelectionOrigin("select.pointer");
39410
39533
  }
39411
39534
  return false;
39412
39535
  };
@@ -39465,15 +39588,15 @@ function basicMouseSelection(view, event) {
39465
39588
  startSel = startSel.map(update.changes);
39466
39589
  }
39467
39590
  },
39468
- get(event2, extend2, multiple) {
39591
+ get(event2, extend, multiple) {
39469
39592
  let cur2 = queryPos(view, event2), removed;
39470
39593
  let range = rangeForClick(view, cur2.pos, cur2.bias, type);
39471
- if (start.pos != cur2.pos && !extend2) {
39594
+ if (start.pos != cur2.pos && !extend) {
39472
39595
  let startRange = rangeForClick(view, start.pos, start.bias, type);
39473
39596
  let from = Math.min(startRange.from, range.from), to2 = Math.max(startRange.to, range.to);
39474
39597
  range = from < range.from ? EditorSelection.range(from, to2) : EditorSelection.range(to2, from);
39475
39598
  }
39476
- if (extend2)
39599
+ if (extend)
39477
39600
  return startSel.replaceRange(startSel.main.extend(range.from, range.to));
39478
39601
  else if (multiple && type == 1 && startSel.ranges.length > 1 && (removed = removeRangeAround(startSel, cur2.pos)))
39479
39602
  return removed;
@@ -39644,7 +39767,7 @@ function focusChangeTransaction(state, focus) {
39644
39767
  if (effect)
39645
39768
  effects.push(effect);
39646
39769
  }
39647
- return effects ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
39770
+ return effects.length ? state.update({ effects, annotations: isFocusChange.of(true) }) : null;
39648
39771
  }
39649
39772
  function updateForFocusChange(view) {
39650
39773
  setTimeout(() => {
@@ -39768,7 +39891,7 @@ class HeightOracle {
39768
39891
  heightForLine(length) {
39769
39892
  if (!this.lineWrapping)
39770
39893
  return this.lineHeight;
39771
- let lines = 1 + Math.max(0, Math.ceil((length - this.lineLength) / (this.lineLength - 5)));
39894
+ let lines = 1 + Math.max(0, Math.ceil((length - this.lineLength) / Math.max(1, this.lineLength - 5)));
39772
39895
  return lines * this.lineHeight;
39773
39896
  }
39774
39897
  setDoc(doc2) {
@@ -40467,6 +40590,10 @@ function visiblePixelRange(dom, paddingTop) {
40467
40590
  bottom: Math.max(top2, bottom) - (rect.top + paddingTop)
40468
40591
  };
40469
40592
  }
40593
+ function inWindow(elt) {
40594
+ let rect = elt.getBoundingClientRect(), win = elt.ownerDocument.defaultView || window;
40595
+ return rect.left < win.innerWidth && rect.right > 0 && rect.top < win.innerHeight && rect.bottom > 0;
40596
+ }
40470
40597
  function fullPixelRange(dom, paddingTop) {
40471
40598
  let rect = dom.getBoundingClientRect();
40472
40599
  return {
@@ -40601,7 +40728,7 @@ class ViewState {
40601
40728
  this.scrollAnchorHeight = scrollAnchor.top;
40602
40729
  } else {
40603
40730
  this.scrollAnchorPos = -1;
40604
- this.scrollAnchorHeight = this.heightMap.height;
40731
+ this.scrollAnchorHeight = prevHeight;
40605
40732
  }
40606
40733
  let viewport = heightChanges.length ? this.mapViewport(this.viewport, update.changes) : this.viewport;
40607
40734
  if (scrollTarget && (scrollTarget.range.head < viewport.from || scrollTarget.range.head > viewport.to) || !this.viewportIsAppropriate(viewport))
@@ -40613,7 +40740,7 @@ class ViewState {
40613
40740
  this.updateViewportLines();
40614
40741
  if (this.lineGaps.length || this.viewport.to - this.viewport.from > 2e3 << 1)
40615
40742
  this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
40616
- update.flags |= this.computeVisibleRanges();
40743
+ update.flags |= this.computeVisibleRanges(update.changes);
40617
40744
  if (scrollTarget)
40618
40745
  this.scrollTarget = scrollTarget;
40619
40746
  if (!this.mustEnforceCursorAssoc && update.selectionSet && update.view.lineWrapping && update.state.selection.main.empty && update.state.selection.main.assoc && !update.state.facet(nativeSelectionHidden))
@@ -40635,7 +40762,7 @@ class ViewState {
40635
40762
  if (scaleX > 5e-3 && Math.abs(this.scaleX - scaleX) > 5e-3 || scaleY > 5e-3 && Math.abs(this.scaleY - scaleY) > 5e-3) {
40636
40763
  this.scaleX = scaleX;
40637
40764
  this.scaleY = scaleY;
40638
- result |= 8;
40765
+ result |= 16;
40639
40766
  refresh = measureContent = true;
40640
40767
  }
40641
40768
  }
@@ -40644,13 +40771,13 @@ class ViewState {
40644
40771
  if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
40645
40772
  this.paddingTop = paddingTop;
40646
40773
  this.paddingBottom = paddingBottom;
40647
- result |= 8 | 2;
40774
+ result |= 16 | 2;
40648
40775
  }
40649
40776
  if (this.editorWidth != view.scrollDOM.clientWidth) {
40650
40777
  if (oracle.lineWrapping)
40651
40778
  measureContent = true;
40652
40779
  this.editorWidth = view.scrollDOM.clientWidth;
40653
- result |= 8;
40780
+ result |= 16;
40654
40781
  }
40655
40782
  let scrollTop = view.scrollDOM.scrollTop * this.scaleY;
40656
40783
  if (this.scrollTop != scrollTop) {
@@ -40667,13 +40794,13 @@ class ViewState {
40667
40794
  if (inView)
40668
40795
  measureContent = true;
40669
40796
  }
40670
- if (!this.inView && !this.scrollTarget)
40797
+ if (!this.inView && !this.scrollTarget && !inWindow(view.dom))
40671
40798
  return 0;
40672
40799
  let contentWidth = domRect.width;
40673
40800
  if (this.contentDOMWidth != contentWidth || this.editorHeight != view.scrollDOM.clientHeight) {
40674
40801
  this.contentDOMWidth = domRect.width;
40675
40802
  this.editorHeight = view.scrollDOM.clientHeight;
40676
- result |= 8;
40803
+ result |= 16;
40677
40804
  }
40678
40805
  if (measureContent) {
40679
40806
  let lineHeights = view.docView.measureVisibleLineHeights(this.viewport);
@@ -40681,10 +40808,10 @@ class ViewState {
40681
40808
  refresh = true;
40682
40809
  if (refresh || oracle.lineWrapping && Math.abs(contentWidth - this.contentDOMWidth) > oracle.charWidth) {
40683
40810
  let { lineHeight, charWidth, textHeight } = view.docView.measureTextSize();
40684
- refresh = lineHeight > 0 && oracle.refresh(whiteSpace, lineHeight, charWidth, textHeight, contentWidth / charWidth, lineHeights);
40811
+ refresh = lineHeight > 0 && oracle.refresh(whiteSpace, lineHeight, charWidth, textHeight, Math.max(5, contentWidth / charWidth), lineHeights);
40685
40812
  if (refresh) {
40686
40813
  view.docView.minWidth = 0;
40687
- result |= 8;
40814
+ result |= 16;
40688
40815
  }
40689
40816
  }
40690
40817
  if (dTop > 0 && dBottom > 0)
@@ -40886,7 +41013,7 @@ class ViewState {
40886
41013
  this.lineGapDeco = Decoration.set(gaps.map((gap) => gap.draw(this, this.heightOracle.lineWrapping)));
40887
41014
  }
40888
41015
  }
40889
- computeVisibleRanges() {
41016
+ computeVisibleRanges(changes) {
40890
41017
  let deco = this.stateDeco;
40891
41018
  if (this.lineGaps.length)
40892
41019
  deco = deco.concat(this.lineGapDeco);
@@ -40898,9 +41025,21 @@ class ViewState {
40898
41025
  point() {
40899
41026
  }
40900
41027
  }, 20);
40901
- let changed = ranges.length != this.visibleRanges.length || this.visibleRanges.some((r, i) => r.from != ranges[i].from || r.to != ranges[i].to);
41028
+ let changed = 0;
41029
+ if (ranges.length != this.visibleRanges.length) {
41030
+ changed = 8 | 4;
41031
+ } else {
41032
+ for (let i = 0; i < ranges.length && !(changed & 8); i++) {
41033
+ let old = this.visibleRanges[i], nw = ranges[i];
41034
+ if (old.from != nw.from || old.to != nw.to) {
41035
+ changed |= 4;
41036
+ if (!(changes && changes.mapPos(old.from, -1) == nw.from && changes.mapPos(old.to, 1) == nw.to))
41037
+ changed |= 8;
41038
+ }
41039
+ }
41040
+ }
40902
41041
  this.visibleRanges = ranges;
40903
- return changed ? 4 : 0;
41042
+ return changed;
40904
41043
  }
40905
41044
  lineBlockAt(pos) {
40906
41045
  return pos >= this.viewport.from && pos <= this.viewport.to && this.viewportLines.find((b) => b.from <= pos && b.to >= pos) || scaleBlock(this.heightMap.lineAt(pos, QueryType$1.ByPos, this.heightOracle, 0, 0), this.scaler);
@@ -41157,7 +41296,7 @@ const baseTheme$1$3 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
41157
41296
  display: "none"
41158
41297
  },
41159
41298
  "&dark .cm-cursor": {
41160
- borderLeftColor: "#444"
41299
+ borderLeftColor: "#ddd"
41161
41300
  },
41162
41301
  ".cm-dropCursor": {
41163
41302
  position: "absolute"
@@ -41184,13 +41323,16 @@ const baseTheme$1$3 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
41184
41323
  display: "flex",
41185
41324
  height: "100%",
41186
41325
  boxSizing: "border-box",
41187
- insetInlineStart: 0,
41188
41326
  zIndex: 200
41189
41327
  },
41328
+ ".cm-gutters-before": { insetInlineStart: 0 },
41329
+ ".cm-gutters-after": { insetInlineEnd: 0 },
41190
41330
  "&light .cm-gutters": {
41191
41331
  backgroundColor: "#f5f5f5",
41192
41332
  color: "#6c6c6c",
41193
- borderRight: "1px solid #ddd"
41333
+ border: "0px solid #ddd",
41334
+ "&.cm-gutters-before": { borderRightWidth: "1px" },
41335
+ "&.cm-gutters-after": { borderLeftWidth: "1px" }
41194
41336
  },
41195
41337
  "&dark .cm-gutters": {
41196
41338
  backgroundColor: "#333338",
@@ -41241,6 +41383,21 @@ const baseTheme$1$3 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
41241
41383
  backgroundColor: "#333338",
41242
41384
  color: "white"
41243
41385
  },
41386
+ ".cm-dialog": {
41387
+ padding: "2px 19px 4px 6px",
41388
+ position: "relative",
41389
+ "& label": { fontSize: "80%" }
41390
+ },
41391
+ ".cm-dialog-close": {
41392
+ position: "absolute",
41393
+ top: "3px",
41394
+ right: "4px",
41395
+ backgroundColor: "inherit",
41396
+ border: "none",
41397
+ font: "inherit",
41398
+ fontSize: "14px",
41399
+ padding: "0"
41400
+ },
41244
41401
  ".cm-tab": {
41245
41402
  display: "inline-block",
41246
41403
  overflow: "hidden",
@@ -41255,7 +41412,8 @@ const baseTheme$1$3 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
41255
41412
  ".cm-placeholder": {
41256
41413
  color: "#888",
41257
41414
  display: "inline-block",
41258
- verticalAlign: "top"
41415
+ verticalAlign: "top",
41416
+ userSelect: "none"
41259
41417
  },
41260
41418
  ".cm-highlightSpace": {
41261
41419
  backgroundImage: "radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",
@@ -41344,7 +41502,7 @@ class DOMObserver {
41344
41502
  else
41345
41503
  this.flush();
41346
41504
  });
41347
- if (window.EditContext && view.constructor.EDIT_CONTEXT !== false && // Chrome <126 doesn't support inverted selections in edit context (#1392)
41505
+ if (window.EditContext && browser.android && view.constructor.EDIT_CONTEXT !== false && // Chrome <126 doesn't support inverted selections in edit context (#1392)
41348
41506
  !(browser.chrome && browser.chrome_version < 126)) {
41349
41507
  this.editContext = new EditContextManager(view);
41350
41508
  if (view.state.facet(editable))
@@ -41764,6 +41922,7 @@ class EditContextManager {
41764
41922
  this.to = 0;
41765
41923
  this.pendingContextChange = null;
41766
41924
  this.handlers = /* @__PURE__ */ Object.create(null);
41925
+ this.composing = null;
41767
41926
  this.resetRange(view.state);
41768
41927
  let context = this.editContext = new window.EditContext({
41769
41928
  text: view.state.doc.sliceString(this.from, this.to),
@@ -41771,21 +41930,28 @@ class EditContextManager {
41771
41930
  selectionEnd: this.toContextPos(view.state.selection.main.head)
41772
41931
  });
41773
41932
  this.handlers.textupdate = (e2) => {
41774
- let { anchor } = view.state.selection.main;
41775
- let change = {
41776
- from: this.toEditorPos(e2.updateRangeStart),
41777
- to: this.toEditorPos(e2.updateRangeEnd),
41778
- insert: Text.of(e2.text.split("\n"))
41779
- };
41933
+ let main = view.state.selection.main, { anchor, head } = main;
41934
+ let from = this.toEditorPos(e2.updateRangeStart), to2 = this.toEditorPos(e2.updateRangeEnd);
41935
+ if (view.inputState.composing >= 0 && !this.composing)
41936
+ this.composing = { contextBase: e2.updateRangeStart, editorBase: from, drifted: false };
41937
+ let change = { from, to: to2, insert: Text.of(e2.text.split("\n")) };
41780
41938
  if (change.from == this.from && anchor < this.from)
41781
41939
  change.from = anchor;
41782
41940
  else if (change.to == this.to && anchor > this.to)
41783
41941
  change.to = anchor;
41784
- if (change.from == change.to && !change.insert.length)
41942
+ if (change.from == change.to && !change.insert.length) {
41943
+ let newSel = EditorSelection.single(this.toEditorPos(e2.selectionStart), this.toEditorPos(e2.selectionEnd));
41944
+ if (!newSel.main.eq(main))
41945
+ view.dispatch({ selection: newSel, userEvent: "select" });
41785
41946
  return;
41947
+ }
41948
+ if ((browser.mac || browser.android) && change.from == head - 1 && /^\. ?$/.test(e2.text) && view.contentDOM.getAttribute("autocorrect") == "off")
41949
+ change = { from, to: to2, insert: Text.of([e2.text.replace(".", " ")]) };
41786
41950
  this.pendingContextChange = change;
41787
- if (!view.state.readOnly)
41788
- applyDOMChangeInner(view, change, EditorSelection.single(this.toEditorPos(e2.selectionStart), this.toEditorPos(e2.selectionEnd)));
41951
+ if (!view.state.readOnly) {
41952
+ let newLen = this.to - this.from + (change.to - change.from + change.insert.length);
41953
+ applyDOMChangeInner(view, change, EditorSelection.single(this.toEditorPos(e2.selectionStart, newLen), this.toEditorPos(e2.selectionEnd, newLen)));
41954
+ }
41789
41955
  if (this.pendingContextChange) {
41790
41956
  this.revertPending(view.state);
41791
41957
  this.setSelection(view.state);
@@ -41805,8 +41971,11 @@ class EditContextManager {
41805
41971
  for (let format of e2.getTextFormats()) {
41806
41972
  let lineStyle = format.underlineStyle, thickness = format.underlineThickness;
41807
41973
  if (lineStyle != "None" && thickness != "None") {
41808
- let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
41809
- deco.push(Decoration.mark({ attributes: { style } }).range(this.toEditorPos(format.rangeStart), this.toEditorPos(format.rangeEnd)));
41974
+ let from = this.toEditorPos(format.rangeStart), to2 = this.toEditorPos(format.rangeEnd);
41975
+ if (from < to2) {
41976
+ let style = `text-decoration: underline ${lineStyle == "Dashed" ? "dashed " : lineStyle == "Squiggle" ? "wavy " : ""}${thickness == "Thin" ? 1 : 2}px`;
41977
+ deco.push(Decoration.mark({ attributes: { style } }).range(from, to2));
41978
+ }
41810
41979
  }
41811
41980
  }
41812
41981
  view.dispatch({ effects: setEditContextFormatting.of(Decoration.set(deco)) });
@@ -41820,6 +41989,12 @@ class EditContextManager {
41820
41989
  this.handlers.compositionend = () => {
41821
41990
  view.inputState.composing = -1;
41822
41991
  view.inputState.compositionFirstChange = null;
41992
+ if (this.composing) {
41993
+ let { drifted } = this.composing;
41994
+ this.composing = null;
41995
+ if (drifted)
41996
+ this.reset(view.state);
41997
+ }
41823
41998
  };
41824
41999
  for (let event in this.handlers)
41825
42000
  context.addEventListener(event, this.handlers[event]);
@@ -41867,12 +42042,13 @@ class EditContextManager {
41867
42042
  return !abort;
41868
42043
  }
41869
42044
  update(update) {
41870
- let reverted = this.pendingContextChange;
41871
- if (!this.applyEdits(update) || !this.rangeIsValid(update.state)) {
42045
+ let reverted = this.pendingContextChange, startSel = update.startState.selection.main;
42046
+ if (this.composing && (this.composing.drifted || !update.changes.touchesRange(startSel.from, startSel.to) && update.transactions.some((tr) => !tr.isUserEvent("input.type") && tr.changes.touchesRange(this.from, this.to)))) {
42047
+ this.composing.drifted = true;
42048
+ this.composing.editorBase = update.changes.mapPos(this.composing.editorBase);
42049
+ } else if (!this.applyEdits(update) || !this.rangeIsValid(update.state)) {
41872
42050
  this.pendingContextChange = null;
41873
- this.resetRange(update.state);
41874
- this.editContext.updateText(0, this.editContext.text.length, update.state.doc.sliceString(this.from, this.to));
41875
- this.setSelection(update.state);
42051
+ this.reset(update.state);
41876
42052
  } else if (update.docChanged || update.selectionSet || reverted) {
41877
42053
  this.setSelection(update.state);
41878
42054
  }
@@ -41892,6 +42068,11 @@ class EditContextManager {
41892
42068
  /* CxVp.Margin */
41893
42069
  );
41894
42070
  }
42071
+ reset(state) {
42072
+ this.resetRange(state);
42073
+ this.editContext.updateText(0, this.editContext.text.length, state.doc.sliceString(this.from, this.to));
42074
+ this.setSelection(state);
42075
+ }
41895
42076
  revertPending(state) {
41896
42077
  let pending = this.pendingContextChange;
41897
42078
  this.pendingContextChange = null;
@@ -41908,11 +42089,14 @@ class EditContextManager {
41908
42089
  let { head } = state.selection.main;
41909
42090
  return !(this.from > 0 && head - this.from < 500 || this.to < state.doc.length && this.to - head < 500 || this.to - this.from > 1e4 * 3);
41910
42091
  }
41911
- toEditorPos(contextPos) {
41912
- return contextPos + this.from;
42092
+ toEditorPos(contextPos, clipLen = this.to - this.from) {
42093
+ contextPos = Math.min(contextPos, clipLen);
42094
+ let c2 = this.composing;
42095
+ return c2 && c2.drifted ? c2.editorBase + (contextPos - c2.contextBase) : contextPos + this.from;
41913
42096
  }
41914
42097
  toContextPos(editorPos) {
41915
- return editorPos - this.from;
42098
+ let c2 = this.composing;
42099
+ return c2 && c2.drifted ? c2.contextBase + (editorPos - c2.editorBase) : editorPos - this.from;
41916
42100
  }
41917
42101
  destroy() {
41918
42102
  for (let event in this.handlers)
@@ -41960,7 +42144,7 @@ class EditorView {
41960
42144
  one change has been made in the current composition.
41961
42145
  */
41962
42146
  get composing() {
41963
- return this.inputState.composing > 0;
42147
+ return !!this.inputState && this.inputState.composing > 0;
41964
42148
  }
41965
42149
  /**
41966
42150
  Indicates whether the user is currently in composing state. Note
@@ -41969,7 +42153,7 @@ class EditorView {
41969
42153
  composition there.
41970
42154
  */
41971
42155
  get compositionStarted() {
41972
- return this.inputState.composing >= 0;
42156
+ return !!this.inputState && this.inputState.composing >= 0;
41973
42157
  }
41974
42158
  /**
41975
42159
  The document or shadow root that the view lives in.
@@ -42335,6 +42519,7 @@ class EditorView {
42335
42519
  spellcheck: "false",
42336
42520
  autocorrect: "off",
42337
42521
  autocapitalize: "off",
42522
+ writingsuggestions: "false",
42338
42523
  translate: "no",
42339
42524
  contenteditable: !this.state.facet(editable) ? "false" : "true",
42340
42525
  class: "cm-content",
@@ -42409,8 +42594,8 @@ class EditorView {
42409
42594
  */
42410
42595
  plugin(plugin) {
42411
42596
  let known = this.pluginMap.get(plugin);
42412
- if (known === void 0 || known && known.spec != plugin)
42413
- this.pluginMap.set(plugin, known = this.plugins.find((p) => p.spec == plugin) || null);
42597
+ if (known === void 0 || known && known.plugin != plugin)
42598
+ this.pluginMap.set(plugin, known = this.plugins.find((p) => p.plugin == plugin) || null);
42414
42599
  return known && known.update(this).value;
42415
42600
  }
42416
42601
  /**
@@ -42452,7 +42637,7 @@ class EditorView {
42452
42637
  }
42453
42638
  /**
42454
42639
  Find the line block (see
42455
- [`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt) at the given
42640
+ [`lineBlockAt`](https://codemirror.net/6/docs/ref/#view.EditorView.lineBlockAt)) at the given
42456
42641
  height, again interpreted relative to the [top of the
42457
42642
  document](https://codemirror.net/6/docs/ref/#view.EditorView.documentTop).
42458
42643
  */
@@ -43060,7 +43245,8 @@ function runHandlers(map, event, view, scope) {
43060
43245
  if (runFor(scopeObj[prefix + modifiers(name2, event, !isChar)])) {
43061
43246
  handled = true;
43062
43247
  } else if (isChar && (event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
43063
- !(browser.windows && event.ctrlKey && event.altKey) && (baseName = base[event.keyCode]) && baseName != name2) {
43248
+ !(browser.windows && event.ctrlKey && event.altKey) && // Alt-combinations on macOS tend to be typed characters
43249
+ !(browser.mac && event.altKey && !(event.ctrlKey || event.metaKey)) && (baseName = base[event.keyCode]) && baseName != name2) {
43064
43250
  if (runFor(scopeObj[prefix + modifiers(baseName, event, true)])) {
43065
43251
  handled = true;
43066
43252
  } else if (event.shiftKey && (shiftName = shift[event.keyCode]) != name2 && shiftName != baseName && runFor(scopeObj[prefix + modifiers(shiftName, event, false)])) {
@@ -43158,7 +43344,7 @@ function rectanglesForRange(view, className, range) {
43158
43344
  let lineElt = content2.querySelector(".cm-line"), lineStyle = lineElt && window.getComputedStyle(lineElt);
43159
43345
  let leftSide = contentRect.left + (lineStyle ? parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent)) : 0);
43160
43346
  let rightSide = contentRect.right - (lineStyle ? parseInt(lineStyle.paddingRight) : 0);
43161
- let startBlock = blockAt(view, from), endBlock = blockAt(view, to2);
43347
+ let startBlock = blockAt(view, from, 1), endBlock = blockAt(view, to2, -1);
43162
43348
  let visualStart = startBlock.type == BlockType.Text ? startBlock : null;
43163
43349
  let visualEnd = endBlock.type == BlockType.Text ? endBlock : null;
43164
43350
  if (visualStart && (view.lineWrapping || startBlock.widgetLineBreaks))
@@ -43178,14 +43364,7 @@ function rectanglesForRange(view, className, range) {
43178
43364
  return pieces(top2).concat(between).concat(pieces(bottom));
43179
43365
  }
43180
43366
  function piece(left, top2, right, bottom) {
43181
- return new RectangleMarker(
43182
- className,
43183
- left - base2.left,
43184
- top2 - base2.top - 0.01,
43185
- right - left,
43186
- bottom - top2 + 0.01
43187
- /* C.Epsilon */
43188
- );
43367
+ return new RectangleMarker(className, left - base2.left, top2 - base2.top, right - left, bottom - top2);
43189
43368
  }
43190
43369
  function pieces({ top: top2, bottom, horizontal }) {
43191
43370
  let pieces2 = [];
@@ -43318,7 +43497,6 @@ function layer(config2) {
43318
43497
  layerOrder.of(config2)
43319
43498
  ];
43320
43499
  }
43321
- const CanHidePrimary = !browser.ios;
43322
43500
  const selectionConfig = /* @__PURE__ */ Facet.define({
43323
43501
  combine(configs) {
43324
43502
  return combineConfig(configs, {
@@ -43349,7 +43527,7 @@ const cursorLayer = /* @__PURE__ */ layer({
43349
43527
  let cursors = [];
43350
43528
  for (let r of state.selection.ranges) {
43351
43529
  let prim = r == state.selection.main;
43352
- if (r.empty ? !prim || CanHidePrimary : conf.drawRangeCursor) {
43530
+ if (r.empty || conf.drawRangeCursor) {
43353
43531
  let className = prim ? "cm-cursor cm-cursor-primary" : "cm-cursor cm-cursor-secondary";
43354
43532
  let cursor2 = r.empty ? r : EditorSelection.cursor(r.head, r.head > r.anchor ? -1 : 1);
43355
43533
  for (let piece of RectangleMarker.forRange(view, className, cursor2))
@@ -43384,11 +43562,13 @@ const selectionLayer = /* @__PURE__ */ layer({
43384
43562
  },
43385
43563
  class: "cm-selectionLayer"
43386
43564
  });
43387
- const themeSpec = {
43565
+ const hideNativeSelection = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ EditorView.theme({
43388
43566
  ".cm-line": {
43389
- "& ::selection, &::selection": { backgroundColor: "transparent !important" }
43567
+ "& ::selection, &::selection": { backgroundColor: "transparent !important" },
43568
+ caretColor: "transparent !important"
43390
43569
  },
43391
43570
  ".cm-content": {
43571
+ caretColor: "transparent !important",
43392
43572
  "& :focus": {
43393
43573
  caretColor: "initial !important",
43394
43574
  "&::selection, & ::selection": {
@@ -43396,10 +43576,7 @@ const themeSpec = {
43396
43576
  }
43397
43577
  }
43398
43578
  }
43399
- };
43400
- if (CanHidePrimary)
43401
- themeSpec[".cm-line"].caretColor = themeSpec[".cm-content"].caretColor = "transparent !important";
43402
- const hideNativeSelection = /* @__PURE__ */ Prec.highest(/* @__PURE__ */ EditorView.theme(themeSpec));
43579
+ }));
43403
43580
  const setDropCursorPos = /* @__PURE__ */ StateEffect.define({
43404
43581
  map(pos, mapping) {
43405
43582
  return pos == null ? null : mapping.mapPos(pos);
@@ -43559,12 +43736,12 @@ class MatchDecorator {
43559
43736
  let changeFrom = 1e9, changeTo = -1;
43560
43737
  if (update.docChanged)
43561
43738
  update.changes.iterChanges((_f, _t2, from, to2) => {
43562
- if (to2 > update.view.viewport.from && from < update.view.viewport.to) {
43739
+ if (to2 >= update.view.viewport.from && from <= update.view.viewport.to) {
43563
43740
  changeFrom = Math.min(from, changeFrom);
43564
43741
  changeTo = Math.max(to2, changeTo);
43565
43742
  }
43566
43743
  });
43567
- if (update.viewportChanged || changeTo - changeFrom > 1e3)
43744
+ if (update.viewportMoved || changeTo - changeFrom > 1e3)
43568
43745
  return this.createDeco(update.view);
43569
43746
  if (changeTo > -1)
43570
43747
  return this.updateRange(update.view, deco.map(update.changes), changeFrom, changeTo);
@@ -43573,7 +43750,7 @@ class MatchDecorator {
43573
43750
  updateRange(view, deco, updateFrom, updateTo) {
43574
43751
  for (let r of view.visibleRanges) {
43575
43752
  let from = Math.max(r.from, updateFrom), to2 = Math.min(r.to, updateTo);
43576
- if (to2 > from) {
43753
+ if (to2 >= from) {
43577
43754
  let fromLine = view.state.doc.lineAt(from), toLine = fromLine.to < to2 ? view.state.doc.lineAt(to2) : fromLine;
43578
43755
  let start = Math.max(r.from, fromLine.from), end = Math.min(r.to, toLine.to);
43579
43756
  if (this.boundary) {
@@ -43784,10 +43961,7 @@ class Placeholder extends WidgetType {
43784
43961
  wrap.className = "cm-placeholder";
43785
43962
  wrap.style.pointerEvents = "none";
43786
43963
  wrap.appendChild(typeof this.content == "string" ? document.createTextNode(this.content) : typeof this.content == "function" ? this.content(view) : this.content.cloneNode(true));
43787
- if (typeof this.content == "string")
43788
- wrap.setAttribute("aria-label", "placeholder " + this.content);
43789
- else
43790
- wrap.setAttribute("aria-hidden", "true");
43964
+ wrap.setAttribute("aria-hidden", "true");
43791
43965
  return wrap;
43792
43966
  }
43793
43967
  coordsAt(dom) {
@@ -43806,7 +43980,7 @@ class Placeholder extends WidgetType {
43806
43980
  }
43807
43981
  }
43808
43982
  function placeholder(content2) {
43809
- return ViewPlugin.fromClass(class {
43983
+ let plugin = ViewPlugin.fromClass(class {
43810
43984
  constructor(view) {
43811
43985
  this.view = view;
43812
43986
  this.placeholder = content2 ? Decoration.set([Decoration.widget({ widget: new Placeholder(content2), side: 1 }).range(0)]) : Decoration.none;
@@ -43815,6 +43989,10 @@ function placeholder(content2) {
43815
43989
  return this.view.state.doc.length ? Decoration.none : this.placeholder;
43816
43990
  }
43817
43991
  }, { decorations: (v) => v.decorations });
43992
+ return typeof content2 == "string" ? [
43993
+ plugin,
43994
+ EditorView.contentAttributes.of({ "aria-placeholder": content2 })
43995
+ ] : plugin;
43818
43996
  }
43819
43997
  const MaxOff = 2e3;
43820
43998
  function rectangleFor(state, a, b) {
@@ -43984,8 +44162,8 @@ class TooltipViewManager {
43984
44162
  }
43985
44163
  }
43986
44164
  function windowSpace(view) {
43987
- let { win } = view;
43988
- return { top: 0, left: 0, bottom: win.innerHeight, right: win.innerWidth };
44165
+ let docElt = view.dom.ownerDocument.documentElement;
44166
+ return { top: 0, left: 0, bottom: docElt.clientHeight, right: docElt.clientWidth };
43989
44167
  }
43990
44168
  const tooltipConfig = /* @__PURE__ */ Facet.define({
43991
44169
  combine: (values) => {
@@ -44112,7 +44290,6 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44112
44290
  clearTimeout(this.measureTimeout);
44113
44291
  }
44114
44292
  readMeasure() {
44115
- let editor = this.view.dom.getBoundingClientRect();
44116
44293
  let scaleX = 1, scaleY = 1, makeAbsolute = false;
44117
44294
  if (this.position == "fixed" && this.manager.tooltipViews.length) {
44118
44295
  let { dom } = this.manager.tooltipViews[0];
@@ -44134,9 +44311,15 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44134
44311
  ({ scaleX, scaleY } = this.view.viewState);
44135
44312
  }
44136
44313
  }
44314
+ let visible = this.view.scrollDOM.getBoundingClientRect(), margins = getScrollMargins(this.view);
44137
44315
  return {
44138
- editor,
44139
- parent: this.parent ? this.container.getBoundingClientRect() : editor,
44316
+ visible: {
44317
+ left: visible.left + margins.left,
44318
+ top: visible.top + margins.top,
44319
+ right: visible.right - margins.right,
44320
+ bottom: visible.bottom - margins.bottom
44321
+ },
44322
+ parent: this.parent ? this.container.getBoundingClientRect() : this.view.dom.getBoundingClientRect(),
44140
44323
  pos: this.manager.tooltips.map((t2, i) => {
44141
44324
  let tv = this.manager.tooltipViews[i];
44142
44325
  return tv.getCoords ? tv.getCoords(t2.pos) : this.view.coordsAtPos(t2.pos);
@@ -44156,12 +44339,12 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44156
44339
  for (let t2 of this.manager.tooltipViews)
44157
44340
  t2.dom.style.position = "absolute";
44158
44341
  }
44159
- let { editor, space, scaleX, scaleY } = measured;
44342
+ let { visible, space, scaleX, scaleY } = measured;
44160
44343
  let others = [];
44161
44344
  for (let i = 0; i < this.manager.tooltips.length; i++) {
44162
44345
  let tooltip = this.manager.tooltips[i], tView = this.manager.tooltipViews[i], { dom } = tView;
44163
44346
  let pos = measured.pos[i], size = measured.size[i];
44164
- if (!pos || pos.bottom <= Math.max(editor.top, space.top) || pos.top >= Math.min(editor.bottom, space.bottom) || pos.right < Math.max(editor.left, space.left) - 0.1 || pos.left > Math.min(editor.right, space.right) + 0.1) {
44347
+ if (!pos || tooltip.clip !== false && (pos.bottom <= Math.max(visible.top, space.top) || pos.top >= Math.min(visible.bottom, space.bottom) || pos.right < Math.max(visible.left, space.left) - 0.1 || pos.left > Math.min(visible.right, space.right) + 0.1)) {
44165
44348
  dom.style.top = Outside;
44166
44349
  continue;
44167
44350
  }
@@ -44171,7 +44354,7 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44171
44354
  let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
44172
44355
  let left = size.width > space.right - space.left ? ltr ? space.left : space.right - size.width : ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 : 0) + offset.x, space.right - width)) : Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 : 0) - offset.x), space.right - width);
44173
44356
  let above = this.above[i];
44174
- if (!tooltip.strictSide && (above ? pos.top - (size.bottom - size.top) - offset.y < space.top : pos.bottom + (size.bottom - size.top) + offset.y > space.bottom) && above == space.bottom - pos.bottom > pos.top - space.top)
44357
+ if (!tooltip.strictSide && (above ? pos.top - height - arrowHeight - offset.y < space.top : pos.bottom + height + arrowHeight + offset.y > space.bottom) && above == space.bottom - pos.bottom > pos.top - space.top)
44175
44358
  above = this.above[i] = !above;
44176
44359
  let spaceVert = (above ? pos.top - space.top : space.bottom - pos.bottom) - arrowHeight;
44177
44360
  if (spaceVert < height && tView.resize !== false) {
@@ -44193,10 +44376,10 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44193
44376
  }
44194
44377
  if (this.position == "absolute") {
44195
44378
  dom.style.top = (top2 - measured.parent.top) / scaleY + "px";
44196
- dom.style.left = (left - measured.parent.left) / scaleX + "px";
44379
+ setLeftStyle(dom, (left - measured.parent.left) / scaleX);
44197
44380
  } else {
44198
44381
  dom.style.top = top2 / scaleY + "px";
44199
- dom.style.left = left / scaleX + "px";
44382
+ setLeftStyle(dom, left / scaleX);
44200
44383
  }
44201
44384
  if (arrow) {
44202
44385
  let arrowLeft = pos.left + (ltr ? offset.x : -offset.x) - (left + 14 - 7);
@@ -44229,9 +44412,14 @@ const tooltipPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
44229
44412
  }
44230
44413
  }
44231
44414
  });
44415
+ function setLeftStyle(elt, value) {
44416
+ let current = parseInt(elt.style.left, 10);
44417
+ if (isNaN(current) || Math.abs(value - current) > 1)
44418
+ elt.style.left = value + "px";
44419
+ }
44232
44420
  const baseTheme$4 = /* @__PURE__ */ EditorView.baseTheme({
44233
44421
  ".cm-tooltip": {
44234
- zIndex: 100,
44422
+ zIndex: 500,
44235
44423
  boxSizing: "border-box"
44236
44424
  },
44237
44425
  "&light .cm-tooltip": {
@@ -44763,11 +44951,12 @@ const defaults$2 = {
44763
44951
  lineMarkerChange: null,
44764
44952
  initialSpacer: null,
44765
44953
  updateSpacer: null,
44766
- domEventHandlers: {}
44954
+ domEventHandlers: {},
44955
+ side: "before"
44767
44956
  };
44768
44957
  const activeGutters = /* @__PURE__ */ Facet.define();
44769
44958
  function gutter(config2) {
44770
- return [gutters(), activeGutters.of(Object.assign(Object.assign({}, defaults$2), config2))];
44959
+ return [gutters(), activeGutters.of({ ...defaults$2, ...config2 })];
44771
44960
  }
44772
44961
  const unfixGutters = /* @__PURE__ */ Facet.define({
44773
44962
  combine: (values) => values.some((x) => x)
@@ -44781,21 +44970,37 @@ function gutters(config2) {
44781
44970
  const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
44782
44971
  constructor(view) {
44783
44972
  this.view = view;
44973
+ this.domAfter = null;
44784
44974
  this.prevViewport = view.viewport;
44785
44975
  this.dom = document.createElement("div");
44786
- this.dom.className = "cm-gutters";
44976
+ this.dom.className = "cm-gutters cm-gutters-before";
44787
44977
  this.dom.setAttribute("aria-hidden", "true");
44788
44978
  this.dom.style.minHeight = this.view.contentHeight / this.view.scaleY + "px";
44789
44979
  this.gutters = view.state.facet(activeGutters).map((conf) => new SingleGutterView(view, conf));
44790
- for (let gutter2 of this.gutters)
44791
- this.dom.appendChild(gutter2.dom);
44792
44980
  this.fixed = !view.state.facet(unfixGutters);
44981
+ for (let gutter2 of this.gutters) {
44982
+ if (gutter2.config.side == "after")
44983
+ this.getDOMAfter().appendChild(gutter2.dom);
44984
+ else
44985
+ this.dom.appendChild(gutter2.dom);
44986
+ }
44793
44987
  if (this.fixed) {
44794
44988
  this.dom.style.position = "sticky";
44795
44989
  }
44796
44990
  this.syncGutters(false);
44797
44991
  view.scrollDOM.insertBefore(this.dom, view.contentDOM);
44798
44992
  }
44993
+ getDOMAfter() {
44994
+ if (!this.domAfter) {
44995
+ this.domAfter = document.createElement("div");
44996
+ this.domAfter.className = "cm-gutters cm-gutters-after";
44997
+ this.domAfter.setAttribute("aria-hidden", "true");
44998
+ this.domAfter.style.minHeight = this.view.contentHeight / this.view.scaleY + "px";
44999
+ this.domAfter.style.position = this.fixed ? "sticky" : "";
45000
+ this.view.scrollDOM.appendChild(this.domAfter);
45001
+ }
45002
+ return this.domAfter;
45003
+ }
44799
45004
  update(update) {
44800
45005
  if (this.updateGutters(update)) {
44801
45006
  let vpA = this.prevViewport, vpB = update.view.viewport;
@@ -44803,18 +45008,26 @@ const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
44803
45008
  this.syncGutters(vpOverlap < (vpB.to - vpB.from) * 0.8);
44804
45009
  }
44805
45010
  if (update.geometryChanged) {
44806
- this.dom.style.minHeight = this.view.contentHeight / this.view.scaleY + "px";
45011
+ let min = this.view.contentHeight / this.view.scaleY + "px";
45012
+ this.dom.style.minHeight = min;
45013
+ if (this.domAfter)
45014
+ this.domAfter.style.minHeight = min;
44807
45015
  }
44808
45016
  if (this.view.state.facet(unfixGutters) != !this.fixed) {
44809
45017
  this.fixed = !this.fixed;
44810
45018
  this.dom.style.position = this.fixed ? "sticky" : "";
45019
+ if (this.domAfter)
45020
+ this.domAfter.style.position = this.fixed ? "sticky" : "";
44811
45021
  }
44812
45022
  this.prevViewport = update.view.viewport;
44813
45023
  }
44814
45024
  syncGutters(detach) {
44815
45025
  let after = this.dom.nextSibling;
44816
- if (detach)
45026
+ if (detach) {
44817
45027
  this.dom.remove();
45028
+ if (this.domAfter)
45029
+ this.domAfter.remove();
45030
+ }
44818
45031
  let lineClasses = RangeSet.iter(this.view.state.facet(gutterLineClass), this.view.viewport.from);
44819
45032
  let classSet = [];
44820
45033
  let contexts = this.gutters.map((gutter2) => new UpdateContext(gutter2, this.view.viewport, -this.view.documentPadding.top));
@@ -44845,8 +45058,11 @@ const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
44845
45058
  }
44846
45059
  for (let cx of contexts)
44847
45060
  cx.finish();
44848
- if (detach)
45061
+ if (detach) {
44849
45062
  this.view.scrollDOM.insertBefore(this.dom, after);
45063
+ if (this.domAfter)
45064
+ this.view.scrollDOM.appendChild(this.domAfter);
45065
+ }
44850
45066
  }
44851
45067
  updateGutters(update) {
44852
45068
  let prev = update.startState.facet(activeGutters), cur2 = update.state.facet(activeGutters);
@@ -44872,8 +45088,12 @@ const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
44872
45088
  if (gutters2.indexOf(g) < 0)
44873
45089
  g.destroy();
44874
45090
  }
44875
- for (let g of gutters2)
44876
- this.dom.appendChild(g.dom);
45091
+ for (let g of gutters2) {
45092
+ if (g.config.side == "after")
45093
+ this.getDOMAfter().appendChild(g.dom);
45094
+ else
45095
+ this.dom.appendChild(g.dom);
45096
+ }
44877
45097
  this.gutters = gutters2;
44878
45098
  }
44879
45099
  return change;
@@ -44882,13 +45102,16 @@ const gutterView = /* @__PURE__ */ ViewPlugin.fromClass(class {
44882
45102
  for (let view of this.gutters)
44883
45103
  view.destroy();
44884
45104
  this.dom.remove();
45105
+ if (this.domAfter)
45106
+ this.domAfter.remove();
44885
45107
  }
44886
45108
  }, {
44887
45109
  provide: (plugin) => EditorView.scrollMargins.of((view) => {
44888
45110
  let value = view.plugin(plugin);
44889
45111
  if (!value || value.gutters.length == 0 || !value.fixed)
44890
45112
  return null;
44891
- return view.textDirection == Direction.LTR ? { left: value.dom.offsetWidth * view.scaleX } : { right: value.dom.offsetWidth * view.scaleX };
45113
+ let before = value.dom.offsetWidth * view.scaleX, after = value.domAfter ? value.domAfter.offsetWidth * view.scaleX : 0;
45114
+ return view.textDirection == Direction.LTR ? { left: before, right: after } : { right: before, left: after };
44892
45115
  })
44893
45116
  });
44894
45117
  function asArray(val) {
@@ -45128,7 +45351,8 @@ const lineNumberGutter = /* @__PURE__ */ activeGutters.compute([lineNumberConfig
45128
45351
  let max = formatNumber(update.view, maxLineNumber(update.view.state.doc.lines));
45129
45352
  return max == spacer.number ? spacer : new NumberMarker(max);
45130
45353
  },
45131
- domEventHandlers: state.facet(lineNumberConfig).domEventHandlers
45354
+ domEventHandlers: state.facet(lineNumberConfig).domEventHandlers,
45355
+ side: "before"
45132
45356
  }));
45133
45357
  function lineNumbers(config2 = {}) {
45134
45358
  return [
@@ -47014,11 +47238,11 @@ class HighlightBuilder {
47014
47238
  for (let i = 0, pos = start; ; i++) {
47015
47239
  let next = i < mounted.overlay.length ? mounted.overlay[i] : null;
47016
47240
  let nextPos = next ? next.from + start : end;
47017
- let rangeFrom = Math.max(from, pos), rangeTo = Math.min(to2, nextPos);
47018
- if (rangeFrom < rangeTo && hasChild2) {
47019
- while (cursor2.from < rangeTo) {
47020
- this.highlightRange(cursor2, rangeFrom, rangeTo, inheritedClass, highlighters);
47021
- this.startSpan(Math.min(rangeTo, cursor2.to), cls);
47241
+ let rangeFrom2 = Math.max(from, pos), rangeTo2 = Math.min(to2, nextPos);
47242
+ if (rangeFrom2 < rangeTo2 && hasChild2) {
47243
+ while (cursor2.from < rangeTo2) {
47244
+ this.highlightRange(cursor2, rangeFrom2, rangeTo2, inheritedClass, highlighters);
47245
+ this.startSpan(Math.min(rangeTo2, cursor2.to), cls);
47022
47246
  if (cursor2.to >= nextPos || !cursor2.nextSibling())
47023
47247
  break;
47024
47248
  }
@@ -48113,10 +48337,10 @@ class IndentContext {
48113
48337
  const indentNodeProp = /* @__PURE__ */ new NodeProp();
48114
48338
  function syntaxIndentation(cx, ast, pos) {
48115
48339
  let stack = ast.resolveStack(pos);
48116
- let inner = stack.node.enterUnfinishedNodesBefore(pos);
48340
+ let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
48117
48341
  if (inner != stack.node) {
48118
48342
  let add2 = [];
48119
- for (let cur2 = inner; cur2 != stack.node; cur2 = cur2.parent)
48343
+ for (let cur2 = inner; cur2 && !(cur2.from < stack.node.from || cur2.to > stack.node.to || cur2.from == stack.node.from && cur2.type == stack.node.type); cur2 = cur2.parent)
48120
48344
  add2.push(cur2);
48121
48345
  for (let i = add2.length - 1; i >= 0; i--)
48122
48346
  stack = { node: add2[i], next: stack };
@@ -48336,6 +48560,8 @@ const foldState = /* @__PURE__ */ StateField.define({
48336
48560
  return Decoration.none;
48337
48561
  },
48338
48562
  update(folded, tr) {
48563
+ if (tr.isUserEvent("delete"))
48564
+ tr.changes.iterChangedRanges((fromA, toA) => folded = clearTouchedFolds(folded, fromA, toA));
48339
48565
  folded = folded.map(tr.changes);
48340
48566
  for (let e2 of tr.effects) {
48341
48567
  if (e2.is(foldEffect) && !foldExists(folded, e2.value.from, e2.value.to)) {
@@ -48350,19 +48576,8 @@ const foldState = /* @__PURE__ */ StateField.define({
48350
48576
  });
48351
48577
  }
48352
48578
  }
48353
- if (tr.selection) {
48354
- let onSelection = false, { head } = tr.selection.main;
48355
- folded.between(head, head, (a, b) => {
48356
- if (a < head && b > head)
48357
- onSelection = true;
48358
- });
48359
- if (onSelection)
48360
- folded = folded.update({
48361
- filterFrom: head,
48362
- filterTo: head,
48363
- filter: (a, b) => b <= head || a >= head
48364
- });
48365
- }
48579
+ if (tr.selection)
48580
+ folded = clearTouchedFolds(folded, tr.selection.main.head);
48366
48581
  return folded;
48367
48582
  },
48368
48583
  provide: (f) => EditorView.decorations.from(f),
@@ -48386,6 +48601,18 @@ const foldState = /* @__PURE__ */ StateField.define({
48386
48601
  return Decoration.set(ranges, true);
48387
48602
  }
48388
48603
  });
48604
+ function clearTouchedFolds(folded, from, to2 = from) {
48605
+ let touched = false;
48606
+ folded.between(from, to2, (a, b) => {
48607
+ if (a < to2 && b > from)
48608
+ touched = true;
48609
+ });
48610
+ return !touched ? folded : folded.update({
48611
+ filterFrom: from,
48612
+ filterTo: to2,
48613
+ filter: (a, b) => a >= to2 || b <= from
48614
+ });
48615
+ }
48389
48616
  function findFold(state, from, to2) {
48390
48617
  var _a2;
48391
48618
  let found = null;
@@ -48538,7 +48765,7 @@ class FoldMarker extends GutterMarker {
48538
48765
  }
48539
48766
  }
48540
48767
  function foldGutter(config2 = {}) {
48541
- let fullConfig = Object.assign(Object.assign({}, foldGutterDefaults), config2);
48768
+ let fullConfig = { ...foldGutterDefaults, ...config2 };
48542
48769
  let canFold = new FoldMarker(fullConfig, true), canUnfold = new FoldMarker(fullConfig, false);
48543
48770
  let markers = ViewPlugin.fromClass(class {
48544
48771
  constructor(view) {
@@ -48571,21 +48798,24 @@ function foldGutter(config2 = {}) {
48571
48798
  initialSpacer() {
48572
48799
  return new FoldMarker(fullConfig, false);
48573
48800
  },
48574
- domEventHandlers: Object.assign(Object.assign({}, domEventHandlers), { click: (view, line, event) => {
48575
- if (domEventHandlers.click && domEventHandlers.click(view, line, event))
48576
- return true;
48577
- let folded = findFold(view.state, line.from, line.to);
48578
- if (folded) {
48579
- view.dispatch({ effects: unfoldEffect.of(folded) });
48580
- return true;
48581
- }
48582
- let range = foldable(view.state, line.from, line.to);
48583
- if (range) {
48584
- view.dispatch({ effects: foldEffect.of(range) });
48585
- return true;
48801
+ domEventHandlers: {
48802
+ ...domEventHandlers,
48803
+ click: (view, line, event) => {
48804
+ if (domEventHandlers.click && domEventHandlers.click(view, line, event))
48805
+ return true;
48806
+ let folded = findFold(view.state, line.from, line.to);
48807
+ if (folded) {
48808
+ view.dispatch({ effects: unfoldEffect.of(folded) });
48809
+ return true;
48810
+ }
48811
+ let range = foldable(view.state, line.from, line.to);
48812
+ if (range) {
48813
+ view.dispatch({ effects: foldEffect.of(range) });
48814
+ return true;
48815
+ }
48816
+ return false;
48586
48817
  }
48587
- return false;
48588
- } })
48818
+ }
48589
48819
  }),
48590
48820
  codeFolding()
48591
48821
  ];
@@ -49020,7 +49250,7 @@ const toggleBlockCommentByLine = /* @__PURE__ */ command(
49020
49250
  /* CommentOption.Toggle */
49021
49251
  );
49022
49252
  function getConfig(state, pos) {
49023
- let data = state.languageDataAt("commentTokens", pos);
49253
+ let data = state.languageDataAt("commentTokens", pos, 1);
49024
49254
  return data.length ? data[0] : {};
49025
49255
  }
49026
49256
  const SearchMargin = 50;
@@ -49063,6 +49293,8 @@ function selectedLineRanges(state) {
49063
49293
  for (let r of state.selection.ranges) {
49064
49294
  let fromLine = state.doc.lineAt(r.from);
49065
49295
  let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
49296
+ if (toLine.from > fromLine.from && toLine.from == r.to)
49297
+ toLine = r.to == fromLine.to + 1 ? fromLine : state.doc.lineAt(r.to - 1);
49066
49298
  let last = ranges.length - 1;
49067
49299
  if (last >= 0 && ranges[last].to > fromLine.from)
49068
49300
  ranges[last].to = toLine.to;
@@ -49533,7 +49765,7 @@ const cursorLineBoundaryLeft = (view) => moveSel(view, (range) => moveByLineBoun
49533
49765
  const cursorLineBoundaryRight = (view) => moveSel(view, (range) => moveByLineBoundary(view, range, ltrAtCursor(view)));
49534
49766
  const cursorLineStart = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
49535
49767
  const cursorLineEnd = (view) => moveSel(view, (range) => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
49536
- function toMatchingBracket(state, dispatch, extend2) {
49768
+ function toMatchingBracket(state, dispatch, extend) {
49537
49769
  let found = false, selection2 = updateSel(state.selection, (range) => {
49538
49770
  let matching = matchBrackets(state, range.head, -1) || matchBrackets(state, range.head, 1) || range.head > 0 && matchBrackets(state, range.head - 1, 1) || range.head < state.doc.length && matchBrackets(state, range.head + 1, -1);
49539
49771
  if (!matching || !matching.end)
@@ -50030,33 +50262,6 @@ const defaultKeymap = /* @__PURE__ */ [
50030
50262
  { key: "Ctrl-m", mac: "Shift-Alt-m", run: toggleTabFocusMode }
50031
50263
  ].concat(standardKeymap);
50032
50264
  const indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };
50033
- function crelt() {
50034
- var elt = arguments[0];
50035
- if (typeof elt == "string") elt = document.createElement(elt);
50036
- var i = 1, next = arguments[1];
50037
- if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) {
50038
- for (var name2 in next) if (Object.prototype.hasOwnProperty.call(next, name2)) {
50039
- var value = next[name2];
50040
- if (typeof value == "string") elt.setAttribute(name2, value);
50041
- else if (value != null) elt[name2] = value;
50042
- }
50043
- i++;
50044
- }
50045
- for (; i < arguments.length; i++) add(elt, arguments[i]);
50046
- return elt;
50047
- }
50048
- function add(elt, child) {
50049
- if (typeof child == "string") {
50050
- elt.appendChild(document.createTextNode(child));
50051
- } else if (child == null) ;
50052
- else if (child.nodeType != null) {
50053
- elt.appendChild(child);
50054
- } else if (Array.isArray(child)) {
50055
- for (var i = 0; i < child.length; i++) add(elt, child[i]);
50056
- } else {
50057
- throw new RangeError("Unsupported child node: " + child);
50058
- }
50059
- }
50060
50265
  const basicNormalize = typeof String.prototype.normalize == "function" ? (x) => x.normalize("NFKD") : (x) => x;
50061
50266
  class SearchCursor {
50062
50267
  /**
@@ -51258,15 +51463,19 @@ function ensureAnchor(expr, start) {
51258
51463
  const pickedCompletion = /* @__PURE__ */ Annotation.define();
51259
51464
  function insertCompletionText(state, text, from, to2) {
51260
51465
  let { main } = state.selection, fromOff = from - main.from, toOff = to2 - main.from;
51261
- return Object.assign(Object.assign({}, state.changeByRange((range) => {
51262
- if (range != main && from != to2 && state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to2))
51263
- return { range };
51264
- let lines = state.toText(text);
51265
- return {
51266
- changes: { from: range.from + fromOff, to: to2 == main.from ? range.to : range.from + toOff, insert: lines },
51267
- range: EditorSelection.cursor(range.from + fromOff + lines.length)
51268
- };
51269
- })), { scrollIntoView: true, userEvent: "input.complete" });
51466
+ return {
51467
+ ...state.changeByRange((range) => {
51468
+ if (range != main && from != to2 && state.sliceDoc(range.from + fromOff, range.from + toOff) != state.sliceDoc(from, to2))
51469
+ return { range };
51470
+ let lines = state.toText(text);
51471
+ return {
51472
+ changes: { from: range.from + fromOff, to: to2 == main.from ? range.to : range.from + toOff, insert: lines },
51473
+ range: EditorSelection.cursor(range.from + fromOff + lines.length)
51474
+ };
51475
+ }),
51476
+ scrollIntoView: true,
51477
+ userEvent: "input.complete"
51478
+ };
51270
51479
  }
51271
51480
  const SourceCache = /* @__PURE__ */ new WeakMap();
51272
51481
  function asSource(source) {
@@ -51696,8 +51905,8 @@ class CompletionTooltip {
51696
51905
  let selRect = sel.getBoundingClientRect();
51697
51906
  let space = this.space;
51698
51907
  if (!space) {
51699
- let win = this.dom.ownerDocument.defaultView || window;
51700
- space = { left: 0, top: 0, right: win.innerWidth, bottom: win.innerHeight };
51908
+ let docElt = this.dom.ownerDocument.documentElement;
51909
+ space = { left: 0, top: 0, right: docElt.clientWidth, bottom: docElt.clientHeight };
51701
51910
  }
51702
51911
  if (selRect.top > Math.min(space.bottom, listRect.bottom) - 10 || selRect.bottom < Math.max(space.top, listRect.top) + 10)
51703
51912
  return null;
@@ -51720,6 +51929,10 @@ class CompletionTooltip {
51720
51929
  ul.setAttribute("role", "listbox");
51721
51930
  ul.setAttribute("aria-expanded", "true");
51722
51931
  ul.setAttribute("aria-label", this.view.state.phrase("Completions"));
51932
+ ul.addEventListener("mousedown", (e2) => {
51933
+ if (e2.target == ul)
51934
+ e2.preventDefault();
51935
+ });
51723
51936
  let curSection = null;
51724
51937
  for (let i = range.from; i < range.to; i++) {
51725
51938
  let { completion, match } = options[i], { section } = completion;
@@ -51852,14 +52065,12 @@ class CompletionDialog {
51852
52065
  setSelected(selected, id) {
51853
52066
  return selected == this.selected || selected >= this.options.length ? this : new CompletionDialog(this.options, makeAttrs(id, selected), this.tooltip, this.timestamp, selected, this.disabled);
51854
52067
  }
51855
- static build(active, state, id, prev, conf) {
52068
+ static build(active, state, id, prev, conf, didSetActive) {
52069
+ if (prev && !didSetActive && active.some((s) => s.isPending))
52070
+ return prev.setDisabled();
51856
52071
  let options = sortOptions(active, state);
51857
- if (!options.length) {
51858
- return prev && active.some(
51859
- (a) => a.state == 1
51860
- /* State.Pending */
51861
- ) ? new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
51862
- }
52072
+ if (!options.length)
52073
+ return prev && active.some((a) => a.isPending) ? prev.setDisabled() : null;
51863
52074
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
51864
52075
  if (prev && prev.selected != selected && prev.selected != -1) {
51865
52076
  let selectedValue = prev.options[prev.selected].completion;
@@ -51876,7 +52087,10 @@ class CompletionDialog {
51876
52087
  }, prev ? prev.timestamp : Date.now(), selected, false);
51877
52088
  }
51878
52089
  map(changes) {
51879
- 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);
52090
+ return new CompletionDialog(this.options, this.attrs, { ...this.tooltip, pos: changes.mapPos(this.tooltip.pos) }, this.timestamp, this.selected, this.disabled);
52091
+ }
52092
+ setDisabled() {
52093
+ return new CompletionDialog(this.options, this.attrs, this.tooltip, this.timestamp, this.selected, true);
51880
52094
  }
51881
52095
  }
51882
52096
  class CompletionState {
@@ -51904,20 +52118,14 @@ class CompletionState {
51904
52118
  });
51905
52119
  if (active.length == this.active.length && active.every((a, i) => a == this.active[i]))
51906
52120
  active = this.active;
51907
- let open = this.open;
52121
+ let open = this.open, didSet = tr.effects.some((e2) => e2.is(setActiveEffect));
51908
52122
  if (open && tr.docChanged)
51909
52123
  open = open.map(tr.changes);
51910
- if (tr.selection || active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active))
51911
- open = CompletionDialog.build(active, state, this.id, open, conf);
51912
- else if (open && open.disabled && !active.some(
51913
- (a) => a.state == 1
51914
- /* State.Pending */
51915
- ))
52124
+ if (tr.selection || active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) || !sameResults(active, this.active) || didSet)
52125
+ open = CompletionDialog.build(active, state, this.id, open, conf, didSet);
52126
+ else if (open && open.disabled && !active.some((a) => a.isPending))
51916
52127
  open = null;
51917
- if (!open && active.every(
51918
- (a) => a.state != 1
51919
- /* State.Pending */
51920
- ) && active.some((a) => a.hasResult()))
52128
+ if (!open && active.every((a) => !a.isPending) && active.some((a) => a.hasResult()))
51921
52129
  active = active.map((a) => a.hasResult() ? new ActiveSource(
51922
52130
  a.source,
51923
52131
  0
@@ -51939,9 +52147,9 @@ function sameResults(a, b) {
51939
52147
  if (a == b)
51940
52148
  return true;
51941
52149
  for (let iA = 0, iB = 0; ; ) {
51942
- while (iA < a.length && !a[iA].hasResult)
52150
+ while (iA < a.length && !a[iA].hasResult())
51943
52151
  iA++;
51944
- while (iB < b.length && !b[iB].hasResult)
52152
+ while (iB < b.length && !b[iB].hasResult())
51945
52153
  iB++;
51946
52154
  let endA = iA == a.length, endB = iB == b.length;
51947
52155
  if (endA || endB)
@@ -51975,14 +52183,17 @@ function getUpdateType(tr, conf) {
51975
52183
  return typing && conf.activateOnTyping ? 4 | 1 : typing ? 1 : tr.isUserEvent("delete.backward") ? 2 : tr.selection ? 8 : tr.docChanged ? 16 : 0;
51976
52184
  }
51977
52185
  class ActiveSource {
51978
- constructor(source, state, explicitPos = -1) {
52186
+ constructor(source, state, explicit = false) {
51979
52187
  this.source = source;
51980
52188
  this.state = state;
51981
- this.explicitPos = explicitPos;
52189
+ this.explicit = explicit;
51982
52190
  }
51983
52191
  hasResult() {
51984
52192
  return false;
51985
52193
  }
52194
+ get isPending() {
52195
+ return this.state == 1;
52196
+ }
51986
52197
  update(tr, conf) {
51987
52198
  let type = getUpdateType(tr, conf), value = this;
51988
52199
  if (type & 8 || type & 16 && this.touches(tr))
@@ -52000,7 +52211,7 @@ class ActiveSource {
52000
52211
  value = value.updateFor(tr, type);
52001
52212
  for (let effect of tr.effects) {
52002
52213
  if (effect.is(startCompletionEffect))
52003
- value = new ActiveSource(value.source, 1, effect.value ? cur(tr.state) : -1);
52214
+ value = new ActiveSource(value.source, 1, effect.value);
52004
52215
  else if (effect.is(closeCompletionEffect))
52005
52216
  value = new ActiveSource(
52006
52217
  value.source,
@@ -52019,15 +52230,16 @@ class ActiveSource {
52019
52230
  return this.map(tr.changes);
52020
52231
  }
52021
52232
  map(changes) {
52022
- return changes.empty || this.explicitPos < 0 ? this : new ActiveSource(this.source, this.state, changes.mapPos(this.explicitPos));
52233
+ return this;
52023
52234
  }
52024
52235
  touches(tr) {
52025
52236
  return tr.changes.touchesRange(cur(tr.state));
52026
52237
  }
52027
52238
  }
52028
52239
  class ActiveResult extends ActiveSource {
52029
- constructor(source, explicitPos, result, from, to2) {
52030
- super(source, 2, explicitPos);
52240
+ constructor(source, explicit, limit, result, from, to2) {
52241
+ super(source, 3, explicit);
52242
+ this.limit = limit;
52031
52243
  this.result = result;
52032
52244
  this.from = from;
52033
52245
  this.to = to2;
@@ -52044,18 +52256,18 @@ class ActiveResult extends ActiveSource {
52044
52256
  result = result.map(result, tr.changes);
52045
52257
  let from = tr.changes.mapPos(this.from), to2 = tr.changes.mapPos(this.to, 1);
52046
52258
  let pos = cur(tr.state);
52047
- if ((this.explicitPos < 0 ? pos <= from : pos < this.from) || pos > to2 || !result || type & 2 && cur(tr.startState) == this.from)
52259
+ if (pos > to2 || !result || type & 2 && (cur(tr.startState) == this.from || pos < this.limit))
52048
52260
  return new ActiveSource(
52049
52261
  this.source,
52050
52262
  type & 4 ? 1 : 0
52051
52263
  /* State.Inactive */
52052
52264
  );
52053
- let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos);
52265
+ let limit = tr.changes.mapPos(this.limit);
52054
52266
  if (checkValid(result.validFor, tr.state, from, to2))
52055
- return new ActiveResult(this.source, explicitPos, result, from, to2);
52056
- if (result.update && (result = result.update(result, from, to2, new CompletionContext(tr.state, pos, explicitPos >= 0))))
52057
- return new ActiveResult(this.source, explicitPos, result, result.from, (_a2 = result.to) !== null && _a2 !== void 0 ? _a2 : cur(tr.state));
52058
- return new ActiveSource(this.source, 1, explicitPos);
52267
+ return new ActiveResult(this.source, this.explicit, limit, result, from, to2);
52268
+ if (result.update && (result = result.update(result, from, to2, new CompletionContext(tr.state, pos, false))))
52269
+ return new ActiveResult(this.source, this.explicit, limit, result, result.from, (_a2 = result.to) !== null && _a2 !== void 0 ? _a2 : cur(tr.state));
52270
+ return new ActiveSource(this.source, 1, this.explicit);
52059
52271
  }
52060
52272
  map(mapping) {
52061
52273
  if (mapping.empty)
@@ -52067,7 +52279,7 @@ class ActiveResult extends ActiveSource {
52067
52279
  0
52068
52280
  /* State.Inactive */
52069
52281
  );
52070
- return new ActiveResult(this.source, this.explicitPos < 0 ? -1 : mapping.mapPos(this.explicitPos), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
52282
+ return new ActiveResult(this.source, this.explicit, mapping.mapPos(this.limit), this.result, mapping.mapPos(this.from), mapping.mapPos(this.to, 1));
52071
52283
  }
52072
52284
  touches(tr) {
52073
52285
  return tr.changes.touchesRange(this.from, this.to);
@@ -52103,7 +52315,10 @@ function applyCompletion(view, option) {
52103
52315
  if (!(result instanceof ActiveResult))
52104
52316
  return false;
52105
52317
  if (typeof apply == "string")
52106
- view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
52318
+ view.dispatch({
52319
+ ...insertCompletionText(view.state, apply, result.from, result.to),
52320
+ annotations: pickedCompletion.of(option.completion)
52321
+ });
52107
52322
  else
52108
52323
  apply(view, option.completion, result.from, result.to);
52109
52324
  return true;
@@ -52169,7 +52384,7 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52169
52384
  this.pendingStart = false;
52170
52385
  this.composing = 0;
52171
52386
  for (let active of view.state.field(completionState).active)
52172
- if (active.state == 1)
52387
+ if (active.isPending)
52173
52388
  this.startQuery(active);
52174
52389
  }
52175
52390
  update(update) {
@@ -52202,7 +52417,7 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52202
52417
  if (update.transactions.some((tr) => tr.effects.some((e2) => e2.is(startCompletionEffect))))
52203
52418
  this.pendingStart = true;
52204
52419
  let delay = this.pendingStart ? 50 : conf.activateOnTypingDelay;
52205
- this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), delay) : -1;
52420
+ this.debounceUpdate = cState.active.some((a) => a.isPending && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), delay) : -1;
52206
52421
  if (this.composing != 0)
52207
52422
  for (let tr of update.transactions) {
52208
52423
  if (tr.isUserEvent("input.type"))
@@ -52216,13 +52431,15 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52216
52431
  this.pendingStart = false;
52217
52432
  let { state } = this.view, cState = state.field(completionState);
52218
52433
  for (let active of cState.active) {
52219
- if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
52434
+ if (active.isPending && !this.running.some((r) => r.active.source == active.source))
52220
52435
  this.startQuery(active);
52221
52436
  }
52437
+ if (this.running.length && cState.open && cState.open.disabled)
52438
+ this.debounceAccept = setTimeout(() => this.accept(), this.view.state.facet(completionConfig).updateSyncTime);
52222
52439
  }
52223
52440
  startQuery(active) {
52224
52441
  let { state } = this.view, pos = cur(state);
52225
- let context = new CompletionContext(state, pos, active.explicitPos == pos, this.view);
52442
+ let context = new CompletionContext(state, pos, active.explicit, this.view);
52226
52443
  let pending = new RunningQuery(active, context);
52227
52444
  this.running.push(pending);
52228
52445
  Promise.resolve(active.source(context)).then((result) => {
@@ -52249,14 +52466,16 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52249
52466
  clearTimeout(this.debounceAccept);
52250
52467
  this.debounceAccept = -1;
52251
52468
  let updated = [];
52252
- let conf = this.view.state.facet(completionConfig);
52469
+ let conf = this.view.state.facet(completionConfig), cState = this.view.state.field(completionState);
52253
52470
  for (let i = 0; i < this.running.length; i++) {
52254
52471
  let query = this.running[i];
52255
52472
  if (query.done === void 0)
52256
52473
  continue;
52257
52474
  this.running.splice(i--, 1);
52258
52475
  if (query.done) {
52259
- let active = new ActiveResult(query.active.source, query.active.explicitPos, query.done, query.done.from, (_a2 = query.done.to) !== null && _a2 !== void 0 ? _a2 : cur(query.updates.length ? query.updates[0].startState : this.view.state));
52476
+ let pos = cur(query.updates.length ? query.updates[0].startState : this.view.state);
52477
+ let limit = Math.min(pos, query.done.from + (query.active.explicit ? 0 : 1));
52478
+ let active = new ActiveResult(query.active.source, query.active.explicit, limit, query.done, query.done.from, (_a2 = query.done.to) !== null && _a2 !== void 0 ? _a2 : pos);
52260
52479
  for (let tr of query.updates)
52261
52480
  active = active.update(tr, conf);
52262
52481
  if (active.hasResult()) {
@@ -52264,8 +52483,8 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52264
52483
  continue;
52265
52484
  }
52266
52485
  }
52267
- let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
52268
- if (current && current.state == 1) {
52486
+ let current = cState.active.find((a) => a.source == query.active.source);
52487
+ if (current && current.isPending) {
52269
52488
  if (query.done == null) {
52270
52489
  let active = new ActiveSource(
52271
52490
  query.active.source,
@@ -52274,14 +52493,14 @@ const completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
52274
52493
  );
52275
52494
  for (let tr of query.updates)
52276
52495
  active = active.update(tr, conf);
52277
- if (active.state != 1)
52496
+ if (!active.isPending)
52278
52497
  updated.push(active);
52279
52498
  } else {
52280
52499
  this.startQuery(current);
52281
52500
  }
52282
52501
  }
52283
52502
  }
52284
- if (updated.length)
52503
+ if (updated.length || cState.open && cState.open.disabled)
52285
52504
  this.view.dispatch({ effects: setActiveEffect.of(updated) });
52286
52505
  }
52287
52506
  }, {
@@ -52477,7 +52696,7 @@ const bracketState = /* @__PURE__ */ StateField.define({
52477
52696
  function closeBrackets() {
52478
52697
  return [inputHandler, bracketState];
52479
52698
  }
52480
- const definedClosing = "()[]{}<>";
52699
+ const definedClosing = "()[]{}<>«»»«[]{}";
52481
52700
  function closing(ch) {
52482
52701
  for (let i = 0; i < definedClosing.length; i += 2)
52483
52702
  if (definedClosing.charCodeAt(i) == ch)
@@ -52685,6 +52904,7 @@ function autocompletion(config2 = {}) {
52685
52904
  const completionKeymap = [
52686
52905
  { key: "Ctrl-Space", run: startCompletion },
52687
52906
  { mac: "Alt-`", run: startCompletion },
52907
+ { mac: "Alt-i", run: startCompletion },
52688
52908
  { key: "Escape", run: closeCompletion },
52689
52909
  { key: "ArrowDown", run: /* @__PURE__ */ moveCompletionSelection(true) },
52690
52910
  { key: "ArrowUp", run: /* @__PURE__ */ moveCompletionSelection(false) },