@vuu-ui/vuu-codemirror 0.8.0-debug → 0.8.1-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
@@ -39,7 +39,6 @@ __export(src_exports, {
39
39
  HighlightStyle: () => HighlightStyle,
40
40
  LRLanguage: () => LRLanguage,
41
41
  LanguageSupport: () => LanguageSupport,
42
- SyntaxNode: () => import_common3.SyntaxNode,
43
42
  Tree: () => import_common3.Tree,
44
43
  asNameSuggestion: () => asNameSuggestion,
45
44
  autocompletion: () => autocompletion,
@@ -4531,7 +4530,7 @@ var WidgetView = class extends ContentView {
4531
4530
  if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom)
4532
4531
  break;
4533
4532
  }
4534
- return this.length ? rect : flattenRect(rect, !fromBack);
4533
+ return flattenRect(rect, !fromBack);
4535
4534
  }
4536
4535
  get isEditable() {
4537
4536
  return false;
@@ -4945,7 +4944,7 @@ var Decoration = class extends RangeValue {
4945
4944
  */
4946
4945
  static widget(spec) {
4947
4946
  let side = Math.max(-1e4, Math.min(1e4, spec.side || 0)), block = !!spec.block;
4948
- side += block ? side > 0 ? 3e8 : -4e8 : side > 0 ? 1e8 : -1e8;
4947
+ side += block && !spec.inlineOrder ? side > 0 ? 3e8 : -4e8 : side > 0 ? 1e8 : -1e8;
4949
4948
  return new PointDecoration(spec, side, side, block, spec.widget || null, false);
4950
4949
  }
4951
4950
  /**
@@ -6684,7 +6683,7 @@ function posAtCoords(view, coords, precise, bias = -1) {
6684
6683
  return 0;
6685
6684
  if (yOffset > docHeight)
6686
6685
  return view.state.doc.length;
6687
- for (let halfLine = view.defaultLineHeight / 2, bounced = false; ; ) {
6686
+ for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false; ; ) {
6688
6687
  block = view.elementAtHeight(yOffset);
6689
6688
  if (block.type == BlockType.Text)
6690
6689
  break;
@@ -6749,7 +6748,8 @@ function posAtCoords(view, coords, precise, bias = -1) {
6749
6748
  function posAtCoordsImprecise(view, contentRect, block, x, y) {
6750
6749
  let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
6751
6750
  if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) {
6752
- let line = Math.floor((y - block.top) / view.defaultLineHeight);
6751
+ let textHeight = view.viewState.heightOracle.textHeight;
6752
+ let line = Math.floor((y - block.top - (view.defaultLineHeight - textHeight) * 0.5) / textHeight);
6753
6753
  into += line * view.viewState.heightOracle.lineLength;
6754
6754
  }
6755
6755
  let content = view.state.sliceDoc(block.from, block.to);
@@ -6853,7 +6853,7 @@ function moveVertically(view, start, forward, distance) {
6853
6853
  startY = (dir < 0 ? line.top : line.bottom) + docTop;
6854
6854
  }
6855
6855
  let resolvedGoal = rect.left + goal;
6856
- let dist = distance !== null && distance !== void 0 ? distance : view.defaultLineHeight >> 1;
6856
+ let dist = distance !== null && distance !== void 0 ? distance : view.viewState.heightOracle.textHeight >> 1;
6857
6857
  for (let extra = 0; ; extra += 10) {
6858
6858
  let curY = startY + (dist + extra) * dir;
6859
6859
  let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
@@ -7087,7 +7087,6 @@ var MouseSelection = class {
7087
7087
  doc2.addEventListener("mouseup", this.up = this.up.bind(this));
7088
7088
  this.extend = startEvent.shiftKey;
7089
7089
  this.multiple = view.state.facet(EditorState.allowMultipleSelections) && addsSelectionRange(view, startEvent);
7090
- this.dragMove = dragMovesSelection(view, startEvent);
7091
7090
  this.dragging = isInPrimarySelection(view, startEvent) && getClickType(startEvent) == 1 ? null : false;
7092
7091
  }
7093
7092
  start(event) {
@@ -7405,7 +7404,7 @@ function dropText(view, event, text, direct) {
7405
7404
  let dropPos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
7406
7405
  event.preventDefault();
7407
7406
  let { mouseSelection } = view.inputState;
7408
- let del = direct && mouseSelection && mouseSelection.dragging && mouseSelection.dragMove ? { from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
7407
+ let del = direct && mouseSelection && mouseSelection.dragging && dragMovesSelection(view, event) ? { from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
7409
7408
  let ins = { from: dropPos, insert: text };
7410
7409
  let changes = view.state.changes(del ? [del, ins] : ins);
7411
7410
  view.focus();
@@ -9940,14 +9939,15 @@ var EditorView = class {
9940
9939
  if (flush)
9941
9940
  this.observer.forceFlush();
9942
9941
  let updated = null;
9943
- let sDOM = this.scrollDOM, { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9942
+ let sDOM = this.scrollDOM, { scrollTop } = sDOM;
9943
+ let { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9944
9944
  this.viewState.scrollAnchorHeight = -1;
9945
- if (scrollAnchorHeight < 0 || sDOM.scrollTop != this.viewState.scrollTop) {
9946
- if (sDOM.scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9945
+ if (scrollAnchorHeight < 0 || scrollTop != this.viewState.scrollTop) {
9946
+ if (scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9947
9947
  scrollAnchorPos = -1;
9948
9948
  scrollAnchorHeight = this.viewState.heightMap.height;
9949
9949
  } else {
9950
- let block = this.viewState.lineBlockAtHeight(sDOM.scrollTop);
9950
+ let block = this.viewState.lineBlockAtHeight(scrollTop);
9951
9951
  scrollAnchorPos = block.from;
9952
9952
  scrollAnchorHeight = block.top;
9953
9953
  }
@@ -10006,7 +10006,7 @@ var EditorView = class {
10006
10006
  let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
10007
10007
  let diff = newAnchorHeight - scrollAnchorHeight;
10008
10008
  if (diff > 1 || diff < -1) {
10009
- sDOM.scrollTop += diff;
10009
+ sDOM.scrollTop = scrollTop + diff;
10010
10010
  scrolled = true;
10011
10011
  }
10012
10012
  }
@@ -11981,7 +11981,7 @@ var requestIdle = (callback) => {
11981
11981
  let timeout = setTimeout(
11982
11982
  () => callback(),
11983
11983
  500
11984
- /* Work.MaxPause */
11984
+ /* MaxPause */
11985
11985
  );
11986
11986
  return () => clearTimeout(timeout);
11987
11987
  };
@@ -11991,11 +11991,11 @@ if (typeof requestIdleCallback != "undefined")
11991
11991
  () => {
11992
11992
  idle = requestIdleCallback(callback, {
11993
11993
  timeout: 500 - 100
11994
- /* Work.MinPause */
11994
+ /* MinPause */
11995
11995
  });
11996
11996
  },
11997
11997
  100
11998
- /* Work.MinPause */
11998
+ /* MinPause */
11999
11999
  );
12000
12000
  return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
12001
12001
  };
@@ -12040,7 +12040,7 @@ var parseWorker = /* @__PURE__ */ ViewPlugin.fromClass(class ParseWorker {
12040
12040
  let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
12041
12041
  if (field.tree == field.context.tree && field.context.isDone(
12042
12042
  vpTo + 1e5
12043
- /* Work.MaxParseAhead */
12043
+ /* MaxParseAhead */
12044
12044
  ))
12045
12045
  return;
12046
12046
  let endTime = Date.now() + Math.min(this.chunkBudget, 100, deadline && !isInputPending ? Math.max(25, deadline.timeRemaining() - 5) : 1e9);
@@ -12275,12 +12275,19 @@ var TreeIndentContext = class extends IndentContext {
12275
12275
  on if it is covered by another such node.
12276
12276
  */
12277
12277
  get baseIndent() {
12278
- let line = this.state.doc.lineAt(this.node.from);
12278
+ return this.baseIndentFor(this.node);
12279
+ }
12280
+ /**
12281
+ Get the indentation for the reference line of the given node
12282
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
12283
+ */
12284
+ baseIndentFor(node) {
12285
+ let line = this.state.doc.lineAt(node.from);
12279
12286
  for (; ; ) {
12280
- let atBreak = this.node.resolve(line.from);
12287
+ let atBreak = node.resolve(line.from);
12281
12288
  while (atBreak.parent && atBreak.parent.from == atBreak.from)
12282
12289
  atBreak = atBreak.parent;
12283
- if (isParent(atBreak, this.node))
12290
+ if (isParent(atBreak, node))
12284
12291
  break;
12285
12292
  line = this.state.doc.lineAt(atBreak.from);
12286
12293
  }
@@ -12794,7 +12801,7 @@ var FuzzyMatcher = class {
12794
12801
  if (this.pattern.length == 0)
12795
12802
  return [
12796
12803
  -100
12797
- /* Penalty.NotFull */
12804
+ /* NotFull */
12798
12805
  ];
12799
12806
  if (word.length < this.pattern.length)
12800
12807
  return null;
@@ -12927,7 +12934,7 @@ function defaultPositionInfo(view, list, option, info, space) {
12927
12934
  maxWidth = Math.min(
12928
12935
  400,
12929
12936
  (rtl ? list.right : space.right - list.left) - 30
12930
- /* Info.Margin */
12937
+ /* Margin */
12931
12938
  );
12932
12939
  let spaceBelow = space.bottom - list.bottom;
12933
12940
  if (spaceBelow >= infoHeight || spaceBelow > list.top) {
@@ -12942,210 +12949,6 @@ function defaultPositionInfo(view, list, option, info, space) {
12942
12949
  class: "cm-completionInfo-" + (narrow ? rtl ? "left-narrow" : "right-narrow" : left ? "left" : "right")
12943
12950
  };
12944
12951
  }
12945
- function moveCompletionSelection(forward, by = "option") {
12946
- return (view) => {
12947
- let cState = view.state.field(completionState, false);
12948
- if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
12949
- return false;
12950
- let step = 1, tooltip;
12951
- if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip)))
12952
- step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
12953
- let { length: length2 } = cState.open.options;
12954
- let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length2 - 1;
12955
- if (selected < 0)
12956
- selected = by == "page" ? 0 : length2 - 1;
12957
- else if (selected >= length2)
12958
- selected = by == "page" ? length2 - 1 : 0;
12959
- view.dispatch({ effects: setSelectedEffect.of(selected) });
12960
- return true;
12961
- };
12962
- }
12963
- var acceptCompletion = (view) => {
12964
- let cState = view.state.field(completionState, false);
12965
- if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
12966
- return false;
12967
- if (!cState.open.disabled)
12968
- return applyCompletion(view, cState.open.options[cState.open.selected]);
12969
- return true;
12970
- };
12971
- var startCompletion = (view) => {
12972
- let cState = view.state.field(completionState, false);
12973
- if (!cState)
12974
- return false;
12975
- view.dispatch({ effects: startCompletionEffect.of(true) });
12976
- return true;
12977
- };
12978
- var closeCompletion = (view) => {
12979
- let cState = view.state.field(completionState, false);
12980
- if (!cState || !cState.active.some(
12981
- (a) => a.state != 0
12982
- /* State.Inactive */
12983
- ))
12984
- return false;
12985
- view.dispatch({ effects: closeCompletionEffect.of(null) });
12986
- return true;
12987
- };
12988
- var RunningQuery = class {
12989
- constructor(active, context) {
12990
- this.active = active;
12991
- this.context = context;
12992
- this.time = Date.now();
12993
- this.updates = [];
12994
- this.done = void 0;
12995
- }
12996
- };
12997
- var DebounceTime = 50;
12998
- var MaxUpdateCount = 50;
12999
- var MinAbortTime = 1e3;
13000
- var completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
13001
- constructor(view) {
13002
- this.view = view;
13003
- this.debounceUpdate = -1;
13004
- this.running = [];
13005
- this.debounceAccept = -1;
13006
- this.composing = 0;
13007
- for (let active of view.state.field(completionState).active)
13008
- if (active.state == 1)
13009
- this.startQuery(active);
13010
- }
13011
- update(update) {
13012
- let cState = update.state.field(completionState);
13013
- if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
13014
- return;
13015
- let doesReset = update.transactions.some((tr) => {
13016
- return (tr.selection || tr.docChanged) && !getUserEvent(tr);
13017
- });
13018
- for (let i = 0; i < this.running.length; i++) {
13019
- let query = this.running[i];
13020
- if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
13021
- for (let handler of query.context.abortListeners) {
13022
- try {
13023
- handler();
13024
- } catch (e) {
13025
- logException(this.view.state, e);
13026
- }
13027
- }
13028
- query.context.abortListeners = null;
13029
- this.running.splice(i--, 1);
13030
- } else {
13031
- query.updates.push(...update.transactions);
13032
- }
13033
- }
13034
- if (this.debounceUpdate > -1)
13035
- clearTimeout(this.debounceUpdate);
13036
- this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
13037
- if (this.composing != 0)
13038
- for (let tr of update.transactions) {
13039
- if (getUserEvent(tr) == "input")
13040
- this.composing = 2;
13041
- else if (this.composing == 2 && tr.selection)
13042
- this.composing = 3;
13043
- }
13044
- }
13045
- startUpdate() {
13046
- this.debounceUpdate = -1;
13047
- let { state } = this.view, cState = state.field(completionState);
13048
- for (let active of cState.active) {
13049
- if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
13050
- this.startQuery(active);
13051
- }
13052
- }
13053
- startQuery(active) {
13054
- let { state } = this.view, pos = cur(state);
13055
- let context = new CompletionContext(state, pos, active.explicitPos == pos);
13056
- let pending = new RunningQuery(active, context);
13057
- this.running.push(pending);
13058
- Promise.resolve(active.source(context)).then((result) => {
13059
- if (!pending.context.aborted) {
13060
- pending.done = result || null;
13061
- this.scheduleAccept();
13062
- }
13063
- }, (err) => {
13064
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13065
- logException(this.view.state, err);
13066
- });
13067
- }
13068
- scheduleAccept() {
13069
- if (this.running.every((q) => q.done !== void 0))
13070
- this.accept();
13071
- else if (this.debounceAccept < 0)
13072
- this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
13073
- }
13074
- // For each finished query in this.running, try to create a result
13075
- // or, if appropriate, restart the query.
13076
- accept() {
13077
- var _a2;
13078
- if (this.debounceAccept > -1)
13079
- clearTimeout(this.debounceAccept);
13080
- this.debounceAccept = -1;
13081
- let updated = [];
13082
- let conf = this.view.state.facet(completionConfig);
13083
- for (let i = 0; i < this.running.length; i++) {
13084
- let query = this.running[i];
13085
- if (query.done === void 0)
13086
- continue;
13087
- this.running.splice(i--, 1);
13088
- if (query.done) {
13089
- 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));
13090
- for (let tr of query.updates)
13091
- active = active.update(tr, conf);
13092
- if (active.hasResult()) {
13093
- updated.push(active);
13094
- continue;
13095
- }
13096
- }
13097
- let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
13098
- if (current && current.state == 1) {
13099
- if (query.done == null) {
13100
- let active = new ActiveSource(
13101
- query.active.source,
13102
- 0
13103
- /* State.Inactive */
13104
- );
13105
- for (let tr of query.updates)
13106
- active = active.update(tr, conf);
13107
- if (active.state != 1)
13108
- updated.push(active);
13109
- } else {
13110
- this.startQuery(current);
13111
- }
13112
- }
13113
- }
13114
- if (updated.length)
13115
- this.view.dispatch({ effects: setActiveEffect.of(updated) });
13116
- }
13117
- }, {
13118
- eventHandlers: {
13119
- blur(event) {
13120
- let state = this.view.state.field(completionState, false);
13121
- if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
13122
- let dialog = state.open && getTooltip(this.view, state.open.tooltip);
13123
- if (!dialog || !dialog.dom.contains(event.relatedTarget))
13124
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13125
- }
13126
- },
13127
- compositionstart() {
13128
- this.composing = 1;
13129
- },
13130
- compositionend() {
13131
- if (this.composing == 3) {
13132
- setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
13133
- }
13134
- this.composing = 0;
13135
- }
13136
- }
13137
- });
13138
- function applyCompletion(view, option) {
13139
- const apply = option.completion.apply || option.completion.label;
13140
- let result = view.state.field(completionState).active.find((a) => a.source == option.source);
13141
- if (!(result instanceof ActiveResult))
13142
- return false;
13143
- if (typeof apply == "string")
13144
- view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
13145
- else
13146
- apply(view, option.completion, result.from, result.to);
13147
- return true;
13148
- }
13149
12952
  function optionContent(config2) {
13150
12953
  let content = config2.addToOptions.slice();
13151
12954
  if (config2.icons)
@@ -13205,10 +13008,12 @@ function rangeAroundSelected(total, selected, max) {
13205
13008
  return { from: total - (off + 1) * max, to: total - off * max };
13206
13009
  }
13207
13010
  var CompletionTooltip = class {
13208
- constructor(view, stateField) {
13011
+ constructor(view, stateField, applyCompletion2) {
13209
13012
  this.view = view;
13210
13013
  this.stateField = stateField;
13014
+ this.applyCompletion = applyCompletion2;
13211
13015
  this.info = null;
13016
+ this.infoDestroy = null;
13212
13017
  this.placeInfoReq = {
13213
13018
  read: () => this.measureInfo(),
13214
13019
  write: (pos) => this.placeInfo(pos),
@@ -13229,7 +13034,7 @@ var CompletionTooltip = class {
13229
13034
  this.dom.addEventListener("mousedown", (e) => {
13230
13035
  for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) {
13231
13036
  if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) {
13232
- applyCompletion(view, options[+match[1]]);
13037
+ this.applyCompletion(view, options[+match[1]]);
13233
13038
  e.preventDefault();
13234
13039
  return;
13235
13040
  }
@@ -13289,10 +13094,7 @@ var CompletionTooltip = class {
13289
13094
  });
13290
13095
  }
13291
13096
  if (this.updateSelectedOption(open.selected)) {
13292
- if (this.info) {
13293
- this.info.remove();
13294
- this.info = null;
13295
- }
13097
+ this.destroyInfo();
13296
13098
  let { completion } = open.options[open.selected];
13297
13099
  let { info } = completion;
13298
13100
  if (!info)
@@ -13301,20 +13103,28 @@ var CompletionTooltip = class {
13301
13103
  if (!infoResult)
13302
13104
  return;
13303
13105
  if ("then" in infoResult) {
13304
- infoResult.then((node) => {
13305
- if (node && this.view.state.field(this.stateField, false) == cState)
13306
- this.addInfoPane(node);
13106
+ infoResult.then((obj) => {
13107
+ if (obj && this.view.state.field(this.stateField, false) == cState)
13108
+ this.addInfoPane(obj, completion);
13307
13109
  }).catch((e) => logException(this.view.state, e, "completion info"));
13308
13110
  } else {
13309
- this.addInfoPane(infoResult);
13111
+ this.addInfoPane(infoResult, completion);
13310
13112
  }
13311
13113
  }
13312
13114
  }
13313
- addInfoPane(content) {
13314
- let dom = this.info = document.createElement("div");
13315
- dom.className = "cm-tooltip cm-completionInfo";
13316
- dom.appendChild(content);
13317
- this.dom.appendChild(dom);
13115
+ addInfoPane(content, completion) {
13116
+ this.destroyInfo();
13117
+ let wrap = this.info = document.createElement("div");
13118
+ wrap.className = "cm-tooltip cm-completionInfo";
13119
+ if (content.nodeType != null) {
13120
+ wrap.appendChild(content);
13121
+ this.infoDestroy = null;
13122
+ } else {
13123
+ let { dom, destroy } = content;
13124
+ wrap.appendChild(dom);
13125
+ this.infoDestroy = destroy || null;
13126
+ }
13127
+ this.dom.appendChild(wrap);
13318
13128
  this.view.requestMeasure(this.placeInfoReq);
13319
13129
  }
13320
13130
  updateSelectedOption(selected) {
@@ -13402,9 +13212,20 @@ var CompletionTooltip = class {
13402
13212
  ul.classList.add("cm-completionListIncompleteBottom");
13403
13213
  return ul;
13404
13214
  }
13215
+ destroyInfo() {
13216
+ if (this.info) {
13217
+ if (this.infoDestroy)
13218
+ this.infoDestroy();
13219
+ this.info.remove();
13220
+ this.info = null;
13221
+ }
13222
+ }
13223
+ destroy() {
13224
+ this.destroyInfo();
13225
+ }
13405
13226
  };
13406
- function completionTooltip(stateField) {
13407
- return (view) => new CompletionTooltip(view, stateField);
13227
+ function completionTooltip(stateField, applyCompletion2) {
13228
+ return (view) => new CompletionTooltip(view, stateField, applyCompletion2);
13408
13229
  }
13409
13230
  function scrollIntoView2(container, element) {
13410
13231
  let parent = container.getBoundingClientRect();
@@ -13469,7 +13290,8 @@ function sortOptions(active, state) {
13469
13290
  let result = [], prev = null;
13470
13291
  let compare2 = state.facet(completionConfig).compareCompletions;
13471
13292
  for (let opt of options.sort((a, b) => b.score - a.score || compare2(a.completion, b.completion))) {
13472
- if (!prev || prev.label != opt.completion.label || prev.detail != opt.completion.detail || prev.type != null && opt.completion.type != null && prev.type != opt.completion.type || prev.apply != opt.completion.apply)
13293
+ let cur2 = opt.completion;
13294
+ if (!prev || prev.label != cur2.label || prev.detail != cur2.detail || prev.type != null && cur2.type != null && prev.type != cur2.type || prev.apply != cur2.apply || prev.boost != cur2.boost)
13473
13295
  result.push(opt);
13474
13296
  else if (score(opt.completion) > score(prev))
13475
13297
  result[result.length - 1] = opt;
@@ -13494,7 +13316,7 @@ var CompletionDialog = class {
13494
13316
  if (!options.length) {
13495
13317
  return prev && active.some(
13496
13318
  (a) => a.state == 1
13497
- /* State.Pending */
13319
+ /* Pending */
13498
13320
  ) ? new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
13499
13321
  }
13500
13322
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
@@ -13508,7 +13330,7 @@ var CompletionDialog = class {
13508
13330
  }
13509
13331
  return new CompletionDialog(options, makeAttrs(id, selected), {
13510
13332
  pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
13511
- create: completionTooltip(completionState),
13333
+ create: completionTooltip(completionState, applyCompletion),
13512
13334
  above: conf.aboveCursor
13513
13335
  }, prev ? prev.timestamp : Date.now(), selected, false);
13514
13336
  }
@@ -13533,9 +13355,9 @@ var CompletionState = class {
13533
13355
  source,
13534
13356
  this.active.some(
13535
13357
  (a) => a.state != 0
13536
- /* State.Inactive */
13358
+ /* Inactive */
13537
13359
  ) ? 1 : 0
13538
- /* State.Inactive */
13360
+ /* Inactive */
13539
13361
  );
13540
13362
  return value.update(tr, conf);
13541
13363
  });
@@ -13548,17 +13370,17 @@ var CompletionState = class {
13548
13370
  open = CompletionDialog.build(active, state, this.id, open, conf);
13549
13371
  else if (open && open.disabled && !active.some(
13550
13372
  (a) => a.state == 1
13551
- /* State.Pending */
13373
+ /* Pending */
13552
13374
  ))
13553
13375
  open = null;
13554
13376
  if (!open && active.every(
13555
13377
  (a) => a.state != 1
13556
- /* State.Pending */
13378
+ /* Pending */
13557
13379
  ) && active.some((a) => a.hasResult()))
13558
13380
  active = active.map((a) => a.hasResult() ? new ActiveSource(
13559
13381
  a.source,
13560
13382
  0
13561
- /* State.Inactive */
13383
+ /* Inactive */
13562
13384
  ) : a);
13563
13385
  for (let effect of tr.effects)
13564
13386
  if (effect.is(setSelectedEffect))
@@ -13623,7 +13445,7 @@ var ActiveSource = class {
13623
13445
  value = new ActiveSource(
13624
13446
  value.source,
13625
13447
  0
13626
- /* State.Inactive */
13448
+ /* Inactive */
13627
13449
  );
13628
13450
  for (let effect of tr.effects) {
13629
13451
  if (effect.is(startCompletionEffect))
@@ -13632,7 +13454,7 @@ var ActiveSource = class {
13632
13454
  value = new ActiveSource(
13633
13455
  value.source,
13634
13456
  0
13635
- /* State.Inactive */
13457
+ /* Inactive */
13636
13458
  );
13637
13459
  else if (effect.is(setActiveEffect)) {
13638
13460
  for (let active of effect.value)
@@ -13646,14 +13468,14 @@ var ActiveSource = class {
13646
13468
  return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(
13647
13469
  this.source,
13648
13470
  1
13649
- /* State.Pending */
13471
+ /* Pending */
13650
13472
  );
13651
13473
  }
13652
13474
  handleChange(tr) {
13653
13475
  return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(
13654
13476
  this.source,
13655
13477
  0
13656
- /* State.Inactive */
13478
+ /* Inactive */
13657
13479
  ) : this.map(tr.changes);
13658
13480
  }
13659
13481
  map(changes) {
@@ -13678,7 +13500,7 @@ var ActiveResult = class extends ActiveSource {
13678
13500
  return new ActiveSource(
13679
13501
  this.source,
13680
13502
  type == "input" && conf.activateOnTyping ? 1 : 0
13681
- /* State.Inactive */
13503
+ /* Inactive */
13682
13504
  );
13683
13505
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated;
13684
13506
  if (checkValid(this.result.validFor, tr.state, from, to))
@@ -13691,7 +13513,7 @@ var ActiveResult = class extends ActiveSource {
13691
13513
  return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(
13692
13514
  this.source,
13693
13515
  0
13694
- /* State.Inactive */
13516
+ /* Inactive */
13695
13517
  ) : this.map(tr.changes);
13696
13518
  }
13697
13519
  map(mapping) {
@@ -13722,6 +13544,208 @@ var completionState = /* @__PURE__ */ StateField.define({
13722
13544
  EditorView.contentAttributes.from(f, (state) => state.attrs)
13723
13545
  ]
13724
13546
  });
13547
+ function applyCompletion(view, option) {
13548
+ const apply = option.completion.apply || option.completion.label;
13549
+ let result = view.state.field(completionState).active.find((a) => a.source == option.source);
13550
+ if (!(result instanceof ActiveResult))
13551
+ return false;
13552
+ if (typeof apply == "string")
13553
+ view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
13554
+ else
13555
+ apply(view, option.completion, result.from, result.to);
13556
+ return true;
13557
+ }
13558
+ function moveCompletionSelection(forward, by = "option") {
13559
+ return (view) => {
13560
+ let cState = view.state.field(completionState, false);
13561
+ if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
13562
+ return false;
13563
+ let step = 1, tooltip;
13564
+ if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip)))
13565
+ step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
13566
+ let { length: length2 } = cState.open.options;
13567
+ let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length2 - 1;
13568
+ if (selected < 0)
13569
+ selected = by == "page" ? 0 : length2 - 1;
13570
+ else if (selected >= length2)
13571
+ selected = by == "page" ? length2 - 1 : 0;
13572
+ view.dispatch({ effects: setSelectedEffect.of(selected) });
13573
+ return true;
13574
+ };
13575
+ }
13576
+ var acceptCompletion = (view) => {
13577
+ let cState = view.state.field(completionState, false);
13578
+ if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
13579
+ return false;
13580
+ return applyCompletion(view, cState.open.options[cState.open.selected]);
13581
+ };
13582
+ var startCompletion = (view) => {
13583
+ let cState = view.state.field(completionState, false);
13584
+ if (!cState)
13585
+ return false;
13586
+ view.dispatch({ effects: startCompletionEffect.of(true) });
13587
+ return true;
13588
+ };
13589
+ var closeCompletion = (view) => {
13590
+ let cState = view.state.field(completionState, false);
13591
+ if (!cState || !cState.active.some(
13592
+ (a) => a.state != 0
13593
+ /* Inactive */
13594
+ ))
13595
+ return false;
13596
+ view.dispatch({ effects: closeCompletionEffect.of(null) });
13597
+ return true;
13598
+ };
13599
+ var RunningQuery = class {
13600
+ constructor(active, context) {
13601
+ this.active = active;
13602
+ this.context = context;
13603
+ this.time = Date.now();
13604
+ this.updates = [];
13605
+ this.done = void 0;
13606
+ }
13607
+ };
13608
+ var DebounceTime = 50;
13609
+ var MaxUpdateCount = 50;
13610
+ var MinAbortTime = 1e3;
13611
+ var completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
13612
+ constructor(view) {
13613
+ this.view = view;
13614
+ this.debounceUpdate = -1;
13615
+ this.running = [];
13616
+ this.debounceAccept = -1;
13617
+ this.composing = 0;
13618
+ for (let active of view.state.field(completionState).active)
13619
+ if (active.state == 1)
13620
+ this.startQuery(active);
13621
+ }
13622
+ update(update) {
13623
+ let cState = update.state.field(completionState);
13624
+ if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
13625
+ return;
13626
+ let doesReset = update.transactions.some((tr) => {
13627
+ return (tr.selection || tr.docChanged) && !getUserEvent(tr);
13628
+ });
13629
+ for (let i = 0; i < this.running.length; i++) {
13630
+ let query = this.running[i];
13631
+ if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
13632
+ for (let handler of query.context.abortListeners) {
13633
+ try {
13634
+ handler();
13635
+ } catch (e) {
13636
+ logException(this.view.state, e);
13637
+ }
13638
+ }
13639
+ query.context.abortListeners = null;
13640
+ this.running.splice(i--, 1);
13641
+ } else {
13642
+ query.updates.push(...update.transactions);
13643
+ }
13644
+ }
13645
+ if (this.debounceUpdate > -1)
13646
+ clearTimeout(this.debounceUpdate);
13647
+ this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
13648
+ if (this.composing != 0)
13649
+ for (let tr of update.transactions) {
13650
+ if (getUserEvent(tr) == "input")
13651
+ this.composing = 2;
13652
+ else if (this.composing == 2 && tr.selection)
13653
+ this.composing = 3;
13654
+ }
13655
+ }
13656
+ startUpdate() {
13657
+ this.debounceUpdate = -1;
13658
+ let { state } = this.view, cState = state.field(completionState);
13659
+ for (let active of cState.active) {
13660
+ if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
13661
+ this.startQuery(active);
13662
+ }
13663
+ }
13664
+ startQuery(active) {
13665
+ let { state } = this.view, pos = cur(state);
13666
+ let context = new CompletionContext(state, pos, active.explicitPos == pos);
13667
+ let pending = new RunningQuery(active, context);
13668
+ this.running.push(pending);
13669
+ Promise.resolve(active.source(context)).then((result) => {
13670
+ if (!pending.context.aborted) {
13671
+ pending.done = result || null;
13672
+ this.scheduleAccept();
13673
+ }
13674
+ }, (err) => {
13675
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13676
+ logException(this.view.state, err);
13677
+ });
13678
+ }
13679
+ scheduleAccept() {
13680
+ if (this.running.every((q) => q.done !== void 0))
13681
+ this.accept();
13682
+ else if (this.debounceAccept < 0)
13683
+ this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
13684
+ }
13685
+ // For each finished query in this.running, try to create a result
13686
+ // or, if appropriate, restart the query.
13687
+ accept() {
13688
+ var _a2;
13689
+ if (this.debounceAccept > -1)
13690
+ clearTimeout(this.debounceAccept);
13691
+ this.debounceAccept = -1;
13692
+ let updated = [];
13693
+ let conf = this.view.state.facet(completionConfig);
13694
+ for (let i = 0; i < this.running.length; i++) {
13695
+ let query = this.running[i];
13696
+ if (query.done === void 0)
13697
+ continue;
13698
+ this.running.splice(i--, 1);
13699
+ if (query.done) {
13700
+ 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));
13701
+ for (let tr of query.updates)
13702
+ active = active.update(tr, conf);
13703
+ if (active.hasResult()) {
13704
+ updated.push(active);
13705
+ continue;
13706
+ }
13707
+ }
13708
+ let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
13709
+ if (current && current.state == 1) {
13710
+ if (query.done == null) {
13711
+ let active = new ActiveSource(
13712
+ query.active.source,
13713
+ 0
13714
+ /* Inactive */
13715
+ );
13716
+ for (let tr of query.updates)
13717
+ active = active.update(tr, conf);
13718
+ if (active.state != 1)
13719
+ updated.push(active);
13720
+ } else {
13721
+ this.startQuery(current);
13722
+ }
13723
+ }
13724
+ }
13725
+ if (updated.length)
13726
+ this.view.dispatch({ effects: setActiveEffect.of(updated) });
13727
+ }
13728
+ }, {
13729
+ eventHandlers: {
13730
+ blur(event) {
13731
+ let state = this.view.state.field(completionState, false);
13732
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
13733
+ let dialog = state.open && getTooltip(this.view, state.open.tooltip);
13734
+ if (!dialog || !dialog.dom.contains(event.relatedTarget))
13735
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13736
+ }
13737
+ },
13738
+ compositionstart() {
13739
+ this.composing = 1;
13740
+ },
13741
+ compositionend() {
13742
+ if (this.composing == 3) {
13743
+ setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
13744
+ }
13745
+ this.composing = 0;
13746
+ }
13747
+ }
13748
+ });
13725
13749
  var baseTheme2 = /* @__PURE__ */ EditorView.baseTheme({
13726
13750
  ".cm-tooltip.cm-tooltip-autocomplete": {
13727
13751
  "& > ul": {