@bastani/atomic-tui 0.9.89 → 0.9.90

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.
Files changed (44) hide show
  1. package/dist/builtin-command-names.d.ts +4 -0
  2. package/dist/builtin-command-names.d.ts.map +1 -0
  3. package/dist/builtin-command-names.js +42 -0
  4. package/dist/builtin-command-names.js.map +1 -0
  5. package/dist/clickable-hints.d.ts +84 -0
  6. package/dist/clickable-hints.d.ts.map +1 -0
  7. package/dist/clickable-hints.js +267 -0
  8. package/dist/clickable-hints.js.map +1 -0
  9. package/dist/components/editor.d.ts +7 -1
  10. package/dist/components/editor.d.ts.map +1 -1
  11. package/dist/components/editor.js +63 -25
  12. package/dist/components/editor.js.map +1 -1
  13. package/dist/components/settings-list.d.ts.map +1 -1
  14. package/dist/components/settings-list.js +3 -2
  15. package/dist/components/settings-list.js.map +1 -1
  16. package/dist/components/windowed-container.d.ts +2 -0
  17. package/dist/components/windowed-container.d.ts.map +1 -1
  18. package/dist/components/windowed-container.js +4 -0
  19. package/dist/components/windowed-container.js.map +1 -1
  20. package/dist/index.d.ts +3 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +4 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/keys.d.ts +5 -0
  25. package/dist/keys.d.ts.map +1 -1
  26. package/dist/keys.js +115 -0
  27. package/dist/keys.js.map +1 -1
  28. package/dist/terminal.d.ts +3 -0
  29. package/dist/terminal.d.ts.map +1 -1
  30. package/dist/terminal.js +16 -0
  31. package/dist/terminal.js.map +1 -1
  32. package/dist/tui-alt-screen.d.ts +24 -3
  33. package/dist/tui-alt-screen.d.ts.map +1 -1
  34. package/dist/tui-alt-screen.js +205 -58
  35. package/dist/tui-alt-screen.js.map +1 -1
  36. package/dist/tui.d.ts +23 -0
  37. package/dist/tui.d.ts.map +1 -1
  38. package/dist/tui.js +48 -5
  39. package/dist/tui.js.map +1 -1
  40. package/dist/utils.d.ts +4 -0
  41. package/dist/utils.d.ts.map +1 -1
  42. package/dist/utils.js +79 -11
  43. package/dist/utils.js.map +1 -1
  44. package/package.json +1 -1
@@ -258,10 +258,13 @@ export class Editor {
258
258
  autocompletePrefix = "";
259
259
  autocompleteCompleteOnConfirm = true;
260
260
  autocompleteSelectionMoved = false;
261
+ menuProvider;
261
262
  autocompleteMaxVisible = 5;
262
263
  autocompleteAbort;
263
264
  autocompleteDebounceTimer;
264
265
  autocompleteRequestTask = Promise.resolve();
266
+ pendingAutocomplete;
267
+ emptyAutocomplete;
265
268
  autocompleteStartToken = 0;
266
269
  autocompleteRequestId = 0;
267
270
  // Paste tracking for large pastes
@@ -329,10 +332,25 @@ export class Editor {
329
332
  this.tui.requestRender();
330
333
  }
331
334
  }
332
- setAutocompleteProvider(provider) {
333
- this.cancelAutocomplete();
335
+ setAutocompleteProvider(provider, options) {
336
+ // A painted menu owns its rows and the provider that offered them. If no menu has opened yet, a still-current
337
+ // lookup (including an empty result) can open one using the newly available commands and the original Tab intent.
338
+ const empty = this.emptyAutocomplete;
339
+ const retry = options?.preserveSelection &&
340
+ !this.autocompleteState &&
341
+ (this.pendingAutocomplete ??
342
+ (empty &&
343
+ empty.line === this.state.cursorLine &&
344
+ empty.col === this.state.cursorCol &&
345
+ empty.text === this.getText()
346
+ ? empty.options
347
+ : undefined));
348
+ if (!options?.preserveSelection)
349
+ this.cancelAutocomplete();
334
350
  this.autocompleteProvider = provider;
335
351
  this.setAutocompleteTriggerCharacters(provider.triggerCharacters ?? []);
352
+ if (retry)
353
+ this.requestAutocomplete({ ...retry, catalogRetry: true });
336
354
  }
337
355
  renderAutocompleteHint(width) {
338
356
  const render = this.theme.autocompleteHint;
@@ -615,6 +633,8 @@ export class Editor {
615
633
  }
616
634
  handleInput(data) {
617
635
  const kb = getKeybindings();
636
+ if (!this.autocompleteState && kb.matches(data, "tui.select.cancel"))
637
+ this.dismissEmptyAutocomplete();
618
638
  // Handle character jump mode (awaiting next character to jump to)
619
639
  if (this.jumpMode !== null) {
620
640
  // Cancel if the hotkey is pressed again
@@ -682,10 +702,10 @@ export class Editor {
682
702
  }
683
703
  if (kb.matches(data, "tui.input.tab")) {
684
704
  const selected = this.autocompleteList.getSelectedItem();
685
- if (selected && this.autocompleteProvider) {
705
+ if (selected && this.menuProvider) {
686
706
  this.pushUndoSnapshot();
687
707
  this.lastAction = null;
688
- const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
708
+ const result = this.menuProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
689
709
  this.state.lines = result.lines;
690
710
  this.state.cursorLine = result.cursorLine;
691
711
  this.setCursorCol(result.cursorCol);
@@ -703,10 +723,10 @@ export class Editor {
703
723
  }
704
724
  else {
705
725
  const selected = this.autocompleteList.getSelectedItem();
706
- if (selected && this.autocompleteProvider) {
726
+ if (selected && this.menuProvider) {
707
727
  this.pushUndoSnapshot();
708
728
  this.lastAction = null;
709
- const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
729
+ const result = this.menuProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
710
730
  this.state.lines = result.lines;
711
731
  this.state.cursorLine = result.cursorLine;
712
732
  this.setCursorCol(result.cursorCol);
@@ -1956,11 +1976,11 @@ export class Editor {
1956
1976
  const layout = prefix.startsWith("/") ? SLASH_COMMAND_SELECT_LIST_LAYOUT : undefined;
1957
1977
  const list = new SelectList(items, this.autocompleteMaxVisible, this.theme.selectList, layout);
1958
1978
  list.onSelect = (selected) => {
1959
- if (!this.autocompleteProvider)
1979
+ if (!this.menuProvider)
1960
1980
  return;
1961
1981
  this.pushUndoSnapshot();
1962
1982
  this.lastAction = null;
1963
- const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
1983
+ const result = this.menuProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
1964
1984
  this.state.lines = result.lines;
1965
1985
  this.state.cursorLine = result.cursorLine;
1966
1986
  this.setCursorCol(result.cursorCol);
@@ -1991,28 +2011,30 @@ export class Editor {
1991
2011
  this.requestAutocomplete({ force: true, explicitTab });
1992
2012
  }
1993
2013
  requestAutocomplete(options) {
1994
- if (!this.autocompleteProvider)
2014
+ const provider = this.autocompleteProvider;
2015
+ if (!provider)
1995
2016
  return;
1996
2017
  if (options.force) {
1997
- const shouldTrigger = !this.autocompleteProvider.shouldTriggerFileCompletion ||
1998
- this.autocompleteProvider.shouldTriggerFileCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol);
2018
+ const shouldTrigger = !provider.shouldTriggerFileCompletion ||
2019
+ provider.shouldTriggerFileCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol);
1999
2020
  if (!shouldTrigger) {
2000
2021
  return;
2001
2022
  }
2002
2023
  }
2003
2024
  this.cancelAutocompleteRequest();
2025
+ this.pendingAutocomplete = options;
2004
2026
  const startToken = ++this.autocompleteStartToken;
2005
2027
  const debounceMs = this.getAutocompleteDebounceMs(options);
2006
2028
  if (debounceMs > 0) {
2007
2029
  this.autocompleteDebounceTimer = setTimeout(() => {
2008
2030
  this.autocompleteDebounceTimer = undefined;
2009
- void this.startAutocompleteRequest(startToken, options);
2031
+ void this.startAutocompleteRequest(startToken, options, provider);
2010
2032
  }, debounceMs);
2011
2033
  return;
2012
2034
  }
2013
- void this.startAutocompleteRequest(startToken, options);
2035
+ void this.startAutocompleteRequest(startToken, options, provider);
2014
2036
  }
2015
- async startAutocompleteRequest(startToken, options) {
2037
+ async startAutocompleteRequest(startToken, options, provider) {
2016
2038
  const previousTask = this.autocompleteRequestTask;
2017
2039
  this.autocompleteRequestTask = (async () => {
2018
2040
  await previousTask;
@@ -2025,7 +2047,13 @@ export class Editor {
2025
2047
  const snapshotText = this.getText();
2026
2048
  const snapshotLine = this.state.cursorLine;
2027
2049
  const snapshotCol = this.state.cursorCol;
2028
- await this.runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options);
2050
+ try {
2051
+ await this.runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options, provider);
2052
+ }
2053
+ finally {
2054
+ if (startToken === this.autocompleteStartToken)
2055
+ this.pendingAutocomplete = undefined;
2056
+ }
2029
2057
  })();
2030
2058
  await this.autocompleteRequestTask;
2031
2059
  }
@@ -2049,16 +2077,18 @@ export class Editor {
2049
2077
  const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
2050
2078
  return this.autocompleteDebouncePattern.test(textBeforeCursor) ? ATTACHMENT_AUTOCOMPLETE_DEBOUNCE_MS : 0;
2051
2079
  }
2052
- async runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options) {
2053
- if (!this.autocompleteProvider)
2054
- return;
2055
- const suggestions = await this.autocompleteProvider.getSuggestions(this.state.lines, this.state.cursorLine, this.state.cursorCol, { signal: controller.signal, force: options.force });
2080
+ async runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options, provider) {
2081
+ const suggestions = await provider.getSuggestions(this.state.lines, this.state.cursorLine, this.state.cursorCol, {
2082
+ signal: controller.signal,
2083
+ force: options.force,
2084
+ });
2056
2085
  if (!this.isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol)) {
2057
2086
  return;
2058
2087
  }
2059
2088
  this.autocompleteAbort = undefined;
2060
2089
  if (!suggestions || !Array.isArray(suggestions.items) || suggestions.items.length === 0) {
2061
2090
  this.cancelAutocomplete();
2091
+ this.emptyAutocomplete = { text: snapshotText, line: snapshotLine, col: snapshotCol, options };
2062
2092
  this.tui.requestRender();
2063
2093
  return;
2064
2094
  }
@@ -2066,7 +2096,7 @@ export class Editor {
2066
2096
  const item = suggestions.items[0];
2067
2097
  this.pushUndoSnapshot();
2068
2098
  this.lastAction = null;
2069
- const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, item, suggestions.prefix);
2099
+ const result = provider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, item, suggestions.prefix);
2070
2100
  this.state.lines = result.lines;
2071
2101
  this.state.cursorLine = result.cursorLine;
2072
2102
  this.setCursorCol(result.cursorCol);
@@ -2075,7 +2105,8 @@ export class Editor {
2075
2105
  this.tui.requestRender();
2076
2106
  return;
2077
2107
  }
2078
- this.applyAutocompleteSuggestions(suggestions, options.force ? "force" : "regular");
2108
+ this.menuProvider = provider;
2109
+ this.applyAutocompleteSuggestions(suggestions, options);
2079
2110
  this.tui.requestRender();
2080
2111
  }
2081
2112
  isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol) {
@@ -2085,18 +2116,24 @@ export class Editor {
2085
2116
  this.state.cursorLine === snapshotLine &&
2086
2117
  this.state.cursorCol === snapshotCol);
2087
2118
  }
2088
- applyAutocompleteSuggestions(suggestions, state) {
2119
+ applyAutocompleteSuggestions(suggestions, options) {
2089
2120
  this.autocompletePrefix = suggestions.prefix;
2090
2121
  this.autocompleteCompleteOnConfirm = suggestions.completeOnConfirm !== false;
2091
2122
  this.autocompleteSelectionMoved = false;
2092
2123
  this.autocompleteList = this.createAutocompleteList(suggestions.prefix, suggestions.items);
2093
2124
  const bestMatchIndex = this.getBestAutocompleteMatchIndex(suggestions.items, suggestions.prefix);
2094
- if (bestMatchIndex >= 0) {
2125
+ if (bestMatchIndex >= 0)
2095
2126
  this.autocompleteList.setSelectedIndex(bestMatchIndex);
2096
- }
2097
- this.autocompleteState = state;
2127
+ this.autocompleteState = options.force ? "force" : "regular";
2128
+ }
2129
+ dismissEmptyAutocomplete() {
2130
+ this.emptyAutocomplete = undefined;
2131
+ if (this.pendingAutocomplete?.catalogRetry && !this.autocompleteState)
2132
+ this.cancelAutocompleteRequest();
2098
2133
  }
2099
2134
  cancelAutocompleteRequest() {
2135
+ this.emptyAutocomplete = undefined;
2136
+ this.pendingAutocomplete = undefined;
2100
2137
  this.autocompleteStartToken += 1;
2101
2138
  if (this.autocompleteDebounceTimer) {
2102
2139
  clearTimeout(this.autocompleteDebounceTimer);
@@ -2111,6 +2148,7 @@ export class Editor {
2111
2148
  this.autocompletePrefix = "";
2112
2149
  this.autocompleteCompleteOnConfirm = true;
2113
2150
  this.autocompleteSelectionMoved = false;
2151
+ this.menuProvider = undefined;
2114
2152
  }
2115
2153
  cancelAutocomplete() {
2116
2154
  this.cancelAutocompleteRequest();