@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/esm/index.js CHANGED
@@ -4470,7 +4470,7 @@ var WidgetView = class extends ContentView {
4470
4470
  if (pos > 0 ? i == 0 : i == rects.length - 1 || rect.top < rect.bottom)
4471
4471
  break;
4472
4472
  }
4473
- return this.length ? rect : flattenRect(rect, !fromBack);
4473
+ return flattenRect(rect, !fromBack);
4474
4474
  }
4475
4475
  get isEditable() {
4476
4476
  return false;
@@ -4884,7 +4884,7 @@ var Decoration = class extends RangeValue {
4884
4884
  */
4885
4885
  static widget(spec) {
4886
4886
  let side = Math.max(-1e4, Math.min(1e4, spec.side || 0)), block = !!spec.block;
4887
- side += block ? side > 0 ? 3e8 : -4e8 : side > 0 ? 1e8 : -1e8;
4887
+ side += block && !spec.inlineOrder ? side > 0 ? 3e8 : -4e8 : side > 0 ? 1e8 : -1e8;
4888
4888
  return new PointDecoration(spec, side, side, block, spec.widget || null, false);
4889
4889
  }
4890
4890
  /**
@@ -6623,7 +6623,7 @@ function posAtCoords(view, coords, precise, bias = -1) {
6623
6623
  return 0;
6624
6624
  if (yOffset > docHeight)
6625
6625
  return view.state.doc.length;
6626
- for (let halfLine = view.defaultLineHeight / 2, bounced = false; ; ) {
6626
+ for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false; ; ) {
6627
6627
  block = view.elementAtHeight(yOffset);
6628
6628
  if (block.type == BlockType.Text)
6629
6629
  break;
@@ -6688,7 +6688,8 @@ function posAtCoords(view, coords, precise, bias = -1) {
6688
6688
  function posAtCoordsImprecise(view, contentRect, block, x, y) {
6689
6689
  let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
6690
6690
  if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) {
6691
- let line = Math.floor((y - block.top) / view.defaultLineHeight);
6691
+ let textHeight = view.viewState.heightOracle.textHeight;
6692
+ let line = Math.floor((y - block.top - (view.defaultLineHeight - textHeight) * 0.5) / textHeight);
6692
6693
  into += line * view.viewState.heightOracle.lineLength;
6693
6694
  }
6694
6695
  let content = view.state.sliceDoc(block.from, block.to);
@@ -6792,7 +6793,7 @@ function moveVertically(view, start, forward, distance) {
6792
6793
  startY = (dir < 0 ? line.top : line.bottom) + docTop;
6793
6794
  }
6794
6795
  let resolvedGoal = rect.left + goal;
6795
- let dist = distance !== null && distance !== void 0 ? distance : view.defaultLineHeight >> 1;
6796
+ let dist = distance !== null && distance !== void 0 ? distance : view.viewState.heightOracle.textHeight >> 1;
6796
6797
  for (let extra = 0; ; extra += 10) {
6797
6798
  let curY = startY + (dist + extra) * dir;
6798
6799
  let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
@@ -7026,7 +7027,6 @@ var MouseSelection = class {
7026
7027
  doc2.addEventListener("mouseup", this.up = this.up.bind(this));
7027
7028
  this.extend = startEvent.shiftKey;
7028
7029
  this.multiple = view.state.facet(EditorState.allowMultipleSelections) && addsSelectionRange(view, startEvent);
7029
- this.dragMove = dragMovesSelection(view, startEvent);
7030
7030
  this.dragging = isInPrimarySelection(view, startEvent) && getClickType(startEvent) == 1 ? null : false;
7031
7031
  }
7032
7032
  start(event) {
@@ -7344,7 +7344,7 @@ function dropText(view, event, text, direct) {
7344
7344
  let dropPos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
7345
7345
  event.preventDefault();
7346
7346
  let { mouseSelection } = view.inputState;
7347
- let del = direct && mouseSelection && mouseSelection.dragging && mouseSelection.dragMove ? { from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
7347
+ let del = direct && mouseSelection && mouseSelection.dragging && dragMovesSelection(view, event) ? { from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
7348
7348
  let ins = { from: dropPos, insert: text };
7349
7349
  let changes = view.state.changes(del ? [del, ins] : ins);
7350
7350
  view.focus();
@@ -9879,14 +9879,15 @@ var EditorView = class {
9879
9879
  if (flush)
9880
9880
  this.observer.forceFlush();
9881
9881
  let updated = null;
9882
- let sDOM = this.scrollDOM, { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9882
+ let sDOM = this.scrollDOM, { scrollTop } = sDOM;
9883
+ let { scrollAnchorPos, scrollAnchorHeight } = this.viewState;
9883
9884
  this.viewState.scrollAnchorHeight = -1;
9884
- if (scrollAnchorHeight < 0 || sDOM.scrollTop != this.viewState.scrollTop) {
9885
- if (sDOM.scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9885
+ if (scrollAnchorHeight < 0 || scrollTop != this.viewState.scrollTop) {
9886
+ if (scrollTop > sDOM.scrollHeight - sDOM.clientHeight - 4) {
9886
9887
  scrollAnchorPos = -1;
9887
9888
  scrollAnchorHeight = this.viewState.heightMap.height;
9888
9889
  } else {
9889
- let block = this.viewState.lineBlockAtHeight(sDOM.scrollTop);
9890
+ let block = this.viewState.lineBlockAtHeight(scrollTop);
9890
9891
  scrollAnchorPos = block.from;
9891
9892
  scrollAnchorHeight = block.top;
9892
9893
  }
@@ -9945,7 +9946,7 @@ var EditorView = class {
9945
9946
  let newAnchorHeight = scrollAnchorPos < 0 ? this.viewState.heightMap.height : this.viewState.lineBlockAt(scrollAnchorPos).top;
9946
9947
  let diff = newAnchorHeight - scrollAnchorHeight;
9947
9948
  if (diff > 1 || diff < -1) {
9948
- sDOM.scrollTop += diff;
9949
+ sDOM.scrollTop = scrollTop + diff;
9949
9950
  scrolled = true;
9950
9951
  }
9951
9952
  }
@@ -11493,7 +11494,7 @@ GutterMarker.prototype.startSide = GutterMarker.prototype.endSide = -1;
11493
11494
  GutterMarker.prototype.point = true;
11494
11495
 
11495
11496
  // ../../node_modules/@codemirror/language/dist/index.js
11496
- import { NodeProp, IterMode, Tree, TreeFragment, Parser, NodeType, NodeSet } from "@lezer/common";
11497
+ import { NodeProp, Tree, IterMode, TreeFragment, Parser, NodeType, NodeSet } from "@lezer/common";
11497
11498
  import { tags, tagHighlighter, highlightTree, styleTags } from "@lezer/highlight";
11498
11499
  var _a;
11499
11500
  var languageDataProp = /* @__PURE__ */ new NodeProp();
@@ -11920,7 +11921,7 @@ var requestIdle = (callback) => {
11920
11921
  let timeout = setTimeout(
11921
11922
  () => callback(),
11922
11923
  500
11923
- /* Work.MaxPause */
11924
+ /* MaxPause */
11924
11925
  );
11925
11926
  return () => clearTimeout(timeout);
11926
11927
  };
@@ -11930,11 +11931,11 @@ if (typeof requestIdleCallback != "undefined")
11930
11931
  () => {
11931
11932
  idle = requestIdleCallback(callback, {
11932
11933
  timeout: 500 - 100
11933
- /* Work.MinPause */
11934
+ /* MinPause */
11934
11935
  });
11935
11936
  },
11936
11937
  100
11937
- /* Work.MinPause */
11938
+ /* MinPause */
11938
11939
  );
11939
11940
  return () => idle < 0 ? clearTimeout(timeout) : cancelIdleCallback(idle);
11940
11941
  };
@@ -11979,7 +11980,7 @@ var parseWorker = /* @__PURE__ */ ViewPlugin.fromClass(class ParseWorker {
11979
11980
  let { state, viewport: { to: vpTo } } = this.view, field = state.field(Language.state);
11980
11981
  if (field.tree == field.context.tree && field.context.isDone(
11981
11982
  vpTo + 1e5
11982
- /* Work.MaxParseAhead */
11983
+ /* MaxParseAhead */
11983
11984
  ))
11984
11985
  return;
11985
11986
  let endTime = Date.now() + Math.min(this.chunkBudget, 100, deadline && !isInputPending ? Math.max(25, deadline.timeRemaining() - 5) : 1e9);
@@ -12214,12 +12215,19 @@ var TreeIndentContext = class extends IndentContext {
12214
12215
  on if it is covered by another such node.
12215
12216
  */
12216
12217
  get baseIndent() {
12217
- let line = this.state.doc.lineAt(this.node.from);
12218
+ return this.baseIndentFor(this.node);
12219
+ }
12220
+ /**
12221
+ Get the indentation for the reference line of the given node
12222
+ (see [`baseIndent`](https://codemirror.net/6/docs/ref/#language.TreeIndentContext.baseIndent)).
12223
+ */
12224
+ baseIndentFor(node) {
12225
+ let line = this.state.doc.lineAt(node.from);
12218
12226
  for (; ; ) {
12219
- let atBreak = this.node.resolve(line.from);
12227
+ let atBreak = node.resolve(line.from);
12220
12228
  while (atBreak.parent && atBreak.parent.from == atBreak.from)
12221
12229
  atBreak = atBreak.parent;
12222
- if (isParent(atBreak, this.node))
12230
+ if (isParent(atBreak, node))
12223
12231
  break;
12224
12232
  line = this.state.doc.lineAt(atBreak.from);
12225
12233
  }
@@ -12733,7 +12741,7 @@ var FuzzyMatcher = class {
12733
12741
  if (this.pattern.length == 0)
12734
12742
  return [
12735
12743
  -100
12736
- /* Penalty.NotFull */
12744
+ /* NotFull */
12737
12745
  ];
12738
12746
  if (word.length < this.pattern.length)
12739
12747
  return null;
@@ -12866,7 +12874,7 @@ function defaultPositionInfo(view, list, option, info, space) {
12866
12874
  maxWidth = Math.min(
12867
12875
  400,
12868
12876
  (rtl ? list.right : space.right - list.left) - 30
12869
- /* Info.Margin */
12877
+ /* Margin */
12870
12878
  );
12871
12879
  let spaceBelow = space.bottom - list.bottom;
12872
12880
  if (spaceBelow >= infoHeight || spaceBelow > list.top) {
@@ -12881,210 +12889,6 @@ function defaultPositionInfo(view, list, option, info, space) {
12881
12889
  class: "cm-completionInfo-" + (narrow ? rtl ? "left-narrow" : "right-narrow" : left ? "left" : "right")
12882
12890
  };
12883
12891
  }
12884
- function moveCompletionSelection(forward, by = "option") {
12885
- return (view) => {
12886
- let cState = view.state.field(completionState, false);
12887
- if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
12888
- return false;
12889
- let step = 1, tooltip;
12890
- if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip)))
12891
- step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
12892
- let { length: length2 } = cState.open.options;
12893
- let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length2 - 1;
12894
- if (selected < 0)
12895
- selected = by == "page" ? 0 : length2 - 1;
12896
- else if (selected >= length2)
12897
- selected = by == "page" ? length2 - 1 : 0;
12898
- view.dispatch({ effects: setSelectedEffect.of(selected) });
12899
- return true;
12900
- };
12901
- }
12902
- var acceptCompletion = (view) => {
12903
- let cState = view.state.field(completionState, false);
12904
- if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
12905
- return false;
12906
- if (!cState.open.disabled)
12907
- return applyCompletion(view, cState.open.options[cState.open.selected]);
12908
- return true;
12909
- };
12910
- var startCompletion = (view) => {
12911
- let cState = view.state.field(completionState, false);
12912
- if (!cState)
12913
- return false;
12914
- view.dispatch({ effects: startCompletionEffect.of(true) });
12915
- return true;
12916
- };
12917
- var closeCompletion = (view) => {
12918
- let cState = view.state.field(completionState, false);
12919
- if (!cState || !cState.active.some(
12920
- (a) => a.state != 0
12921
- /* State.Inactive */
12922
- ))
12923
- return false;
12924
- view.dispatch({ effects: closeCompletionEffect.of(null) });
12925
- return true;
12926
- };
12927
- var RunningQuery = class {
12928
- constructor(active, context) {
12929
- this.active = active;
12930
- this.context = context;
12931
- this.time = Date.now();
12932
- this.updates = [];
12933
- this.done = void 0;
12934
- }
12935
- };
12936
- var DebounceTime = 50;
12937
- var MaxUpdateCount = 50;
12938
- var MinAbortTime = 1e3;
12939
- var completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
12940
- constructor(view) {
12941
- this.view = view;
12942
- this.debounceUpdate = -1;
12943
- this.running = [];
12944
- this.debounceAccept = -1;
12945
- this.composing = 0;
12946
- for (let active of view.state.field(completionState).active)
12947
- if (active.state == 1)
12948
- this.startQuery(active);
12949
- }
12950
- update(update) {
12951
- let cState = update.state.field(completionState);
12952
- if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
12953
- return;
12954
- let doesReset = update.transactions.some((tr) => {
12955
- return (tr.selection || tr.docChanged) && !getUserEvent(tr);
12956
- });
12957
- for (let i = 0; i < this.running.length; i++) {
12958
- let query = this.running[i];
12959
- if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
12960
- for (let handler of query.context.abortListeners) {
12961
- try {
12962
- handler();
12963
- } catch (e) {
12964
- logException(this.view.state, e);
12965
- }
12966
- }
12967
- query.context.abortListeners = null;
12968
- this.running.splice(i--, 1);
12969
- } else {
12970
- query.updates.push(...update.transactions);
12971
- }
12972
- }
12973
- if (this.debounceUpdate > -1)
12974
- clearTimeout(this.debounceUpdate);
12975
- this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
12976
- if (this.composing != 0)
12977
- for (let tr of update.transactions) {
12978
- if (getUserEvent(tr) == "input")
12979
- this.composing = 2;
12980
- else if (this.composing == 2 && tr.selection)
12981
- this.composing = 3;
12982
- }
12983
- }
12984
- startUpdate() {
12985
- this.debounceUpdate = -1;
12986
- let { state } = this.view, cState = state.field(completionState);
12987
- for (let active of cState.active) {
12988
- if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
12989
- this.startQuery(active);
12990
- }
12991
- }
12992
- startQuery(active) {
12993
- let { state } = this.view, pos = cur(state);
12994
- let context = new CompletionContext(state, pos, active.explicitPos == pos);
12995
- let pending = new RunningQuery(active, context);
12996
- this.running.push(pending);
12997
- Promise.resolve(active.source(context)).then((result) => {
12998
- if (!pending.context.aborted) {
12999
- pending.done = result || null;
13000
- this.scheduleAccept();
13001
- }
13002
- }, (err) => {
13003
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13004
- logException(this.view.state, err);
13005
- });
13006
- }
13007
- scheduleAccept() {
13008
- if (this.running.every((q) => q.done !== void 0))
13009
- this.accept();
13010
- else if (this.debounceAccept < 0)
13011
- this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
13012
- }
13013
- // For each finished query in this.running, try to create a result
13014
- // or, if appropriate, restart the query.
13015
- accept() {
13016
- var _a2;
13017
- if (this.debounceAccept > -1)
13018
- clearTimeout(this.debounceAccept);
13019
- this.debounceAccept = -1;
13020
- let updated = [];
13021
- let conf = this.view.state.facet(completionConfig);
13022
- for (let i = 0; i < this.running.length; i++) {
13023
- let query = this.running[i];
13024
- if (query.done === void 0)
13025
- continue;
13026
- this.running.splice(i--, 1);
13027
- if (query.done) {
13028
- 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));
13029
- for (let tr of query.updates)
13030
- active = active.update(tr, conf);
13031
- if (active.hasResult()) {
13032
- updated.push(active);
13033
- continue;
13034
- }
13035
- }
13036
- let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
13037
- if (current && current.state == 1) {
13038
- if (query.done == null) {
13039
- let active = new ActiveSource(
13040
- query.active.source,
13041
- 0
13042
- /* State.Inactive */
13043
- );
13044
- for (let tr of query.updates)
13045
- active = active.update(tr, conf);
13046
- if (active.state != 1)
13047
- updated.push(active);
13048
- } else {
13049
- this.startQuery(current);
13050
- }
13051
- }
13052
- }
13053
- if (updated.length)
13054
- this.view.dispatch({ effects: setActiveEffect.of(updated) });
13055
- }
13056
- }, {
13057
- eventHandlers: {
13058
- blur(event) {
13059
- let state = this.view.state.field(completionState, false);
13060
- if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
13061
- let dialog = state.open && getTooltip(this.view, state.open.tooltip);
13062
- if (!dialog || !dialog.dom.contains(event.relatedTarget))
13063
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13064
- }
13065
- },
13066
- compositionstart() {
13067
- this.composing = 1;
13068
- },
13069
- compositionend() {
13070
- if (this.composing == 3) {
13071
- setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
13072
- }
13073
- this.composing = 0;
13074
- }
13075
- }
13076
- });
13077
- function applyCompletion(view, option) {
13078
- const apply = option.completion.apply || option.completion.label;
13079
- let result = view.state.field(completionState).active.find((a) => a.source == option.source);
13080
- if (!(result instanceof ActiveResult))
13081
- return false;
13082
- if (typeof apply == "string")
13083
- view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
13084
- else
13085
- apply(view, option.completion, result.from, result.to);
13086
- return true;
13087
- }
13088
12892
  function optionContent(config2) {
13089
12893
  let content = config2.addToOptions.slice();
13090
12894
  if (config2.icons)
@@ -13144,10 +12948,12 @@ function rangeAroundSelected(total, selected, max) {
13144
12948
  return { from: total - (off + 1) * max, to: total - off * max };
13145
12949
  }
13146
12950
  var CompletionTooltip = class {
13147
- constructor(view, stateField) {
12951
+ constructor(view, stateField, applyCompletion2) {
13148
12952
  this.view = view;
13149
12953
  this.stateField = stateField;
12954
+ this.applyCompletion = applyCompletion2;
13150
12955
  this.info = null;
12956
+ this.infoDestroy = null;
13151
12957
  this.placeInfoReq = {
13152
12958
  read: () => this.measureInfo(),
13153
12959
  write: (pos) => this.placeInfo(pos),
@@ -13168,7 +12974,7 @@ var CompletionTooltip = class {
13168
12974
  this.dom.addEventListener("mousedown", (e) => {
13169
12975
  for (let dom = e.target, match; dom && dom != this.dom; dom = dom.parentNode) {
13170
12976
  if (dom.nodeName == "LI" && (match = /-(\d+)$/.exec(dom.id)) && +match[1] < options.length) {
13171
- applyCompletion(view, options[+match[1]]);
12977
+ this.applyCompletion(view, options[+match[1]]);
13172
12978
  e.preventDefault();
13173
12979
  return;
13174
12980
  }
@@ -13228,10 +13034,7 @@ var CompletionTooltip = class {
13228
13034
  });
13229
13035
  }
13230
13036
  if (this.updateSelectedOption(open.selected)) {
13231
- if (this.info) {
13232
- this.info.remove();
13233
- this.info = null;
13234
- }
13037
+ this.destroyInfo();
13235
13038
  let { completion } = open.options[open.selected];
13236
13039
  let { info } = completion;
13237
13040
  if (!info)
@@ -13240,20 +13043,28 @@ var CompletionTooltip = class {
13240
13043
  if (!infoResult)
13241
13044
  return;
13242
13045
  if ("then" in infoResult) {
13243
- infoResult.then((node) => {
13244
- if (node && this.view.state.field(this.stateField, false) == cState)
13245
- this.addInfoPane(node);
13046
+ infoResult.then((obj) => {
13047
+ if (obj && this.view.state.field(this.stateField, false) == cState)
13048
+ this.addInfoPane(obj, completion);
13246
13049
  }).catch((e) => logException(this.view.state, e, "completion info"));
13247
13050
  } else {
13248
- this.addInfoPane(infoResult);
13051
+ this.addInfoPane(infoResult, completion);
13249
13052
  }
13250
13053
  }
13251
13054
  }
13252
- addInfoPane(content) {
13253
- let dom = this.info = document.createElement("div");
13254
- dom.className = "cm-tooltip cm-completionInfo";
13255
- dom.appendChild(content);
13256
- this.dom.appendChild(dom);
13055
+ addInfoPane(content, completion) {
13056
+ this.destroyInfo();
13057
+ let wrap = this.info = document.createElement("div");
13058
+ wrap.className = "cm-tooltip cm-completionInfo";
13059
+ if (content.nodeType != null) {
13060
+ wrap.appendChild(content);
13061
+ this.infoDestroy = null;
13062
+ } else {
13063
+ let { dom, destroy } = content;
13064
+ wrap.appendChild(dom);
13065
+ this.infoDestroy = destroy || null;
13066
+ }
13067
+ this.dom.appendChild(wrap);
13257
13068
  this.view.requestMeasure(this.placeInfoReq);
13258
13069
  }
13259
13070
  updateSelectedOption(selected) {
@@ -13341,9 +13152,20 @@ var CompletionTooltip = class {
13341
13152
  ul.classList.add("cm-completionListIncompleteBottom");
13342
13153
  return ul;
13343
13154
  }
13155
+ destroyInfo() {
13156
+ if (this.info) {
13157
+ if (this.infoDestroy)
13158
+ this.infoDestroy();
13159
+ this.info.remove();
13160
+ this.info = null;
13161
+ }
13162
+ }
13163
+ destroy() {
13164
+ this.destroyInfo();
13165
+ }
13344
13166
  };
13345
- function completionTooltip(stateField) {
13346
- return (view) => new CompletionTooltip(view, stateField);
13167
+ function completionTooltip(stateField, applyCompletion2) {
13168
+ return (view) => new CompletionTooltip(view, stateField, applyCompletion2);
13347
13169
  }
13348
13170
  function scrollIntoView2(container, element) {
13349
13171
  let parent = container.getBoundingClientRect();
@@ -13408,7 +13230,8 @@ function sortOptions(active, state) {
13408
13230
  let result = [], prev = null;
13409
13231
  let compare2 = state.facet(completionConfig).compareCompletions;
13410
13232
  for (let opt of options.sort((a, b) => b.score - a.score || compare2(a.completion, b.completion))) {
13411
- 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)
13233
+ let cur2 = opt.completion;
13234
+ 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)
13412
13235
  result.push(opt);
13413
13236
  else if (score(opt.completion) > score(prev))
13414
13237
  result[result.length - 1] = opt;
@@ -13433,7 +13256,7 @@ var CompletionDialog = class {
13433
13256
  if (!options.length) {
13434
13257
  return prev && active.some(
13435
13258
  (a) => a.state == 1
13436
- /* State.Pending */
13259
+ /* Pending */
13437
13260
  ) ? new CompletionDialog(prev.options, prev.attrs, prev.tooltip, prev.timestamp, prev.selected, true) : null;
13438
13261
  }
13439
13262
  let selected = state.facet(completionConfig).selectOnOpen ? 0 : -1;
@@ -13447,7 +13270,7 @@ var CompletionDialog = class {
13447
13270
  }
13448
13271
  return new CompletionDialog(options, makeAttrs(id, selected), {
13449
13272
  pos: active.reduce((a, b) => b.hasResult() ? Math.min(a, b.from) : a, 1e8),
13450
- create: completionTooltip(completionState),
13273
+ create: completionTooltip(completionState, applyCompletion),
13451
13274
  above: conf.aboveCursor
13452
13275
  }, prev ? prev.timestamp : Date.now(), selected, false);
13453
13276
  }
@@ -13472,9 +13295,9 @@ var CompletionState = class {
13472
13295
  source,
13473
13296
  this.active.some(
13474
13297
  (a) => a.state != 0
13475
- /* State.Inactive */
13298
+ /* Inactive */
13476
13299
  ) ? 1 : 0
13477
- /* State.Inactive */
13300
+ /* Inactive */
13478
13301
  );
13479
13302
  return value.update(tr, conf);
13480
13303
  });
@@ -13487,17 +13310,17 @@ var CompletionState = class {
13487
13310
  open = CompletionDialog.build(active, state, this.id, open, conf);
13488
13311
  else if (open && open.disabled && !active.some(
13489
13312
  (a) => a.state == 1
13490
- /* State.Pending */
13313
+ /* Pending */
13491
13314
  ))
13492
13315
  open = null;
13493
13316
  if (!open && active.every(
13494
13317
  (a) => a.state != 1
13495
- /* State.Pending */
13318
+ /* Pending */
13496
13319
  ) && active.some((a) => a.hasResult()))
13497
13320
  active = active.map((a) => a.hasResult() ? new ActiveSource(
13498
13321
  a.source,
13499
13322
  0
13500
- /* State.Inactive */
13323
+ /* Inactive */
13501
13324
  ) : a);
13502
13325
  for (let effect of tr.effects)
13503
13326
  if (effect.is(setSelectedEffect))
@@ -13562,7 +13385,7 @@ var ActiveSource = class {
13562
13385
  value = new ActiveSource(
13563
13386
  value.source,
13564
13387
  0
13565
- /* State.Inactive */
13388
+ /* Inactive */
13566
13389
  );
13567
13390
  for (let effect of tr.effects) {
13568
13391
  if (effect.is(startCompletionEffect))
@@ -13571,7 +13394,7 @@ var ActiveSource = class {
13571
13394
  value = new ActiveSource(
13572
13395
  value.source,
13573
13396
  0
13574
- /* State.Inactive */
13397
+ /* Inactive */
13575
13398
  );
13576
13399
  else if (effect.is(setActiveEffect)) {
13577
13400
  for (let active of effect.value)
@@ -13585,14 +13408,14 @@ var ActiveSource = class {
13585
13408
  return type == "delete" || !conf.activateOnTyping ? this.map(tr.changes) : new ActiveSource(
13586
13409
  this.source,
13587
13410
  1
13588
- /* State.Pending */
13411
+ /* Pending */
13589
13412
  );
13590
13413
  }
13591
13414
  handleChange(tr) {
13592
13415
  return tr.changes.touchesRange(cur(tr.startState)) ? new ActiveSource(
13593
13416
  this.source,
13594
13417
  0
13595
- /* State.Inactive */
13418
+ /* Inactive */
13596
13419
  ) : this.map(tr.changes);
13597
13420
  }
13598
13421
  map(changes) {
@@ -13617,7 +13440,7 @@ var ActiveResult = class extends ActiveSource {
13617
13440
  return new ActiveSource(
13618
13441
  this.source,
13619
13442
  type == "input" && conf.activateOnTyping ? 1 : 0
13620
- /* State.Inactive */
13443
+ /* Inactive */
13621
13444
  );
13622
13445
  let explicitPos = this.explicitPos < 0 ? -1 : tr.changes.mapPos(this.explicitPos), updated;
13623
13446
  if (checkValid(this.result.validFor, tr.state, from, to))
@@ -13630,7 +13453,7 @@ var ActiveResult = class extends ActiveSource {
13630
13453
  return tr.changes.touchesRange(this.from, this.to) ? new ActiveSource(
13631
13454
  this.source,
13632
13455
  0
13633
- /* State.Inactive */
13456
+ /* Inactive */
13634
13457
  ) : this.map(tr.changes);
13635
13458
  }
13636
13459
  map(mapping) {
@@ -13661,6 +13484,208 @@ var completionState = /* @__PURE__ */ StateField.define({
13661
13484
  EditorView.contentAttributes.from(f, (state) => state.attrs)
13662
13485
  ]
13663
13486
  });
13487
+ function applyCompletion(view, option) {
13488
+ const apply = option.completion.apply || option.completion.label;
13489
+ let result = view.state.field(completionState).active.find((a) => a.source == option.source);
13490
+ if (!(result instanceof ActiveResult))
13491
+ return false;
13492
+ if (typeof apply == "string")
13493
+ view.dispatch(Object.assign(Object.assign({}, insertCompletionText(view.state, apply, result.from, result.to)), { annotations: pickedCompletion.of(option.completion) }));
13494
+ else
13495
+ apply(view, option.completion, result.from, result.to);
13496
+ return true;
13497
+ }
13498
+ function moveCompletionSelection(forward, by = "option") {
13499
+ return (view) => {
13500
+ let cState = view.state.field(completionState, false);
13501
+ if (!cState || !cState.open || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
13502
+ return false;
13503
+ let step = 1, tooltip;
13504
+ if (by == "page" && (tooltip = getTooltip(view, cState.open.tooltip)))
13505
+ step = Math.max(2, Math.floor(tooltip.dom.offsetHeight / tooltip.dom.querySelector("li").offsetHeight) - 1);
13506
+ let { length: length2 } = cState.open.options;
13507
+ let selected = cState.open.selected > -1 ? cState.open.selected + step * (forward ? 1 : -1) : forward ? 0 : length2 - 1;
13508
+ if (selected < 0)
13509
+ selected = by == "page" ? 0 : length2 - 1;
13510
+ else if (selected >= length2)
13511
+ selected = by == "page" ? length2 - 1 : 0;
13512
+ view.dispatch({ effects: setSelectedEffect.of(selected) });
13513
+ return true;
13514
+ };
13515
+ }
13516
+ var acceptCompletion = (view) => {
13517
+ let cState = view.state.field(completionState, false);
13518
+ if (view.state.readOnly || !cState || !cState.open || cState.open.selected < 0 || cState.open.disabled || Date.now() - cState.open.timestamp < view.state.facet(completionConfig).interactionDelay)
13519
+ return false;
13520
+ return applyCompletion(view, cState.open.options[cState.open.selected]);
13521
+ };
13522
+ var startCompletion = (view) => {
13523
+ let cState = view.state.field(completionState, false);
13524
+ if (!cState)
13525
+ return false;
13526
+ view.dispatch({ effects: startCompletionEffect.of(true) });
13527
+ return true;
13528
+ };
13529
+ var closeCompletion = (view) => {
13530
+ let cState = view.state.field(completionState, false);
13531
+ if (!cState || !cState.active.some(
13532
+ (a) => a.state != 0
13533
+ /* Inactive */
13534
+ ))
13535
+ return false;
13536
+ view.dispatch({ effects: closeCompletionEffect.of(null) });
13537
+ return true;
13538
+ };
13539
+ var RunningQuery = class {
13540
+ constructor(active, context) {
13541
+ this.active = active;
13542
+ this.context = context;
13543
+ this.time = Date.now();
13544
+ this.updates = [];
13545
+ this.done = void 0;
13546
+ }
13547
+ };
13548
+ var DebounceTime = 50;
13549
+ var MaxUpdateCount = 50;
13550
+ var MinAbortTime = 1e3;
13551
+ var completionPlugin = /* @__PURE__ */ ViewPlugin.fromClass(class {
13552
+ constructor(view) {
13553
+ this.view = view;
13554
+ this.debounceUpdate = -1;
13555
+ this.running = [];
13556
+ this.debounceAccept = -1;
13557
+ this.composing = 0;
13558
+ for (let active of view.state.field(completionState).active)
13559
+ if (active.state == 1)
13560
+ this.startQuery(active);
13561
+ }
13562
+ update(update) {
13563
+ let cState = update.state.field(completionState);
13564
+ if (!update.selectionSet && !update.docChanged && update.startState.field(completionState) == cState)
13565
+ return;
13566
+ let doesReset = update.transactions.some((tr) => {
13567
+ return (tr.selection || tr.docChanged) && !getUserEvent(tr);
13568
+ });
13569
+ for (let i = 0; i < this.running.length; i++) {
13570
+ let query = this.running[i];
13571
+ if (doesReset || query.updates.length + update.transactions.length > MaxUpdateCount && Date.now() - query.time > MinAbortTime) {
13572
+ for (let handler of query.context.abortListeners) {
13573
+ try {
13574
+ handler();
13575
+ } catch (e) {
13576
+ logException(this.view.state, e);
13577
+ }
13578
+ }
13579
+ query.context.abortListeners = null;
13580
+ this.running.splice(i--, 1);
13581
+ } else {
13582
+ query.updates.push(...update.transactions);
13583
+ }
13584
+ }
13585
+ if (this.debounceUpdate > -1)
13586
+ clearTimeout(this.debounceUpdate);
13587
+ this.debounceUpdate = cState.active.some((a) => a.state == 1 && !this.running.some((q) => q.active.source == a.source)) ? setTimeout(() => this.startUpdate(), DebounceTime) : -1;
13588
+ if (this.composing != 0)
13589
+ for (let tr of update.transactions) {
13590
+ if (getUserEvent(tr) == "input")
13591
+ this.composing = 2;
13592
+ else if (this.composing == 2 && tr.selection)
13593
+ this.composing = 3;
13594
+ }
13595
+ }
13596
+ startUpdate() {
13597
+ this.debounceUpdate = -1;
13598
+ let { state } = this.view, cState = state.field(completionState);
13599
+ for (let active of cState.active) {
13600
+ if (active.state == 1 && !this.running.some((r) => r.active.source == active.source))
13601
+ this.startQuery(active);
13602
+ }
13603
+ }
13604
+ startQuery(active) {
13605
+ let { state } = this.view, pos = cur(state);
13606
+ let context = new CompletionContext(state, pos, active.explicitPos == pos);
13607
+ let pending = new RunningQuery(active, context);
13608
+ this.running.push(pending);
13609
+ Promise.resolve(active.source(context)).then((result) => {
13610
+ if (!pending.context.aborted) {
13611
+ pending.done = result || null;
13612
+ this.scheduleAccept();
13613
+ }
13614
+ }, (err) => {
13615
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13616
+ logException(this.view.state, err);
13617
+ });
13618
+ }
13619
+ scheduleAccept() {
13620
+ if (this.running.every((q) => q.done !== void 0))
13621
+ this.accept();
13622
+ else if (this.debounceAccept < 0)
13623
+ this.debounceAccept = setTimeout(() => this.accept(), DebounceTime);
13624
+ }
13625
+ // For each finished query in this.running, try to create a result
13626
+ // or, if appropriate, restart the query.
13627
+ accept() {
13628
+ var _a2;
13629
+ if (this.debounceAccept > -1)
13630
+ clearTimeout(this.debounceAccept);
13631
+ this.debounceAccept = -1;
13632
+ let updated = [];
13633
+ let conf = this.view.state.facet(completionConfig);
13634
+ for (let i = 0; i < this.running.length; i++) {
13635
+ let query = this.running[i];
13636
+ if (query.done === void 0)
13637
+ continue;
13638
+ this.running.splice(i--, 1);
13639
+ if (query.done) {
13640
+ 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));
13641
+ for (let tr of query.updates)
13642
+ active = active.update(tr, conf);
13643
+ if (active.hasResult()) {
13644
+ updated.push(active);
13645
+ continue;
13646
+ }
13647
+ }
13648
+ let current = this.view.state.field(completionState).active.find((a) => a.source == query.active.source);
13649
+ if (current && current.state == 1) {
13650
+ if (query.done == null) {
13651
+ let active = new ActiveSource(
13652
+ query.active.source,
13653
+ 0
13654
+ /* Inactive */
13655
+ );
13656
+ for (let tr of query.updates)
13657
+ active = active.update(tr, conf);
13658
+ if (active.state != 1)
13659
+ updated.push(active);
13660
+ } else {
13661
+ this.startQuery(current);
13662
+ }
13663
+ }
13664
+ }
13665
+ if (updated.length)
13666
+ this.view.dispatch({ effects: setActiveEffect.of(updated) });
13667
+ }
13668
+ }, {
13669
+ eventHandlers: {
13670
+ blur(event) {
13671
+ let state = this.view.state.field(completionState, false);
13672
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
13673
+ let dialog = state.open && getTooltip(this.view, state.open.tooltip);
13674
+ if (!dialog || !dialog.dom.contains(event.relatedTarget))
13675
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
13676
+ }
13677
+ },
13678
+ compositionstart() {
13679
+ this.composing = 1;
13680
+ },
13681
+ compositionend() {
13682
+ if (this.composing == 3) {
13683
+ setTimeout(() => this.view.dispatch({ effects: startCompletionEffect.of(false) }), 20);
13684
+ }
13685
+ this.composing = 0;
13686
+ }
13687
+ }
13688
+ });
13664
13689
  var baseTheme2 = /* @__PURE__ */ EditorView.baseTheme({
13665
13690
  ".cm-tooltip.cm-tooltip-autocomplete": {
13666
13691
  "& > ul": {
@@ -15028,7 +15053,7 @@ var defaultKeymap = /* @__PURE__ */ [
15028
15053
  ].concat(standardKeymap);
15029
15054
 
15030
15055
  // src/index.ts
15031
- import { SyntaxNode, Tree as Tree2 } from "@lezer/common";
15056
+ import { Tree as Tree2 } from "@lezer/common";
15032
15057
  import { styleTags as styleTags2, tags as tags2 } from "@lezer/highlight";
15033
15058
 
15034
15059
  // src/codemirror-basic-setup.ts
@@ -15411,7 +15436,6 @@ export {
15411
15436
  HighlightStyle,
15412
15437
  LRLanguage,
15413
15438
  LanguageSupport,
15414
- SyntaxNode,
15415
15439
  Tree2 as Tree,
15416
15440
  asNameSuggestion,
15417
15441
  autocompletion,