@vuu-ui/vuu-codemirror 0.8.7-debug → 0.8.8-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -3746,12 +3746,14 @@ function windowRect(win) {
3746
3746
  }
3747
3747
  function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {
3748
3748
  let doc2 = dom.ownerDocument, win = doc2.defaultView || window;
3749
- for (let cur2 = dom; cur2; ) {
3749
+ for (let cur2 = dom, stop = false; cur2 && !stop; ) {
3750
3750
  if (cur2.nodeType == 1) {
3751
3751
  let bounding, top2 = cur2 == doc2.body;
3752
3752
  if (top2) {
3753
3753
  bounding = windowRect(win);
3754
3754
  } else {
3755
+ if (/^(fixed|sticky)$/.test(getComputedStyle(cur2).position))
3756
+ stop = true;
3755
3757
  if (cur2.scrollHeight <= cur2.clientHeight && cur2.scrollWidth <= cur2.clientWidth) {
3756
3758
  cur2 = cur2.assignedSlot || cur2.parentNode;
3757
3759
  continue;
@@ -3972,7 +3974,7 @@ var ContentView = class {
3972
3974
  constructor() {
3973
3975
  this.parent = null;
3974
3976
  this.dom = null;
3975
- this.dirty = 2;
3977
+ this.flags = 2;
3976
3978
  }
3977
3979
  get overrideDOMText() {
3978
3980
  return null;
@@ -3996,18 +3998,18 @@ var ContentView = class {
3996
3998
  return this.posBefore(view) + view.length;
3997
3999
  }
3998
4000
  sync(view, track) {
3999
- if (this.dirty & 2) {
4001
+ if (this.flags & 2) {
4000
4002
  let parent = this.dom;
4001
4003
  let prev = null, next;
4002
4004
  for (let child of this.children) {
4003
- if (child.dirty) {
4004
- if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild) && next != view.docView.compositionNode) {
4005
+ if (child.flags & 7) {
4006
+ if (!child.dom && (next = prev ? prev.nextSibling : parent.firstChild)) {
4005
4007
  let contentView = ContentView.get(next);
4006
4008
  if (!contentView || !contentView.parent && contentView.canReuseDOM(child))
4007
4009
  child.reuseDOM(next);
4008
4010
  }
4009
4011
  child.sync(view, track);
4010
- child.dirty = 0;
4012
+ child.flags &= ~7;
4011
4013
  }
4012
4014
  next = prev ? prev.nextSibling : parent.firstChild;
4013
4015
  if (track && !track.written && track.node == parent && next != child.dom)
@@ -4025,11 +4027,11 @@ var ContentView = class {
4025
4027
  track.written = true;
4026
4028
  while (next)
4027
4029
  next = rm$1(next);
4028
- } else if (this.dirty & 1) {
4030
+ } else if (this.flags & 1) {
4029
4031
  for (let child of this.children)
4030
- if (child.dirty) {
4032
+ if (child.flags & 7) {
4031
4033
  child.sync(view, track);
4032
- child.dirty = 0;
4034
+ child.flags &= ~7;
4033
4035
  }
4034
4036
  }
4035
4037
  }
@@ -4097,23 +4099,23 @@ var ContentView = class {
4097
4099
  };
4098
4100
  }
4099
4101
  markDirty(andParent = false) {
4100
- this.dirty |= 2;
4102
+ this.flags |= 2;
4101
4103
  this.markParentsDirty(andParent);
4102
4104
  }
4103
4105
  markParentsDirty(childList) {
4104
4106
  for (let parent = this.parent; parent; parent = parent.parent) {
4105
4107
  if (childList)
4106
- parent.dirty |= 2;
4107
- if (parent.dirty & 1)
4108
+ parent.flags |= 2;
4109
+ if (parent.flags & 1)
4108
4110
  return;
4109
- parent.dirty |= 1;
4111
+ parent.flags |= 1;
4110
4112
  childList = false;
4111
4113
  }
4112
4114
  }
4113
4115
  setParent(parent) {
4114
4116
  if (this.parent != parent) {
4115
4117
  this.parent = parent;
4116
- if (this.dirty)
4118
+ if (this.flags & 7)
4117
4119
  this.markParentsDirty(true);
4118
4120
  }
4119
4121
  }
@@ -4177,7 +4179,7 @@ var ContentView = class {
4177
4179
  return false;
4178
4180
  }
4179
4181
  canReuseDOM(other) {
4180
- return other.constructor == this.constructor;
4182
+ return other.constructor == this.constructor && !((this.flags | other.flags) & 8);
4181
4183
  }
4182
4184
  // When this is a zero-length view with a side, this should return a
4183
4185
  // number <= 0 to indicate it is before its position, or a
@@ -4281,6 +4283,107 @@ function mergeChildrenInto(parent, from, to, insert2, openStart, openEnd) {
4281
4283
  parent.length += dLen;
4282
4284
  replaceRange(parent, fromI, fromOff, toI, toOff, insert2, 0, openStart, openEnd);
4283
4285
  }
4286
+ var LineBreakPlaceholder = "\uFFFF";
4287
+ var DOMReader = class {
4288
+ constructor(points, state) {
4289
+ this.points = points;
4290
+ this.text = "";
4291
+ this.lineSeparator = state.facet(EditorState.lineSeparator);
4292
+ }
4293
+ append(text) {
4294
+ this.text += text;
4295
+ }
4296
+ lineBreak() {
4297
+ this.text += LineBreakPlaceholder;
4298
+ }
4299
+ readRange(start, end) {
4300
+ if (!start)
4301
+ return this;
4302
+ let parent = start.parentNode;
4303
+ for (let cur2 = start; ; ) {
4304
+ this.findPointBefore(parent, cur2);
4305
+ let oldLen = this.text.length;
4306
+ this.readNode(cur2);
4307
+ let next = cur2.nextSibling;
4308
+ if (next == end)
4309
+ break;
4310
+ let view = ContentView.get(cur2), nextView = ContentView.get(next);
4311
+ if (view && nextView ? view.breakAfter : (view ? view.breakAfter : isBlockElement(cur2)) || isBlockElement(next) && (cur2.nodeName != "BR" || cur2.cmIgnore) && this.text.length > oldLen)
4312
+ this.lineBreak();
4313
+ cur2 = next;
4314
+ }
4315
+ this.findPointBefore(parent, end);
4316
+ return this;
4317
+ }
4318
+ readTextNode(node) {
4319
+ let text = node.nodeValue;
4320
+ for (let point of this.points)
4321
+ if (point.node == node)
4322
+ point.pos = this.text.length + Math.min(point.offset, text.length);
4323
+ for (let off = 0, re = this.lineSeparator ? null : /\r\n?|\n/g; ; ) {
4324
+ let nextBreak = -1, breakSize = 1, m;
4325
+ if (this.lineSeparator) {
4326
+ nextBreak = text.indexOf(this.lineSeparator, off);
4327
+ breakSize = this.lineSeparator.length;
4328
+ } else if (m = re.exec(text)) {
4329
+ nextBreak = m.index;
4330
+ breakSize = m[0].length;
4331
+ }
4332
+ this.append(text.slice(off, nextBreak < 0 ? text.length : nextBreak));
4333
+ if (nextBreak < 0)
4334
+ break;
4335
+ this.lineBreak();
4336
+ if (breakSize > 1) {
4337
+ for (let point of this.points)
4338
+ if (point.node == node && point.pos > this.text.length)
4339
+ point.pos -= breakSize - 1;
4340
+ }
4341
+ off = nextBreak + breakSize;
4342
+ }
4343
+ }
4344
+ readNode(node) {
4345
+ if (node.cmIgnore)
4346
+ return;
4347
+ let view = ContentView.get(node);
4348
+ let fromView = view && view.overrideDOMText;
4349
+ if (fromView != null) {
4350
+ this.findPointInside(node, fromView.length);
4351
+ for (let i = fromView.iter(); !i.next().done; ) {
4352
+ if (i.lineBreak)
4353
+ this.lineBreak();
4354
+ else
4355
+ this.append(i.value);
4356
+ }
4357
+ } else if (node.nodeType == 3) {
4358
+ this.readTextNode(node);
4359
+ } else if (node.nodeName == "BR") {
4360
+ if (node.nextSibling)
4361
+ this.lineBreak();
4362
+ } else if (node.nodeType == 1) {
4363
+ this.readRange(node.firstChild, null);
4364
+ }
4365
+ }
4366
+ findPointBefore(node, next) {
4367
+ for (let point of this.points)
4368
+ if (point.node == node && node.childNodes[point.offset] == next)
4369
+ point.pos = this.text.length;
4370
+ }
4371
+ findPointInside(node, maxLen) {
4372
+ for (let point of this.points)
4373
+ if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
4374
+ point.pos = this.text.length + Math.min(maxLen, point.offset);
4375
+ }
4376
+ };
4377
+ function isBlockElement(node) {
4378
+ return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName);
4379
+ }
4380
+ var DOMPoint = class {
4381
+ constructor(node, offset) {
4382
+ this.node = node;
4383
+ this.offset = offset;
4384
+ this.pos = -1;
4385
+ }
4386
+ };
4284
4387
  var nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };
4285
4388
  var doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };
4286
4389
  var ie_edge = /* @__PURE__ */ /Edge\/(\d+)/.exec(nav.userAgent);
@@ -4335,7 +4438,7 @@ var TextView = class extends ContentView {
4335
4438
  this.createDOM(dom);
4336
4439
  }
4337
4440
  merge(from, to, source) {
4338
- if (source && (!(source instanceof TextView) || this.length - (to - from) + source.length > MaxJoinLen))
4441
+ if (this.flags & 8 || source && (!(source instanceof TextView) || this.length - (to - from) + source.length > MaxJoinLen || source.flags & 8))
4339
4442
  return false;
4340
4443
  this.text = this.text.slice(0, from) + (source ? source.text : "") + this.text.slice(to);
4341
4444
  this.markDirty();
@@ -4345,6 +4448,7 @@ var TextView = class extends ContentView {
4345
4448
  let result = new TextView(this.text.slice(from));
4346
4449
  this.text = this.text.slice(0, from);
4347
4450
  this.markDirty();
4451
+ result.flags |= this.flags & 8;
4348
4452
  return result;
4349
4453
  }
4350
4454
  localPosFromDOM(node, offset) {
@@ -4378,16 +4482,19 @@ var MarkView = class extends ContentView {
4378
4482
  dom.setAttribute(name, this.mark.attrs[name]);
4379
4483
  return dom;
4380
4484
  }
4485
+ canReuseDOM(other) {
4486
+ return super.canReuseDOM(other) && !((this.flags | other.flags) & 8);
4487
+ }
4381
4488
  reuseDOM(node) {
4382
4489
  if (node.nodeName == this.mark.tagName.toUpperCase()) {
4383
4490
  this.setDOM(node);
4384
- this.dirty |= 4 | 2;
4491
+ this.flags |= 4 | 2;
4385
4492
  }
4386
4493
  }
4387
4494
  sync(view, track) {
4388
4495
  if (!this.dom)
4389
4496
  this.setDOM(this.setAttrs(document.createElement(this.mark.tagName)));
4390
- else if (this.dirty & 4)
4497
+ else if (this.flags & 4)
4391
4498
  this.setAttrs(this.dom);
4392
4499
  super.sync(view, track);
4393
4500
  }
@@ -4462,7 +4569,7 @@ var WidgetView = class extends ContentView {
4462
4569
  this.prevWidget = null;
4463
4570
  }
4464
4571
  static create(widget, length2, side) {
4465
- return new (widget.customView || WidgetView)(widget, length2, side);
4572
+ return new WidgetView(widget, length2, side);
4466
4573
  }
4467
4574
  split(from) {
4468
4575
  let result = WidgetView.create(this.widget, this.length - from, this.side);
@@ -4550,127 +4657,6 @@ var WidgetView = class extends ContentView {
4550
4657
  this.widget.destroy(this.dom);
4551
4658
  }
4552
4659
  };
4553
- var CompositionView = class extends WidgetView {
4554
- domAtPos(pos) {
4555
- let { topView, text } = this.widget;
4556
- if (!topView)
4557
- return new DOMPos(text, Math.min(pos, text.nodeValue.length));
4558
- return scanCompositionTree(pos, 0, topView, text, this.length - topView.length, (v, p) => v.domAtPos(p), (text2, p) => new DOMPos(text2, Math.min(p, text2.nodeValue.length)));
4559
- }
4560
- sync() {
4561
- this.setDOM(this.widget.toDOM());
4562
- }
4563
- localPosFromDOM(node, offset) {
4564
- let { topView, text } = this.widget;
4565
- if (!topView)
4566
- return Math.min(offset, this.length);
4567
- return posFromDOMInCompositionTree(node, offset, topView, text, this.length - topView.length);
4568
- }
4569
- ignoreMutation() {
4570
- return false;
4571
- }
4572
- get overrideDOMText() {
4573
- return null;
4574
- }
4575
- coordsAt(pos, side) {
4576
- let { topView, text } = this.widget;
4577
- if (!topView)
4578
- return textCoords(text, pos, side);
4579
- return scanCompositionTree(pos, side, topView, text, this.length - topView.length, (v, pos2, side2) => v.coordsAt(pos2, side2), (text2, pos2, side2) => textCoords(text2, pos2, side2));
4580
- }
4581
- destroy() {
4582
- var _a2;
4583
- super.destroy();
4584
- (_a2 = this.widget.topView) === null || _a2 === void 0 ? void 0 : _a2.destroy();
4585
- }
4586
- get isEditable() {
4587
- return true;
4588
- }
4589
- canReuseDOM() {
4590
- return true;
4591
- }
4592
- };
4593
- function scanCompositionTree(pos, side, view, text, dLen, enterView, fromText) {
4594
- if (view instanceof MarkView) {
4595
- for (let child = view.dom.firstChild; child; child = child.nextSibling) {
4596
- let desc = ContentView.get(child);
4597
- if (!desc) {
4598
- let inner = scanCompositionNode(pos, side, child, fromText);
4599
- if (typeof inner != "number")
4600
- return inner;
4601
- pos = inner;
4602
- } else {
4603
- let hasComp = contains(child, text);
4604
- let len = desc.length + (hasComp ? dLen : 0);
4605
- if (pos < len || pos == len && desc.getSide() <= 0)
4606
- return hasComp ? scanCompositionTree(pos, side, desc, text, dLen, enterView, fromText) : enterView(desc, pos, side);
4607
- pos -= len;
4608
- }
4609
- }
4610
- return enterView(view, view.length, -1);
4611
- } else if (view.dom == text) {
4612
- return fromText(text, pos, side);
4613
- } else {
4614
- return enterView(view, pos, side);
4615
- }
4616
- }
4617
- function scanCompositionNode(pos, side, node, fromText) {
4618
- if (node.nodeType == 3) {
4619
- let len = node.nodeValue.length;
4620
- if (pos <= len)
4621
- return fromText(node, pos, side);
4622
- pos -= len;
4623
- } else if (node.nodeType == 1 && node.contentEditable != "false") {
4624
- for (let child = node.firstChild; child; child = child.nextSibling) {
4625
- let inner = scanCompositionNode(pos, side, child, fromText);
4626
- if (typeof inner != "number")
4627
- return inner;
4628
- pos = inner;
4629
- }
4630
- }
4631
- return pos;
4632
- }
4633
- function posFromDOMInCompositionTree(node, offset, view, text, dLen) {
4634
- if (view instanceof MarkView) {
4635
- let pos = 0;
4636
- for (let child = view.dom.firstChild; child; child = child.nextSibling) {
4637
- let childView = ContentView.get(child);
4638
- if (childView) {
4639
- let hasComp = contains(child, text);
4640
- if (contains(child, node))
4641
- return pos + (hasComp ? posFromDOMInCompositionTree(node, offset, childView, text, dLen) : childView.localPosFromDOM(node, offset));
4642
- pos += childView.length + (hasComp ? dLen : 0);
4643
- } else {
4644
- let inner = posFromDOMInOpaqueNode(node, offset, child);
4645
- if (inner.result != null)
4646
- return pos + inner.result;
4647
- pos += inner.size;
4648
- }
4649
- }
4650
- } else if (view.dom == text) {
4651
- return Math.min(offset, text.nodeValue.length);
4652
- }
4653
- return view.localPosFromDOM(node, offset);
4654
- }
4655
- function posFromDOMInOpaqueNode(node, offset, target) {
4656
- if (target.nodeType == 3) {
4657
- return node == target ? { result: offset } : { size: target.nodeValue.length };
4658
- } else if (target.nodeType == 1 && target.contentEditable != "false") {
4659
- let pos = 0;
4660
- for (let child = target.firstChild, i = 0; ; child = child.nextSibling, i++) {
4661
- if (node == target && i == offset)
4662
- return { result: pos };
4663
- if (!child)
4664
- return { size: pos };
4665
- let inner = posFromDOMInOpaqueNode(node, offset, child);
4666
- if (inner.result != null)
4667
- return { result: offset + inner.result };
4668
- pos += inner.size;
4669
- }
4670
- } else {
4671
- return target.contains(node) ? { result: 0 } : { size: 0 };
4672
- }
4673
- }
4674
4660
  var WidgetBufferView = class extends ContentView {
4675
4661
  constructor(side) {
4676
4662
  super();
@@ -4796,16 +4782,19 @@ function combineAttrs(source, target) {
4796
4782
  }
4797
4783
  return target;
4798
4784
  }
4799
- function attrsEq(a, b) {
4785
+ var noAttrs = /* @__PURE__ */ Object.create(null);
4786
+ function attrsEq(a, b, ignore) {
4800
4787
  if (a == b)
4801
4788
  return true;
4802
- if (!a || !b)
4803
- return false;
4789
+ if (!a)
4790
+ a = noAttrs;
4791
+ if (!b)
4792
+ b = noAttrs;
4804
4793
  let keysA = Object.keys(a), keysB = Object.keys(b);
4805
- if (keysA.length != keysB.length)
4794
+ if (keysA.length - (ignore && keysA.indexOf(ignore) > -1 ? 1 : 0) != keysB.length - (ignore && keysB.indexOf(ignore) > -1 ? 1 : 0))
4806
4795
  return false;
4807
4796
  for (let key of keysA) {
4808
- if (keysB.indexOf(key) == -1 || a[key] !== b[key])
4797
+ if (key != ignore && (keysB.indexOf(key) == -1 || a[key] !== b[key]))
4809
4798
  return false;
4810
4799
  }
4811
4800
  return true;
@@ -4824,6 +4813,14 @@ function updateAttrs(dom, prev, attrs) {
4824
4813
  }
4825
4814
  return !!changed;
4826
4815
  }
4816
+ function getAttrs(dom) {
4817
+ let attrs = /* @__PURE__ */ Object.create(null);
4818
+ for (let i = 0; i < dom.attributes.length; i++) {
4819
+ let attr = dom.attributes[i];
4820
+ attrs[attr.name] = attr.value;
4821
+ }
4822
+ return attrs;
4823
+ }
4827
4824
  var WidgetType = class {
4828
4825
  /**
4829
4826
  Compare this instance to another instance of the same type.
@@ -4892,12 +4889,6 @@ var WidgetType = class {
4892
4889
  /**
4893
4890
  @internal
4894
4891
  */
4895
- get customView() {
4896
- return null;
4897
- }
4898
- /**
4899
- @internal
4900
- */
4901
4892
  get isHidden() {
4902
4893
  return false;
4903
4894
  }
@@ -4998,7 +4989,8 @@ var MarkDecoration = class extends Decoration {
4998
4989
  this.attrs = spec.attributes || null;
4999
4990
  }
5000
4991
  eq(other) {
5001
- return this == other || other instanceof MarkDecoration && this.tagName == other.tagName && this.class == other.class && attrsEq(this.attrs, other.attrs);
4992
+ var _a2, _b;
4993
+ return this == other || other instanceof MarkDecoration && this.tagName == other.tagName && (this.class || ((_a2 = this.attrs) === null || _a2 === void 0 ? void 0 : _a2.class)) == (other.class || ((_b = other.attrs) === null || _b === void 0 ? void 0 : _b.class)) && attrsEq(this.attrs, other.attrs, "class");
5002
4994
  }
5003
4995
  range(from, to = from) {
5004
4996
  if (from >= to)
@@ -5143,7 +5135,7 @@ var LineView = class extends ContentView {
5143
5135
  reuseDOM(node) {
5144
5136
  if (node.nodeName == "DIV") {
5145
5137
  this.setDOM(node);
5146
- this.dirty |= 4 | 2;
5138
+ this.flags |= 4 | 2;
5147
5139
  }
5148
5140
  }
5149
5141
  sync(view, track) {
@@ -5152,7 +5144,7 @@ var LineView = class extends ContentView {
5152
5144
  this.setDOM(document.createElement("div"));
5153
5145
  this.dom.className = "cm-line";
5154
5146
  this.prevAttrs = this.attrs ? null : void 0;
5155
- } else if (this.dirty & 4) {
5147
+ } else if (this.flags & 4) {
5156
5148
  clearAttributes(this.dom);
5157
5149
  this.dom.className = "cm-line";
5158
5150
  this.prevAttrs = this.attrs ? null : void 0;
@@ -5196,8 +5188,8 @@ var LineView = class extends ContentView {
5196
5188
  if (!this.children.length && rect && this.parent) {
5197
5189
  let { heightOracle } = this.parent.view.viewState, height = rect.bottom - rect.top;
5198
5190
  if (Math.abs(height - heightOracle.lineHeight) < 2 && heightOracle.textHeight < height) {
5199
- let dist = (height - heightOracle.textHeight) / 2;
5200
- return { top: rect.top + dist, bottom: rect.bottom - dist, left: rect.left, right: rect.left };
5191
+ let dist2 = (height - heightOracle.textHeight) / 2;
5192
+ return { top: rect.top + dist2, bottom: rect.bottom - dist2, left: rect.left, right: rect.left };
5201
5193
  }
5202
5194
  }
5203
5195
  return rect;
@@ -5959,115 +5951,14 @@ function moveVisually(line, order, dir, start, forward) {
5959
5951
  return EditorSelection.cursor(nextSpan.side(!forward, dir) + line.from, forward ? 1 : -1, nextSpan.level);
5960
5952
  return EditorSelection.cursor(nextIndex + line.from, forward ? -1 : 1, span.level);
5961
5953
  }
5962
- var LineBreakPlaceholder = "\uFFFF";
5963
- var DOMReader = class {
5964
- constructor(points, state) {
5965
- this.points = points;
5966
- this.text = "";
5967
- this.lineSeparator = state.facet(EditorState.lineSeparator);
5968
- }
5969
- append(text) {
5970
- this.text += text;
5971
- }
5972
- lineBreak() {
5973
- this.text += LineBreakPlaceholder;
5974
- }
5975
- readRange(start, end) {
5976
- if (!start)
5977
- return this;
5978
- let parent = start.parentNode;
5979
- for (let cur2 = start; ; ) {
5980
- this.findPointBefore(parent, cur2);
5981
- let oldLen = this.text.length;
5982
- this.readNode(cur2);
5983
- let next = cur2.nextSibling;
5984
- if (next == end)
5985
- break;
5986
- let view = ContentView.get(cur2), nextView = ContentView.get(next);
5987
- if (view && nextView ? view.breakAfter : (view ? view.breakAfter : isBlockElement(cur2)) || isBlockElement(next) && (cur2.nodeName != "BR" || cur2.cmIgnore) && this.text.length > oldLen)
5988
- this.lineBreak();
5989
- cur2 = next;
5990
- }
5991
- this.findPointBefore(parent, end);
5992
- return this;
5993
- }
5994
- readTextNode(node) {
5995
- let text = node.nodeValue;
5996
- for (let point of this.points)
5997
- if (point.node == node)
5998
- point.pos = this.text.length + Math.min(point.offset, text.length);
5999
- for (let off = 0, re = this.lineSeparator ? null : /\r\n?|\n/g; ; ) {
6000
- let nextBreak = -1, breakSize = 1, m;
6001
- if (this.lineSeparator) {
6002
- nextBreak = text.indexOf(this.lineSeparator, off);
6003
- breakSize = this.lineSeparator.length;
6004
- } else if (m = re.exec(text)) {
6005
- nextBreak = m.index;
6006
- breakSize = m[0].length;
6007
- }
6008
- this.append(text.slice(off, nextBreak < 0 ? text.length : nextBreak));
6009
- if (nextBreak < 0)
6010
- break;
6011
- this.lineBreak();
6012
- if (breakSize > 1) {
6013
- for (let point of this.points)
6014
- if (point.node == node && point.pos > this.text.length)
6015
- point.pos -= breakSize - 1;
6016
- }
6017
- off = nextBreak + breakSize;
6018
- }
6019
- }
6020
- readNode(node) {
6021
- if (node.cmIgnore)
6022
- return;
6023
- let view = ContentView.get(node);
6024
- let fromView = view && view.overrideDOMText;
6025
- if (fromView != null) {
6026
- this.findPointInside(node, fromView.length);
6027
- for (let i = fromView.iter(); !i.next().done; ) {
6028
- if (i.lineBreak)
6029
- this.lineBreak();
6030
- else
6031
- this.append(i.value);
6032
- }
6033
- } else if (node.nodeType == 3) {
6034
- this.readTextNode(node);
6035
- } else if (node.nodeName == "BR") {
6036
- if (node.nextSibling)
6037
- this.lineBreak();
6038
- } else if (node.nodeType == 1) {
6039
- this.readRange(node.firstChild, null);
6040
- }
6041
- }
6042
- findPointBefore(node, next) {
6043
- for (let point of this.points)
6044
- if (point.node == node && node.childNodes[point.offset] == next)
6045
- point.pos = this.text.length;
6046
- }
6047
- findPointInside(node, maxLen) {
6048
- for (let point of this.points)
6049
- if (node.nodeType == 3 ? point.node == node : node.contains(point.node))
6050
- point.pos = this.text.length + Math.min(maxLen, point.offset);
6051
- }
6052
- };
6053
- function isBlockElement(node) {
6054
- return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName);
6055
- }
6056
- var DOMPoint = class {
6057
- constructor(node, offset) {
6058
- this.node = node;
6059
- this.offset = offset;
6060
- this.pos = -1;
6061
- }
6062
- };
6063
5954
  var DocView = class extends ContentView {
6064
5955
  constructor(view) {
6065
5956
  super();
6066
5957
  this.view = view;
6067
- this.compositionDeco = Decoration.none;
6068
- this.compositionNode = null;
6069
5958
  this.decorations = [];
6070
5959
  this.dynamicDecorationMap = [];
5960
+ this.hasComposition = null;
5961
+ this.markedForComposition = /* @__PURE__ */ new Set();
6071
5962
  this.minWidth = 0;
6072
5963
  this.minWidthFrom = 0;
6073
5964
  this.minWidthTo = 0;
@@ -6079,7 +5970,7 @@ var DocView = class extends ContentView {
6079
5970
  this.children = [new LineView()];
6080
5971
  this.children[0].setParent(this);
6081
5972
  this.updateDeco();
6082
- this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0);
5973
+ this.updateInner([new ChangedRange(0, 0, 0, view.state.doc.length)], 0, null);
6083
5974
  }
6084
5975
  get length() {
6085
5976
  return this.view.state.doc.length;
@@ -6095,16 +5986,22 @@ var DocView = class extends ContentView {
6095
5986
  this.minWidthTo = update.changes.mapPos(this.minWidthTo, 1);
6096
5987
  }
6097
5988
  }
6098
- ({ deco: this.compositionDeco, node: this.compositionNode } = this.view.inputState.composing < 0 ? noComp : computeCompositionDeco(this.view, update.changes));
6099
- if ((browser.ie || browser.chrome) && !this.compositionDeco.size && update && update.state.doc.lines != update.startState.doc.lines)
5989
+ let composition = this.view.inputState.composing < 0 ? null : findCompositionRange(this.view, update.changes);
5990
+ if (this.hasComposition) {
5991
+ this.markedForComposition.clear();
5992
+ let { from, to } = this.hasComposition;
5993
+ changedRanges = new ChangedRange(from, to, update.changes.mapPos(from, -1), update.changes.mapPos(to, 1)).addToSet(changedRanges.slice());
5994
+ }
5995
+ this.hasComposition = composition ? { from: composition.range.fromB, to: composition.range.toB } : null;
5996
+ if ((browser.ie || browser.chrome) && !composition && update && update.state.doc.lines != update.startState.doc.lines)
6100
5997
  this.forceSelection = true;
6101
5998
  let prevDeco = this.decorations, deco = this.updateDeco();
6102
5999
  let decoDiff = findChangedDeco(prevDeco, deco, update.changes);
6103
6000
  changedRanges = ChangedRange.extendWithRanges(changedRanges, decoDiff);
6104
- if (this.dirty == 0 && changedRanges.length == 0) {
6001
+ if (!(this.flags & 7) && changedRanges.length == 0) {
6105
6002
  return false;
6106
6003
  } else {
6107
- this.updateInner(changedRanges, update.startState.doc.length);
6004
+ this.updateInner(changedRanges, update.startState.doc.length, composition);
6108
6005
  if (update.transactions.length)
6109
6006
  this.lastUpdate = Date.now();
6110
6007
  return true;
@@ -6112,20 +6009,24 @@ var DocView = class extends ContentView {
6112
6009
  }
6113
6010
  // Used by update and the constructor do perform the actual DOM
6114
6011
  // update
6115
- updateInner(changes, oldLength) {
6012
+ updateInner(changes, oldLength, composition) {
6116
6013
  this.view.viewState.mustMeasureContent = true;
6117
- this.updateChildren(changes, oldLength);
6014
+ this.updateChildren(changes, oldLength, composition);
6118
6015
  let { observer } = this.view;
6119
6016
  observer.ignore(() => {
6120
6017
  this.dom.style.height = this.view.viewState.contentHeight + "px";
6121
6018
  this.dom.style.flexBasis = this.minWidth ? this.minWidth + "px" : "";
6122
6019
  let track = browser.chrome || browser.ios ? { node: observer.selectionRange.focusNode, written: false } : void 0;
6123
6020
  this.sync(this.view, track);
6124
- this.dirty = 0;
6021
+ this.flags &= ~7;
6125
6022
  if (track && (track.written || observer.selectionRange.focusNode != track.node))
6126
6023
  this.forceSelection = true;
6127
6024
  this.dom.style.height = "";
6128
6025
  });
6026
+ this.markedForComposition.forEach(
6027
+ (cView) => cView.flags &= ~8
6028
+ /* Composition */
6029
+ );
6129
6030
  let gaps = [];
6130
6031
  if (this.view.viewport.from || this.view.viewport.to < this.view.state.doc.length) {
6131
6032
  for (let child of this.children)
@@ -6134,18 +6035,69 @@ var DocView = class extends ContentView {
6134
6035
  }
6135
6036
  observer.updateGaps(gaps);
6136
6037
  }
6137
- updateChildren(changes, oldLength) {
6038
+ updateChildren(changes, oldLength, composition) {
6039
+ let ranges = composition ? composition.range.addToSet(changes.slice()) : changes;
6138
6040
  let cursor = this.childCursor(oldLength);
6139
- for (let i = changes.length - 1; ; i--) {
6140
- let next = i >= 0 ? changes[i] : null;
6041
+ for (let i = ranges.length - 1; ; i--) {
6042
+ let next = i >= 0 ? ranges[i] : null;
6141
6043
  if (!next)
6142
6044
  break;
6143
- let { fromA, toA, fromB, toB } = next;
6144
- let { content, breakAtStart, openStart, openEnd } = ContentBuilder.build(this.view.state.doc, fromB, toB, this.decorations, this.dynamicDecorationMap);
6045
+ let { fromA, toA, fromB, toB } = next, content, breakAtStart, openStart, openEnd;
6046
+ if (composition && composition.range.fromB < toB && composition.range.toB > fromB) {
6047
+ let before = ContentBuilder.build(this.view.state.doc, fromB, composition.range.fromB, this.decorations, this.dynamicDecorationMap);
6048
+ let after = ContentBuilder.build(this.view.state.doc, composition.range.toB, toB, this.decorations, this.dynamicDecorationMap);
6049
+ breakAtStart = before.breakAtStart;
6050
+ openStart = before.openStart;
6051
+ openEnd = after.openEnd;
6052
+ let compLine = this.compositionView(composition);
6053
+ if (after.breakAtStart) {
6054
+ compLine.breakAfter = 1;
6055
+ } else if (after.content.length && compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0)) {
6056
+ compLine.breakAfter = after.content[0].breakAfter;
6057
+ after.content.shift();
6058
+ }
6059
+ if (before.content.length && compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd)) {
6060
+ before.content.pop();
6061
+ }
6062
+ content = before.content.concat(compLine).concat(after.content);
6063
+ } else {
6064
+ ({ content, breakAtStart, openStart, openEnd } = ContentBuilder.build(this.view.state.doc, fromB, toB, this.decorations, this.dynamicDecorationMap));
6065
+ }
6145
6066
  let { i: toI, off: toOff } = cursor.findPos(toA, 1);
6146
6067
  let { i: fromI, off: fromOff } = cursor.findPos(fromA, -1);
6147
6068
  replaceRange(this, fromI, fromOff, toI, toOff, content, breakAtStart, openStart, openEnd);
6148
6069
  }
6070
+ if (composition)
6071
+ this.fixCompositionDOM(composition);
6072
+ }
6073
+ compositionView(composition) {
6074
+ let cur2 = new TextView(composition.text.nodeValue);
6075
+ cur2.flags |= 8;
6076
+ for (let { deco } of composition.marks)
6077
+ cur2 = new MarkView(deco, [cur2], cur2.length);
6078
+ let line = new LineView();
6079
+ line.append(cur2, 0);
6080
+ return line;
6081
+ }
6082
+ fixCompositionDOM(composition) {
6083
+ let fix = (dom, cView2) => {
6084
+ cView2.flags |= 8;
6085
+ this.markedForComposition.add(cView2);
6086
+ let prev = ContentView.get(dom);
6087
+ if (prev != cView2) {
6088
+ if (prev)
6089
+ prev.dom = null;
6090
+ cView2.setDOM(dom);
6091
+ }
6092
+ };
6093
+ let pos = this.childPos(composition.range.fromB, 1);
6094
+ let cView = this.children[pos.i];
6095
+ fix(composition.line, cView);
6096
+ for (let i = composition.marks.length - 1; i >= -1; i--) {
6097
+ pos = cView.childPos(pos.off, 1);
6098
+ cView = cView.children[pos.i];
6099
+ fix(i >= 0 ? composition.marks[i].node : composition.text, cView);
6100
+ }
6149
6101
  }
6150
6102
  // Sync the DOM selection to this.state.selection
6151
6103
  updateSelection(mustRead = false, fromPointer = false) {
@@ -6160,7 +6112,7 @@ var DocView = class extends ContentView {
6160
6112
  let main = this.view.state.selection.main;
6161
6113
  let anchor = this.domAtPos(main.anchor);
6162
6114
  let head = main.empty ? anchor : this.domAtPos(main.head);
6163
- if (browser.gecko && main.empty && !this.compositionDeco.size && betweenUneditable(anchor)) {
6115
+ if (browser.gecko && main.empty && !this.hasComposition && betweenUneditable(anchor)) {
6164
6116
  let dummy = document.createTextNode("");
6165
6117
  this.view.observer.ignore(() => anchor.node.insertBefore(dummy, anchor.node.childNodes[anchor.offset] || null));
6166
6118
  anchor = head = new DOMPos(dummy, 0);
@@ -6215,7 +6167,7 @@ var DocView = class extends ContentView {
6215
6167
  this.impreciseHead = head.precise ? null : new DOMPos(domSel.focusNode, domSel.focusOffset);
6216
6168
  }
6217
6169
  enforceCursorAssoc() {
6218
- if (this.compositionDeco.size)
6170
+ if (this.hasComposition)
6219
6171
  return;
6220
6172
  let { view } = this, cursor = view.state.selection.main;
6221
6173
  let sel = getSelection(view.root);
@@ -6273,6 +6225,28 @@ var DocView = class extends ContentView {
6273
6225
  off = start;
6274
6226
  }
6275
6227
  }
6228
+ coordsForChar(pos) {
6229
+ let { i, off } = this.childPos(pos, 1), child = this.children[i];
6230
+ if (!(child instanceof LineView))
6231
+ return null;
6232
+ while (child.children.length) {
6233
+ let { i: i2, off: childOff } = child.childPos(off, 1);
6234
+ for (; ; i2++) {
6235
+ if (i2 == child.children.length)
6236
+ return null;
6237
+ if ((child = child.children[i2]).length)
6238
+ break;
6239
+ }
6240
+ off = childOff;
6241
+ }
6242
+ if (!(child instanceof TextView))
6243
+ return null;
6244
+ let end = findClusterBreak(child.text, off);
6245
+ if (end == off)
6246
+ return null;
6247
+ let rects = textRange(child.dom, off, end).getClientRects();
6248
+ return !rects.length || rects[0].top >= rects[0].bottom ? null : rects[0];
6249
+ }
6276
6250
  measureVisibleLineHeights(viewport) {
6277
6251
  let result = [], { from, to } = viewport;
6278
6252
  let contentWidth = this.view.contentDOM.clientWidth;
@@ -6319,6 +6293,7 @@ var DocView = class extends ContentView {
6319
6293
  let dummy = document.createElement("div"), lineHeight, charWidth, textHeight;
6320
6294
  dummy.className = "cm-line";
6321
6295
  dummy.style.width = "99999px";
6296
+ dummy.style.position = "absolute";
6322
6297
  dummy.textContent = "abc def ghi jkl mno pqr stu";
6323
6298
  this.view.observer.ignore(() => {
6324
6299
  this.dom.appendChild(dummy);
@@ -6365,7 +6340,6 @@ var DocView = class extends ContentView {
6365
6340
  this.dynamicDecorationMap[i] = false;
6366
6341
  return this.decorations = [
6367
6342
  ...allDeco,
6368
- this.compositionDeco,
6369
6343
  this.computeBlockGapDeco(),
6370
6344
  this.view.viewState.lineGapDeco
6371
6345
  ];
@@ -6416,89 +6390,83 @@ var BlockGapWidget = class extends WidgetType {
6416
6390
  return this.height;
6417
6391
  }
6418
6392
  };
6419
- function compositionSurroundingNode(view) {
6393
+ function findCompositionNode(view) {
6420
6394
  let sel = view.observer.selectionRange;
6421
6395
  let textNode = sel.focusNode && nearbyTextNode(sel.focusNode, sel.focusOffset, 0);
6422
6396
  if (!textNode)
6423
6397
  return null;
6424
- let cView = view.docView.nearest(textNode);
6425
- if (!cView)
6426
- return null;
6427
- if (cView instanceof LineView) {
6428
- let topNode = textNode;
6429
- while (topNode.parentNode != cView.dom)
6430
- topNode = topNode.parentNode;
6431
- let prev = topNode.previousSibling;
6432
- while (prev && !ContentView.get(prev))
6433
- prev = prev.previousSibling;
6434
- let pos = prev ? ContentView.get(prev).posAtEnd : cView.posAtStart;
6435
- return { from: pos, to: pos, node: topNode, text: textNode };
6398
+ let cView = ContentView.get(textNode);
6399
+ let from, to;
6400
+ if (cView instanceof TextView) {
6401
+ from = cView.posAtStart;
6402
+ to = from + cView.length;
6436
6403
  } else {
6437
- for (; ; ) {
6438
- let { parent } = cView;
6439
- if (!parent)
6440
- return null;
6441
- if (parent instanceof LineView)
6442
- break;
6443
- cView = parent;
6444
- }
6445
- let from = cView.posAtStart;
6446
- return { from, to: from + cView.length, node: cView.dom, text: textNode };
6447
- }
6448
- }
6449
- var noComp = { deco: Decoration.none, node: null };
6450
- function computeCompositionDeco(view, changes) {
6451
- let surrounding = compositionSurroundingNode(view);
6452
- if (!surrounding)
6453
- return noComp;
6454
- let { from, to, node, text: textNode } = surrounding;
6455
- let newFrom = changes.mapPos(from, 1), newTo = Math.max(newFrom, changes.mapPos(to, -1));
6456
- let { state } = view, reader = new DOMReader([], state);
6457
- if (node.nodeType == 3)
6458
- reader.readTextNode(node);
6459
- else
6460
- reader.readRange(node.firstChild, null);
6461
- let { text } = reader;
6462
- if (text.indexOf(LineBreakPlaceholder) > -1)
6463
- return noComp;
6464
- if (newTo - newFrom < text.length) {
6465
- if (state.doc.sliceString(newFrom, Math.min(state.doc.length, newFrom + text.length)) == text)
6466
- newTo = newFrom + text.length;
6467
- else if (state.doc.sliceString(Math.max(0, newTo - text.length), newTo) == text)
6468
- newFrom = newTo - text.length;
6469
- else
6470
- return noComp;
6471
- } else if (state.doc.sliceString(newFrom, newTo) != text) {
6472
- return noComp;
6473
- }
6474
- let topView = ContentView.get(node);
6475
- if (topView instanceof CompositionView)
6476
- topView = topView.widget.topView;
6477
- else if (topView)
6478
- topView.parent = null;
6479
- let deco = Decoration.set(Decoration.replace({ widget: new CompositionWidget(node, textNode, topView), inclusive: true }).range(newFrom, newTo));
6480
- return { deco, node };
6481
- }
6482
- var CompositionWidget = class extends WidgetType {
6483
- constructor(top2, text, topView) {
6484
- super();
6485
- this.top = top2;
6486
- this.text = text;
6487
- this.topView = topView;
6488
- }
6489
- eq(other) {
6490
- return this.top == other.top && this.text == other.text;
6491
- }
6492
- toDOM() {
6493
- return this.top;
6404
+ up:
6405
+ for (let offset = 0, node = textNode; ; ) {
6406
+ for (let sibling = node.previousSibling, cView2; sibling; sibling = sibling.previousSibling) {
6407
+ if (cView2 = ContentView.get(sibling)) {
6408
+ from = to = cView2.posAtEnd + offset;
6409
+ break up;
6410
+ }
6411
+ let reader = new DOMReader([], view.state);
6412
+ reader.readNode(sibling);
6413
+ if (reader.text.indexOf(LineBreakPlaceholder) > -1)
6414
+ return null;
6415
+ offset += reader.text.length;
6416
+ }
6417
+ node = node.parentNode;
6418
+ if (!node)
6419
+ return null;
6420
+ let parentView = ContentView.get(node);
6421
+ if (parentView) {
6422
+ from = to = parentView.posAtStart + offset;
6423
+ break;
6424
+ }
6425
+ }
6494
6426
  }
6495
- ignoreEvent() {
6496
- return false;
6427
+ return { from, to, node: textNode };
6428
+ }
6429
+ function findCompositionRange(view, changes) {
6430
+ let found = findCompositionNode(view);
6431
+ if (!found)
6432
+ return null;
6433
+ let { from: fromA, to: toA, node: textNode } = found;
6434
+ let fromB = changes.mapPos(fromA, -1), toB = changes.mapPos(toA, 1);
6435
+ let text = textNode.nodeValue;
6436
+ if (/[\n\r]/.test(text))
6437
+ return null;
6438
+ if (toB - fromB != text.length) {
6439
+ let fromB2 = changes.mapPos(fromA, 1), toB2 = changes.mapPos(toA, -1);
6440
+ if (toB2 - fromB2 == text.length)
6441
+ fromB = fromB2, toB = toB2;
6442
+ else if (view.state.doc.sliceString(toB - text.length, toB) == text)
6443
+ fromB = toB - text.length;
6444
+ else if (view.state.doc.sliceString(fromB, fromB + text.length) == text)
6445
+ toB = fromB + text.length;
6446
+ else
6447
+ return null;
6497
6448
  }
6498
- get customView() {
6499
- return CompositionView;
6449
+ let { main } = view.state.selection;
6450
+ if (view.state.doc.sliceString(fromB, toB) != text || fromB > main.head || toB < main.head)
6451
+ return null;
6452
+ let marks = [];
6453
+ let range = new ChangedRange(fromA, toA, fromB, toB);
6454
+ for (let parent = textNode.parentNode; ; parent = parent.parentNode) {
6455
+ let parentView = ContentView.get(parent);
6456
+ if (parentView instanceof MarkView)
6457
+ marks.push({ node: parent, deco: parentView.mark });
6458
+ else if (parentView instanceof LineView || parent.nodeName == "DIV" && parent.parentNode == view.contentDOM)
6459
+ return { range, text: textNode, marks, line: parent };
6460
+ else if (parent != view.contentDOM)
6461
+ marks.push({ node: parent, deco: new MarkDecoration({
6462
+ inclusive: true,
6463
+ attributes: getAttrs(parent),
6464
+ tagName: parent.tagName.toLowerCase()
6465
+ }) });
6466
+ else
6467
+ return null;
6500
6468
  }
6501
- };
6469
+ }
6502
6470
  function nearbyTextNode(startNode, startOffset, side) {
6503
6471
  if (side <= 0)
6504
6472
  for (let node = startNode, offset = startOffset; ; ) {
@@ -6856,9 +6824,9 @@ function moveVertically(view, start, forward, distance) {
6856
6824
  startY = (dir < 0 ? line.top : line.bottom) + docTop;
6857
6825
  }
6858
6826
  let resolvedGoal = rect.left + goal;
6859
- let dist = distance !== null && distance !== void 0 ? distance : view.viewState.heightOracle.textHeight >> 1;
6827
+ let dist2 = distance !== null && distance !== void 0 ? distance : view.viewState.heightOracle.textHeight >> 1;
6860
6828
  for (let extra = 0; ; extra += 10) {
6861
- let curY = startY + (dist + extra) * dir;
6829
+ let curY = startY + (dist2 + extra) * dir;
6862
6830
  let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
6863
6831
  if (curY < rect.top || curY > rect.bottom || (dir < 0 ? pos < startPos : pos > startPos))
6864
6832
  return EditorSelection.cursor(pos, start.assoc, void 0, goal);
@@ -7073,12 +7041,16 @@ var PendingKeys = [
7073
7041
  var EmacsyPendingKeys = "dthko";
7074
7042
  var modifierCodes = [16, 17, 18, 20, 91, 92, 224, 225];
7075
7043
  var dragScrollMargin = 6;
7076
- function dragScrollSpeed(dist) {
7077
- return Math.max(0, dist) * 0.7 + 8;
7044
+ function dragScrollSpeed(dist2) {
7045
+ return Math.max(0, dist2) * 0.7 + 8;
7046
+ }
7047
+ function dist(a, b) {
7048
+ return Math.max(Math.abs(a.clientX - b.clientX), Math.abs(a.clientY - b.clientY));
7078
7049
  }
7079
7050
  var MouseSelection = class {
7080
7051
  constructor(view, startEvent, style, mustSelect) {
7081
7052
  this.view = view;
7053
+ this.startEvent = startEvent;
7082
7054
  this.style = style;
7083
7055
  this.mustSelect = mustSelect;
7084
7056
  this.scrollSpeed = { x: 0, y: 0 };
@@ -7103,7 +7075,7 @@ var MouseSelection = class {
7103
7075
  var _a2;
7104
7076
  if (event.buttons == 0)
7105
7077
  return this.destroy();
7106
- if (this.dragging !== false)
7078
+ if (this.dragging || this.dragging == null && dist(this.startEvent, event) < 10)
7107
7079
  return;
7108
7080
  this.select(this.lastEvent = event);
7109
7081
  let sx = 0, sy = 0;
@@ -7177,7 +7149,7 @@ var MouseSelection = class {
7177
7149
  }
7178
7150
  select(event) {
7179
7151
  let { view } = this, selection = this.skipAtoms(this.style.get(event, this.extend, this.multiple));
7180
- if (this.mustSelect || !selection.eq(view.state.selection) || selection.main.assoc != view.state.selection.main.assoc)
7152
+ if (this.mustSelect || !selection.eq(view.state.selection) || selection.main.assoc != view.state.selection.main.assoc && this.dragging === false)
7181
7153
  this.view.dispatch({
7182
7154
  selection,
7183
7155
  userEvent: "select.pointer"
@@ -7567,7 +7539,7 @@ handlers.compositionend = (view) => {
7567
7539
  Promise.resolve().then(() => view.observer.flush());
7568
7540
  } else {
7569
7541
  setTimeout(() => {
7570
- if (view.inputState.composing < 0 && view.docView.compositionDeco.size)
7542
+ if (view.inputState.composing < 0 && view.docView.hasComposition)
7571
7543
  view.update([]);
7572
7544
  }, 50);
7573
7545
  }
@@ -8748,12 +8720,12 @@ function findPosition({ total, ranges }, ratio) {
8748
8720
  return ranges[0].from;
8749
8721
  if (ratio >= 1)
8750
8722
  return ranges[ranges.length - 1].to;
8751
- let dist = Math.floor(total * ratio);
8723
+ let dist2 = Math.floor(total * ratio);
8752
8724
  for (let i = 0; ; i++) {
8753
8725
  let { from, to } = ranges[i], size = to - from;
8754
- if (dist <= size)
8755
- return from + dist;
8756
- dist -= size;
8726
+ if (dist2 <= size)
8727
+ return from + dist2;
8728
+ dist2 -= size;
8757
8729
  }
8758
8730
  }
8759
8731
  function findFraction(structure, pos) {
@@ -8959,7 +8931,7 @@ var baseTheme$1 = /* @__PURE__ */ buildTheme("." + baseThemeID, {
8959
8931
  display: "flex",
8960
8932
  height: "100%",
8961
8933
  boxSizing: "border-box",
8962
- left: 0,
8934
+ insetInlineStart: 0,
8963
8935
  zIndex: 200
8964
8936
  },
8965
8937
  "&light .cm-gutters": {
@@ -9167,7 +9139,7 @@ function applyDOMChange(view, domChange) {
9167
9139
  let mainSel = newSel && newSel.main.to <= changes.newLength ? newSel.main : void 0;
9168
9140
  if (startState.selection.ranges.length > 1 && view.inputState.composing >= 0 && change.to <= sel.to && change.to >= sel.to - 10) {
9169
9141
  let replaced = view.state.sliceDoc(change.from, change.to);
9170
- let compositionRange = compositionSurroundingNode(view) || view.state.doc.lineAt(sel.head);
9142
+ let composition = findCompositionNode(view) || view.state.doc.lineAt(sel.head);
9171
9143
  let offset = sel.to - change.to, size = sel.to - sel.from;
9172
9144
  tr = startState.changeByRange((range) => {
9173
9145
  if (range.from == sel.from && range.to == sel.to)
@@ -9177,7 +9149,7 @@ function applyDOMChange(view, domChange) {
9177
9149
  // changes in the same node work without aborting
9178
9150
  // composition, so cursors in the composition range are
9179
9151
  // ignored.
9180
- compositionRange && range.to >= compositionRange.from && range.from <= compositionRange.to)
9152
+ composition && range.to >= composition.from && range.from <= composition.to)
9181
9153
  return { range };
9182
9154
  let rangeChanges = startState.changes({ from, to, insert: change.insert }), selOff = range.to - sel.to;
9183
9155
  return {
@@ -9590,7 +9562,7 @@ var DOMObserver = class {
9590
9562
  return null;
9591
9563
  cView.markDirty(rec.type == "attributes");
9592
9564
  if (rec.type == "attributes")
9593
- cView.dirty |= 4;
9565
+ cView.flags |= 4;
9594
9566
  if (rec.type == "childList") {
9595
9567
  let childBefore = findChild(cView, rec.previousSibling || rec.target.previousSibling, -1);
9596
9568
  let childAfter = findChild(cView, rec.nextSibling || rec.target.nextSibling, 1);
@@ -10280,6 +10252,17 @@ var EditorView = class {
10280
10252
  return flattenRect(rect, span.dir == Direction.LTR == side > 0);
10281
10253
  }
10282
10254
  /**
10255
+ Return the rectangle around a given character. If `pos` does not
10256
+ point in front of a character that is in the viewport and
10257
+ rendered (i.e. not replaced, not a line break), this will return
10258
+ null. For space characters that are a line wrap point, this will
10259
+ return the position before the line break.
10260
+ */
10261
+ coordsForChar(pos) {
10262
+ this.readMeasured();
10263
+ return this.docView.coordsForChar(pos);
10264
+ }
10265
+ /**
10283
10266
  The default width of a character in the editor. May not
10284
10267
  accurately reflect the width of all characters (given variable
10285
10268
  width fonts or styling of invididual ranges).
@@ -10578,7 +10561,7 @@ function buildKeymap(bindings, platform = currentPlatform) {
10578
10561
  else if (current != is)
10579
10562
  throw new Error("Key binding " + name + " is used both as a regular binding and as a multi-stroke prefix");
10580
10563
  };
10581
- let add = (scope, key, command2, preventDefault) => {
10564
+ let add = (scope, key, command2, preventDefault, stopPropagation) => {
10582
10565
  var _a2, _b;
10583
10566
  let scopeObj = bound[scope] || (bound[scope] = /* @__PURE__ */ Object.create(null));
10584
10567
  let parts = key.split(/ (?!$)/).map((k) => normalizeKeyName(k, platform));
@@ -10588,6 +10571,7 @@ function buildKeymap(bindings, platform = currentPlatform) {
10588
10571
  if (!scopeObj[prefix])
10589
10572
  scopeObj[prefix] = {
10590
10573
  preventDefault: true,
10574
+ stopPropagation: false,
10591
10575
  run: [(view) => {
10592
10576
  let ourObj = storedPrefix = { view, prefix, scope };
10593
10577
  setTimeout(() => {
@@ -10600,11 +10584,17 @@ function buildKeymap(bindings, platform = currentPlatform) {
10600
10584
  }
10601
10585
  let full = parts.join(" ");
10602
10586
  checkPrefix(full, false);
10603
- let binding = scopeObj[full] || (scopeObj[full] = { preventDefault: false, run: ((_b = (_a2 = scopeObj._any) === null || _a2 === void 0 ? void 0 : _a2.run) === null || _b === void 0 ? void 0 : _b.slice()) || [] });
10587
+ let binding = scopeObj[full] || (scopeObj[full] = {
10588
+ preventDefault: false,
10589
+ stopPropagation: false,
10590
+ run: ((_b = (_a2 = scopeObj._any) === null || _a2 === void 0 ? void 0 : _a2.run) === null || _b === void 0 ? void 0 : _b.slice()) || []
10591
+ });
10604
10592
  if (command2)
10605
10593
  binding.run.push(command2);
10606
10594
  if (preventDefault)
10607
10595
  binding.preventDefault = true;
10596
+ if (stopPropagation)
10597
+ binding.stopPropagation = true;
10608
10598
  };
10609
10599
  for (let b of bindings) {
10610
10600
  let scopes = b.scope ? b.scope.split(" ") : ["editor"];
@@ -10612,7 +10602,7 @@ function buildKeymap(bindings, platform = currentPlatform) {
10612
10602
  for (let scope of scopes) {
10613
10603
  let scopeObj = bound[scope] || (bound[scope] = /* @__PURE__ */ Object.create(null));
10614
10604
  if (!scopeObj._any)
10615
- scopeObj._any = { preventDefault: false, run: [] };
10605
+ scopeObj._any = { preventDefault: false, stopPropagation: false, run: [] };
10616
10606
  for (let key in scopeObj)
10617
10607
  scopeObj[key].run.push(b.any);
10618
10608
  }
@@ -10620,9 +10610,9 @@ function buildKeymap(bindings, platform = currentPlatform) {
10620
10610
  if (!name)
10621
10611
  continue;
10622
10612
  for (let scope of scopes) {
10623
- add(scope, name, b.run, b.preventDefault);
10613
+ add(scope, name, b.run, b.preventDefault, b.stopPropagation);
10624
10614
  if (b.shift)
10625
- add(scope, "Shift-" + name, b.shift, b.preventDefault);
10615
+ add(scope, "Shift-" + name, b.shift, b.preventDefault, b.stopPropagation);
10626
10616
  }
10627
10617
  }
10628
10618
  return bound;
@@ -10630,11 +10620,13 @@ function buildKeymap(bindings, platform = currentPlatform) {
10630
10620
  function runHandlers(map, event, view, scope) {
10631
10621
  let name = keyName(event);
10632
10622
  let charCode = codePointAt(name, 0), isChar = codePointSize(charCode) == name.length && name != " ";
10633
- let prefix = "", fallthrough = false;
10623
+ let prefix = "", handled = false, prevented = false, stopPropagation = false;
10634
10624
  if (storedPrefix && storedPrefix.view == view && storedPrefix.scope == scope) {
10635
10625
  prefix = storedPrefix.prefix + " ";
10636
- if (fallthrough = modifierCodes.indexOf(event.keyCode) < 0)
10626
+ if (modifierCodes.indexOf(event.keyCode) < 0) {
10627
+ prevented = true;
10637
10628
  storedPrefix = null;
10629
+ }
10638
10630
  }
10639
10631
  let ran = /* @__PURE__ */ new Set();
10640
10632
  let runFor = (binding) => {
@@ -10642,32 +10634,42 @@ function runHandlers(map, event, view, scope) {
10642
10634
  for (let cmd2 of binding.run)
10643
10635
  if (!ran.has(cmd2)) {
10644
10636
  ran.add(cmd2);
10645
- if (cmd2(view, event))
10637
+ if (cmd2(view, event)) {
10638
+ if (binding.stopPropagation)
10639
+ stopPropagation = true;
10646
10640
  return true;
10641
+ }
10647
10642
  }
10648
- if (binding.preventDefault)
10649
- fallthrough = true;
10643
+ if (binding.preventDefault) {
10644
+ if (binding.stopPropagation)
10645
+ stopPropagation = true;
10646
+ prevented = true;
10647
+ }
10650
10648
  }
10651
10649
  return false;
10652
10650
  };
10653
10651
  let scopeObj = map[scope], baseName, shiftName;
10654
10652
  if (scopeObj) {
10655
- if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
10656
- return true;
10657
- if (isChar && (event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
10653
+ if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)])) {
10654
+ handled = true;
10655
+ } else if (isChar && (event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
10658
10656
  !(browser.windows && event.ctrlKey && event.altKey) && (baseName = base[event.keyCode]) && baseName != name) {
10659
- if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
10660
- return true;
10661
- else if (event.shiftKey && (shiftName = shift[event.keyCode]) != name && shiftName != baseName && runFor(scopeObj[prefix + modifiers(shiftName, event, false)]))
10662
- return true;
10663
- } else if (isChar && event.shiftKey) {
10664
- if (runFor(scopeObj[prefix + modifiers(name, event, true)]))
10665
- return true;
10657
+ if (runFor(scopeObj[prefix + modifiers(baseName, event, true)])) {
10658
+ handled = true;
10659
+ } else if (event.shiftKey && (shiftName = shift[event.keyCode]) != name && shiftName != baseName && runFor(scopeObj[prefix + modifiers(shiftName, event, false)])) {
10660
+ handled = true;
10661
+ }
10662
+ } else if (isChar && event.shiftKey && runFor(scopeObj[prefix + modifiers(name, event, true)])) {
10663
+ handled = true;
10666
10664
  }
10667
- if (runFor(scopeObj._any))
10668
- return true;
10665
+ if (!handled && runFor(scopeObj._any))
10666
+ handled = true;
10669
10667
  }
10670
- return fallthrough;
10668
+ if (prevented)
10669
+ handled = true;
10670
+ if (handled && stopPropagation)
10671
+ event.stopPropagation();
10672
+ return handled;
10671
10673
  }
10672
10674
  var RectangleMarker = class {
10673
10675
  /**
@@ -12791,6 +12793,8 @@ var FuzzyMatcher = class {
12791
12793
  this.any = [];
12792
12794
  this.precise = [];
12793
12795
  this.byWord = [];
12796
+ this.score = 0;
12797
+ this.matched = [];
12794
12798
  for (let p = 0; p < pattern.length; ) {
12795
12799
  let char = codePointAt(pattern, p), size = codePointSize(char);
12796
12800
  this.chars.push(char);
@@ -12800,21 +12804,23 @@ var FuzzyMatcher = class {
12800
12804
  }
12801
12805
  this.astral = pattern.length != this.chars.length;
12802
12806
  }
12807
+ ret(score2, matched) {
12808
+ this.score = score2;
12809
+ this.matched = matched;
12810
+ return true;
12811
+ }
12803
12812
  // Matches a given word (completion) against the pattern (input).
12804
- // Will return null for no match, and otherwise an array that starts
12805
- // with the match score, followed by any number of `from, to` pairs
12806
- // indicating the matched parts of `word`.
12813
+ // Will return a boolean indicating whether there was a match and,
12814
+ // on success, set `this.score` to the score, `this.matched` to an
12815
+ // array of `from, to` pairs indicating the matched parts of `word`.
12807
12816
  //
12808
12817
  // The score is a number that is more negative the worse the match
12809
12818
  // is. See `Penalty` above.
12810
12819
  match(word) {
12811
12820
  if (this.pattern.length == 0)
12812
- return [
12813
- -100
12814
- /* NotFull */
12815
- ];
12821
+ return this.ret(-100, []);
12816
12822
  if (word.length < this.pattern.length)
12817
- return null;
12823
+ return false;
12818
12824
  let { chars, folded, any, precise, byWord } = this;
12819
12825
  if (chars.length == 1) {
12820
12826
  let first = codePointAt(word, 0), firstSize = codePointSize(first);
@@ -12824,12 +12830,12 @@ var FuzzyMatcher = class {
12824
12830
  else if (first == folded[0])
12825
12831
  score2 += -200;
12826
12832
  else
12827
- return null;
12828
- return [score2, 0, firstSize];
12833
+ return false;
12834
+ return this.ret(score2, [0, firstSize]);
12829
12835
  }
12830
12836
  let direct = word.indexOf(this.pattern);
12831
12837
  if (direct == 0)
12832
- return [word.length == this.pattern.length ? 0 : -100, 0, this.pattern.length];
12838
+ return this.ret(word.length == this.pattern.length ? 0 : -100, [0, this.pattern.length]);
12833
12839
  let len = chars.length, anyTo = 0;
12834
12840
  if (direct < 0) {
12835
12841
  for (let i = 0, e = Math.min(word.length, 200); i < e && anyTo < len; ) {
@@ -12839,7 +12845,7 @@ var FuzzyMatcher = class {
12839
12845
  i += codePointSize(next);
12840
12846
  }
12841
12847
  if (anyTo < len)
12842
- return null;
12848
+ return false;
12843
12849
  }
12844
12850
  let preciseTo = 0;
12845
12851
  let byWordTo = 0, byWordFolded = false;
@@ -12874,27 +12880,27 @@ var FuzzyMatcher = class {
12874
12880
  if (byWordTo == len && byWord[0] == 0 && wordAdjacent)
12875
12881
  return this.result(-100 + (byWordFolded ? -200 : 0), byWord, word);
12876
12882
  if (adjacentTo == len && adjacentStart == 0)
12877
- return [-200 - word.length + (adjacentEnd == word.length ? 0 : -100), 0, adjacentEnd];
12883
+ return this.ret(-200 - word.length + (adjacentEnd == word.length ? 0 : -100), [0, adjacentEnd]);
12878
12884
  if (direct > -1)
12879
- return [-700 - word.length, direct, direct + this.pattern.length];
12885
+ return this.ret(-700 - word.length, [direct, direct + this.pattern.length]);
12880
12886
  if (adjacentTo == len)
12881
- return [-200 + -700 - word.length, adjacentStart, adjacentEnd];
12887
+ return this.ret(-200 + -700 - word.length, [adjacentStart, adjacentEnd]);
12882
12888
  if (byWordTo == len)
12883
12889
  return this.result(-100 + (byWordFolded ? -200 : 0) + -700 + (wordAdjacent ? 0 : -1100), byWord, word);
12884
- return chars.length == 2 ? null : this.result((any[0] ? -700 : 0) + -200 + -1100, any, word);
12890
+ return chars.length == 2 ? false : this.result((any[0] ? -700 : 0) + -200 + -1100, any, word);
12885
12891
  }
12886
12892
  result(score2, positions, word) {
12887
- let result = [score2 - word.length], i = 1;
12893
+ let result = [], i = 0;
12888
12894
  for (let pos of positions) {
12889
12895
  let to = pos + (this.astral ? codePointSize(codePointAt(word, pos)) : 1);
12890
- if (i > 1 && result[i - 1] == pos)
12896
+ if (i && result[i - 1] == pos)
12891
12897
  result[i - 1] = to;
12892
12898
  else {
12893
12899
  result[i++] = pos;
12894
12900
  result[i++] = to;
12895
12901
  }
12896
12902
  }
12897
- return result;
12903
+ return this.ret(score2 - word.length, result);
12898
12904
  }
12899
12905
  };
12900
12906
  var completionConfig = /* @__PURE__ */ Facet.define({
@@ -12977,8 +12983,8 @@ function optionContent(config2) {
12977
12983
  render(completion, _s, match) {
12978
12984
  let labelElt = document.createElement("span");
12979
12985
  labelElt.className = "cm-completionLabel";
12980
- let { label } = completion, off = 0;
12981
- for (let j = 1; j < match.length; ) {
12986
+ let label = completion.displayLabel || completion.label, off = 0;
12987
+ for (let j = 0; j < match.length; ) {
12982
12988
  let from = match[j++], to = match[j++];
12983
12989
  if (from > off)
12984
12990
  labelElt.appendChild(document.createTextNode(label.slice(off, from)));
@@ -13264,20 +13270,17 @@ function sortOptions(active, state) {
13264
13270
  };
13265
13271
  for (let a of active)
13266
13272
  if (a.hasResult()) {
13273
+ let getMatch = a.result.getMatch;
13267
13274
  if (a.result.filter === false) {
13268
- let getMatch = a.result.getMatch;
13269
13275
  for (let option of a.result.options) {
13270
- let match = [1e9 - options.length];
13271
- if (getMatch)
13272
- for (let n of getMatch(option))
13273
- match.push(n);
13274
- addOption(new Option(option, a.source, match, match[0]));
13276
+ addOption(new Option(option, a.source, getMatch ? getMatch(option) : [], 1e9 - options.length));
13275
13277
  }
13276
13278
  } else {
13277
- let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to)), match;
13279
+ let matcher = new FuzzyMatcher(state.sliceDoc(a.from, a.to));
13278
13280
  for (let option of a.result.options)
13279
- if (match = matcher.match(option.label)) {
13280
- addOption(new Option(option, a.source, match, match[0] + (option.boost || 0)));
13281
+ if (matcher.match(option.label)) {
13282
+ let matched = !option.displayLabel ? matcher.matched : getMatch ? getMatch(option, matcher.matched) : [];
13283
+ addOption(new Option(option, a.source, matched, matcher.score + (option.boost || 0)));
13281
13284
  }
13282
13285
  }
13283
13286
  }