@codemirror/autocomplete 6.5.0 → 6.5.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 6.5.1 (2023-04-13)
2
+
3
+ ### Bug fixes
4
+
5
+ Keep completions open when interaction with an info tooltip moves focus out of the editor.
6
+
1
7
  ## 6.5.0 (2023-04-13)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -194,6 +194,8 @@ function asSource(source) {
194
194
  SourceCache.set(source, known = completeFromList(source));
195
195
  return known;
196
196
  }
197
+ const startCompletionEffect = state.StateEffect.define();
198
+ const closeCompletionEffect = state.StateEffect.define();
197
199
 
198
200
  // A pattern matcher for fuzzy completion matching. Create an instance
199
201
  // once for a pattern, and then use that to match any number of
@@ -475,6 +477,12 @@ class CompletionTooltip {
475
477
  }
476
478
  }
477
479
  });
480
+ this.dom.addEventListener("focusout", (e) => {
481
+ let state = view.state.field(this.stateField, false);
482
+ if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur &&
483
+ e.relatedTarget != view.contentDOM)
484
+ view.dispatch({ effects: closeCompletionEffect.of(null) });
485
+ });
478
486
  this.list = this.dom.appendChild(this.createListBox(options, cState.id, this.range));
479
487
  this.list.addEventListener("scroll", () => {
480
488
  if (this.info)
@@ -905,8 +913,6 @@ function checkValid(validFor, state, from, to) {
905
913
  let text = state.sliceDoc(from, to);
906
914
  return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text);
907
915
  }
908
- const startCompletionEffect = state.StateEffect.define();
909
- const closeCompletionEffect = state.StateEffect.define();
910
916
  const setActiveEffect = state.StateEffect.define({
911
917
  map(sources, mapping) { return sources.map(s => s.map(mapping)); }
912
918
  });
@@ -1113,10 +1119,13 @@ const completionPlugin = view.ViewPlugin.fromClass(class {
1113
1119
  }
1114
1120
  }, {
1115
1121
  eventHandlers: {
1116
- blur() {
1122
+ blur(event) {
1117
1123
  let state = this.view.state.field(completionState, false);
1118
- if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur)
1119
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
1124
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
1125
+ let dialog = state.open && view.getTooltip(this.view, state.open.tooltip);
1126
+ if (!dialog || !dialog.dom.contains(event.relatedTarget))
1127
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
1128
+ }
1120
1129
  },
1121
1130
  compositionstart() {
1122
1131
  this.composing = 1 /* CompositionState.Started */;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Annotation, EditorSelection, codePointAt, codePointSize, fromCodePoint, Facet, combineConfig, StateEffect, StateField, Prec, Text, MapMode, RangeValue, RangeSet, CharCategory } from '@codemirror/state';
1
+ import { Annotation, StateEffect, EditorSelection, codePointAt, codePointSize, fromCodePoint, Facet, combineConfig, StateField, Prec, Text, MapMode, RangeValue, RangeSet, CharCategory } from '@codemirror/state';
2
2
  import { Direction, logException, showTooltip, EditorView, ViewPlugin, getTooltip, Decoration, WidgetType, keymap } from '@codemirror/view';
3
3
  import { syntaxTree, indentUnit } from '@codemirror/language';
4
4
 
@@ -190,6 +190,8 @@ function asSource(source) {
190
190
  SourceCache.set(source, known = completeFromList(source));
191
191
  return known;
192
192
  }
193
+ const startCompletionEffect = /*@__PURE__*/StateEffect.define();
194
+ const closeCompletionEffect = /*@__PURE__*/StateEffect.define();
193
195
 
194
196
  // A pattern matcher for fuzzy completion matching. Create an instance
195
197
  // once for a pattern, and then use that to match any number of
@@ -471,6 +473,12 @@ class CompletionTooltip {
471
473
  }
472
474
  }
473
475
  });
476
+ this.dom.addEventListener("focusout", (e) => {
477
+ let state = view.state.field(this.stateField, false);
478
+ if (state && state.tooltip && view.state.facet(completionConfig).closeOnBlur &&
479
+ e.relatedTarget != view.contentDOM)
480
+ view.dispatch({ effects: closeCompletionEffect.of(null) });
481
+ });
474
482
  this.list = this.dom.appendChild(this.createListBox(options, cState.id, this.range));
475
483
  this.list.addEventListener("scroll", () => {
476
484
  if (this.info)
@@ -901,8 +909,6 @@ function checkValid(validFor, state, from, to) {
901
909
  let text = state.sliceDoc(from, to);
902
910
  return typeof validFor == "function" ? validFor(text, from, to, state) : ensureAnchor(validFor, true).test(text);
903
911
  }
904
- const startCompletionEffect = /*@__PURE__*/StateEffect.define();
905
- const closeCompletionEffect = /*@__PURE__*/StateEffect.define();
906
912
  const setActiveEffect = /*@__PURE__*/StateEffect.define({
907
913
  map(sources, mapping) { return sources.map(s => s.map(mapping)); }
908
914
  });
@@ -1109,10 +1115,13 @@ const completionPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
1109
1115
  }
1110
1116
  }, {
1111
1117
  eventHandlers: {
1112
- blur() {
1118
+ blur(event) {
1113
1119
  let state = this.view.state.field(completionState, false);
1114
- if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur)
1115
- this.view.dispatch({ effects: closeCompletionEffect.of(null) });
1120
+ if (state && state.tooltip && this.view.state.facet(completionConfig).closeOnBlur) {
1121
+ let dialog = state.open && getTooltip(this.view, state.open.tooltip);
1122
+ if (!dialog || !dialog.dom.contains(event.relatedTarget))
1123
+ this.view.dispatch({ effects: closeCompletionEffect.of(null) });
1124
+ }
1116
1125
  },
1117
1126
  compositionstart() {
1118
1127
  this.composing = 1 /* CompositionState.Started */;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/autocomplete",
3
- "version": "6.5.0",
3
+ "version": "6.5.1",
4
4
  "description": "Autocompletion for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",