@schovest/pi-tui 0.7.3

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 (114) hide show
  1. package/README.md +791 -0
  2. package/dist/autocomplete.d.ts +57 -0
  3. package/dist/autocomplete.d.ts.map +1 -0
  4. package/dist/autocomplete.js +646 -0
  5. package/dist/autocomplete.js.map +1 -0
  6. package/dist/components/box.d.ts +22 -0
  7. package/dist/components/box.d.ts.map +1 -0
  8. package/dist/components/box.js +104 -0
  9. package/dist/components/box.js.map +1 -0
  10. package/dist/components/cancellable-loader.d.ts +22 -0
  11. package/dist/components/cancellable-loader.d.ts.map +1 -0
  12. package/dist/components/cancellable-loader.js +35 -0
  13. package/dist/components/cancellable-loader.js.map +1 -0
  14. package/dist/components/editor.d.ts +254 -0
  15. package/dist/components/editor.d.ts.map +1 -0
  16. package/dist/components/editor.js +1916 -0
  17. package/dist/components/editor.js.map +1 -0
  18. package/dist/components/image.d.ts +28 -0
  19. package/dist/components/image.d.ts.map +1 -0
  20. package/dist/components/image.js +89 -0
  21. package/dist/components/image.js.map +1 -0
  22. package/dist/components/input.d.ts +37 -0
  23. package/dist/components/input.d.ts.map +1 -0
  24. package/dist/components/input.js +385 -0
  25. package/dist/components/input.js.map +1 -0
  26. package/dist/components/loader.d.ts +31 -0
  27. package/dist/components/loader.d.ts.map +1 -0
  28. package/dist/components/loader.js +69 -0
  29. package/dist/components/loader.js.map +1 -0
  30. package/dist/components/markdown.d.ts +96 -0
  31. package/dist/components/markdown.d.ts.map +1 -0
  32. package/dist/components/markdown.js +648 -0
  33. package/dist/components/markdown.js.map +1 -0
  34. package/dist/components/select-list.d.ts +50 -0
  35. package/dist/components/select-list.d.ts.map +1 -0
  36. package/dist/components/select-list.js +161 -0
  37. package/dist/components/select-list.js.map +1 -0
  38. package/dist/components/settings-list.d.ts +50 -0
  39. package/dist/components/settings-list.d.ts.map +1 -0
  40. package/dist/components/settings-list.js +186 -0
  41. package/dist/components/settings-list.js.map +1 -0
  42. package/dist/components/spacer.d.ts +12 -0
  43. package/dist/components/spacer.d.ts.map +1 -0
  44. package/dist/components/spacer.js +23 -0
  45. package/dist/components/spacer.js.map +1 -0
  46. package/dist/components/text.d.ts +19 -0
  47. package/dist/components/text.d.ts.map +1 -0
  48. package/dist/components/text.js +89 -0
  49. package/dist/components/text.js.map +1 -0
  50. package/dist/components/truncated-text.d.ts +13 -0
  51. package/dist/components/truncated-text.d.ts.map +1 -0
  52. package/dist/components/truncated-text.js +51 -0
  53. package/dist/components/truncated-text.js.map +1 -0
  54. package/dist/editor-component.d.ts +39 -0
  55. package/dist/editor-component.d.ts.map +1 -0
  56. package/dist/editor-component.js +2 -0
  57. package/dist/editor-component.js.map +1 -0
  58. package/dist/fuzzy.d.ts +16 -0
  59. package/dist/fuzzy.d.ts.map +1 -0
  60. package/dist/fuzzy.js +110 -0
  61. package/dist/fuzzy.js.map +1 -0
  62. package/dist/index.d.ts +23 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +32 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/keybindings.d.ts +193 -0
  67. package/dist/keybindings.d.ts.map +1 -0
  68. package/dist/keybindings.js +174 -0
  69. package/dist/keybindings.js.map +1 -0
  70. package/dist/keys.d.ts +184 -0
  71. package/dist/keys.d.ts.map +1 -0
  72. package/dist/keys.js +1181 -0
  73. package/dist/keys.js.map +1 -0
  74. package/dist/kill-ring.d.ts +28 -0
  75. package/dist/kill-ring.d.ts.map +1 -0
  76. package/dist/kill-ring.js +44 -0
  77. package/dist/kill-ring.js.map +1 -0
  78. package/dist/native-modifiers.d.ts +3 -0
  79. package/dist/native-modifiers.d.ts.map +1 -0
  80. package/dist/native-modifiers.js +53 -0
  81. package/dist/native-modifiers.js.map +1 -0
  82. package/dist/stdin-buffer.d.ts +60 -0
  83. package/dist/stdin-buffer.d.ts.map +1 -0
  84. package/dist/stdin-buffer.js +406 -0
  85. package/dist/stdin-buffer.js.map +1 -0
  86. package/dist/terminal-image.d.ts +90 -0
  87. package/dist/terminal-image.d.ts.map +1 -0
  88. package/dist/terminal-image.js +366 -0
  89. package/dist/terminal-image.js.map +1 -0
  90. package/dist/terminal.d.ts +121 -0
  91. package/dist/terminal.d.ts.map +1 -0
  92. package/dist/terminal.js +464 -0
  93. package/dist/terminal.js.map +1 -0
  94. package/dist/tui.d.ts +347 -0
  95. package/dist/tui.d.ts.map +1 -0
  96. package/dist/tui.js +1608 -0
  97. package/dist/tui.js.map +1 -0
  98. package/dist/undo-stack.d.ts +17 -0
  99. package/dist/undo-stack.d.ts.map +1 -0
  100. package/dist/undo-stack.js +25 -0
  101. package/dist/undo-stack.js.map +1 -0
  102. package/dist/utils.d.ts +101 -0
  103. package/dist/utils.d.ts.map +1 -0
  104. package/dist/utils.js +1108 -0
  105. package/dist/utils.js.map +1 -0
  106. package/dist/word-navigation.d.ts +25 -0
  107. package/dist/word-navigation.d.ts.map +1 -0
  108. package/dist/word-navigation.js +96 -0
  109. package/dist/word-navigation.js.map +1 -0
  110. package/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  111. package/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  112. package/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  113. package/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  114. package/package.json +47 -0
@@ -0,0 +1,1916 @@
1
+ import { getKeybindings } from "../keybindings.js";
2
+ import { decodePrintableKey, matchesKey } from "../keys.js";
3
+ import { KillRing } from "../kill-ring.js";
4
+ import { CURSOR_MARKER } from "../tui.js";
5
+ import { UndoStack } from "../undo-stack.js";
6
+ import { cjkBreakRegex, getGraphemeSegmenter, getWordSegmenter, isWhitespaceChar, truncateToWidth, visibleWidth, } from "../utils.js";
7
+ import { findWordBackward, findWordForward } from "../word-navigation.js";
8
+ import { SelectList } from "./select-list.js";
9
+ const graphemeSegmenter = getGraphemeSegmenter();
10
+ const wordSegmenter = getWordSegmenter();
11
+ /** Regex matching paste markers like `[paste #1 +123 lines]` or `[paste #2 1234 chars]`. */
12
+ const PASTE_MARKER_REGEX = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
13
+ /** Non-global version for single-segment testing. */
14
+ const PASTE_MARKER_SINGLE = /^\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]$/;
15
+ /** Check if a segment is a paste marker (i.e. was merged by segmentWithMarkers). */
16
+ function isPasteMarker(segment) {
17
+ return segment.length >= 10 && PASTE_MARKER_SINGLE.test(segment);
18
+ }
19
+ /**
20
+ * A segmenter that wraps Intl.Segmenter and merges graphemes that fall
21
+ * within paste markers into single atomic segments. This makes cursor
22
+ * movement, deletion, word-wrap, etc. treat paste markers as single units.
23
+ *
24
+ * Only markers whose numeric ID exists in `validIds` are merged.
25
+ */
26
+ function segmentWithMarkers(text, baseSegmenter, validIds) {
27
+ // Fast path: no paste markers in the text or no valid IDs.
28
+ if (validIds.size === 0 || !text.includes("[paste #")) {
29
+ return baseSegmenter.segment(text);
30
+ }
31
+ // Find all marker spans with valid IDs.
32
+ const markers = [];
33
+ for (const m of text.matchAll(PASTE_MARKER_REGEX)) {
34
+ const id = Number.parseInt(m[1], 10);
35
+ if (!validIds.has(id))
36
+ continue;
37
+ markers.push({ start: m.index, end: m.index + m[0].length });
38
+ }
39
+ if (markers.length === 0) {
40
+ return baseSegmenter.segment(text);
41
+ }
42
+ // Build merged segment list.
43
+ const baseSegments = baseSegmenter.segment(text);
44
+ const result = [];
45
+ let markerIdx = 0;
46
+ for (const seg of baseSegments) {
47
+ // Skip past markers that are entirely before this segment.
48
+ while (markerIdx < markers.length && markers[markerIdx].end <= seg.index) {
49
+ markerIdx++;
50
+ }
51
+ const marker = markerIdx < markers.length ? markers[markerIdx] : null;
52
+ if (marker && seg.index >= marker.start && seg.index < marker.end) {
53
+ // This segment falls inside a marker.
54
+ // If this is the first segment of the marker, emit a merged segment.
55
+ if (seg.index === marker.start) {
56
+ const markerText = text.slice(marker.start, marker.end);
57
+ result.push({
58
+ segment: markerText,
59
+ index: marker.start,
60
+ input: text,
61
+ });
62
+ }
63
+ // Otherwise skip (already merged into the first segment).
64
+ }
65
+ else {
66
+ result.push(seg);
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+ /**
72
+ * Split a line into word-wrapped chunks.
73
+ * Wraps at word boundaries when possible, falling back to character-level
74
+ * wrapping for words longer than the available width.
75
+ *
76
+ * @param line - The text line to wrap
77
+ * @param maxWidth - Maximum visible width per chunk
78
+ * @param preSegmented - Optional pre-segmented graphemes (e.g. with paste-marker awareness).
79
+ * When omitted the default Intl.Segmenter is used.
80
+ * @returns Array of chunks with text and position information
81
+ */
82
+ export function wordWrapLine(line, maxWidth, preSegmented) {
83
+ if (!line || maxWidth <= 0) {
84
+ return [{ text: "", startIndex: 0, endIndex: 0 }];
85
+ }
86
+ const lineWidth = visibleWidth(line);
87
+ if (lineWidth <= maxWidth) {
88
+ return [{ text: line, startIndex: 0, endIndex: line.length }];
89
+ }
90
+ const chunks = [];
91
+ const segments = preSegmented ?? [...graphemeSegmenter.segment(line)];
92
+ let currentWidth = 0;
93
+ let chunkStart = 0;
94
+ // Wrap opportunity: the position after the last whitespace before a non-whitespace
95
+ // grapheme, i.e. where a line break is allowed.
96
+ let wrapOppIndex = -1;
97
+ let wrapOppWidth = 0;
98
+ for (let i = 0; i < segments.length; i++) {
99
+ const seg = segments[i];
100
+ const grapheme = seg.segment;
101
+ const gWidth = visibleWidth(grapheme);
102
+ const charIndex = seg.index;
103
+ const isWs = !isPasteMarker(grapheme) && isWhitespaceChar(grapheme);
104
+ // Overflow check before advancing.
105
+ if (currentWidth + gWidth > maxWidth) {
106
+ if (wrapOppIndex >= 0 && currentWidth - wrapOppWidth + gWidth <= maxWidth) {
107
+ // Backtrack to last wrap opportunity (the remaining content
108
+ // plus the current grapheme still fits within maxWidth).
109
+ chunks.push({ text: line.slice(chunkStart, wrapOppIndex), startIndex: chunkStart, endIndex: wrapOppIndex });
110
+ chunkStart = wrapOppIndex;
111
+ currentWidth -= wrapOppWidth;
112
+ }
113
+ else if (chunkStart < charIndex) {
114
+ // No viable wrap opportunity: force-break at current position.
115
+ // This also handles the case where backtracking to a word
116
+ // boundary wouldn't help because the remaining content plus
117
+ // the current grapheme (e.g. a wide character) still exceeds
118
+ // maxWidth.
119
+ chunks.push({ text: line.slice(chunkStart, charIndex), startIndex: chunkStart, endIndex: charIndex });
120
+ chunkStart = charIndex;
121
+ currentWidth = 0;
122
+ }
123
+ wrapOppIndex = -1;
124
+ }
125
+ if (gWidth > maxWidth) {
126
+ // Single atomic segment wider than maxWidth (e.g. paste marker
127
+ // in a narrow terminal). Re-wrap it at grapheme granularity.
128
+ // The segment remains logically atomic for cursor
129
+ // movement / editing — the split is purely visual for word-wrap layout.
130
+ const subChunks = wordWrapLine(grapheme, maxWidth);
131
+ for (let j = 0; j < subChunks.length - 1; j++) {
132
+ const sc = subChunks[j];
133
+ chunks.push({ text: sc.text, startIndex: charIndex + sc.startIndex, endIndex: charIndex + sc.endIndex });
134
+ }
135
+ const last = subChunks[subChunks.length - 1];
136
+ chunkStart = charIndex + last.startIndex;
137
+ currentWidth = visibleWidth(last.text);
138
+ wrapOppIndex = -1;
139
+ continue;
140
+ }
141
+ // Advance.
142
+ currentWidth += gWidth;
143
+ // Record wrap opportunity: whitespace followed by non-whitespace
144
+ // (multiple spaces join; the break point is after the last space),
145
+ // or at a boundary where either side is CJK (CJK allows breaking
146
+ // between any adjacent characters).
147
+ const next = segments[i + 1];
148
+ if (isWs && next && (isPasteMarker(next.segment) || !isWhitespaceChar(next.segment))) {
149
+ wrapOppIndex = next.index;
150
+ wrapOppWidth = currentWidth;
151
+ }
152
+ else if (!isWs && next && !isWhitespaceChar(next.segment)) {
153
+ const isCjk = !isPasteMarker(grapheme) && cjkBreakRegex.test(grapheme);
154
+ const nextIsCjk = !isPasteMarker(next.segment) && cjkBreakRegex.test(next.segment);
155
+ if (isCjk || nextIsCjk) {
156
+ wrapOppIndex = next.index;
157
+ wrapOppWidth = currentWidth;
158
+ }
159
+ }
160
+ }
161
+ // Push final chunk.
162
+ chunks.push({ text: line.slice(chunkStart), startIndex: chunkStart, endIndex: line.length });
163
+ return chunks;
164
+ }
165
+ const SLASH_COMMAND_SELECT_LIST_LAYOUT = {
166
+ minPrimaryColumnWidth: 12,
167
+ maxPrimaryColumnWidth: 32,
168
+ };
169
+ const ATTACHMENT_AUTOCOMPLETE_DEBOUNCE_MS = 20;
170
+ const DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS = ["@", "#"];
171
+ function escapeCharacterClass(value) {
172
+ return value.replace(/[\\^$.*+?()[\]{}|-]/g, "\\$&");
173
+ }
174
+ function buildTriggerPattern(triggerCharacters) {
175
+ return new RegExp(`(?:^|[\\s])[${triggerCharacters.map(escapeCharacterClass).join("")}][^\\s]*$`);
176
+ }
177
+ function buildDebouncePattern(triggerCharacters) {
178
+ const escapedWithoutAt = triggerCharacters.filter((character) => character !== "@").map(escapeCharacterClass);
179
+ return new RegExp(`(?:^|[ \\t])(?:@(?:"[^"]*|[^\\s]*)|[${escapedWithoutAt.join("")}][^\\s]*)$`);
180
+ }
181
+ export class Editor {
182
+ state = {
183
+ lines: [""],
184
+ cursorLine: 0,
185
+ cursorCol: 0,
186
+ };
187
+ /** Focusable interface - set by TUI when focus changes */
188
+ focused = false;
189
+ tui;
190
+ theme;
191
+ paddingX = 0;
192
+ // Store last render width for cursor navigation
193
+ lastWidth = 80;
194
+ // Vertical scrolling support
195
+ scrollOffset = 0;
196
+ // Border color (can be changed dynamically)
197
+ borderColor;
198
+ // Autocomplete support
199
+ autocompleteProvider;
200
+ autocompleteTriggerCharacters = [...DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS];
201
+ autocompleteTriggerPattern = buildTriggerPattern(this.autocompleteTriggerCharacters);
202
+ autocompleteDebouncePattern = buildDebouncePattern(this.autocompleteTriggerCharacters);
203
+ autocompleteList;
204
+ autocompleteState = null;
205
+ autocompletePrefix = "";
206
+ autocompleteMaxVisible = 5;
207
+ autocompleteAbort;
208
+ autocompleteDebounceTimer;
209
+ autocompleteRequestTask = Promise.resolve();
210
+ autocompleteStartToken = 0;
211
+ autocompleteRequestId = 0;
212
+ // Paste tracking for large pastes
213
+ pastes = new Map();
214
+ pasteCounter = 0;
215
+ // Bracketed paste mode buffering
216
+ pasteBuffer = "";
217
+ isInPaste = false;
218
+ // Prompt history for up/down navigation
219
+ history = [];
220
+ historyIndex = -1; // -1 = not browsing, 0 = most recent, 1 = older, etc.
221
+ historyDraft = null;
222
+ // Kill ring for Emacs-style kill/yank operations
223
+ killRing = new KillRing();
224
+ lastAction = null;
225
+ // Character jump mode
226
+ jumpMode = null;
227
+ // Preferred visual column for vertical cursor movement (sticky column)
228
+ preferredVisualCol = null;
229
+ // When the cursor is snapped to the start of an atomic segment, e.g. a
230
+ // paste marker, cursorCol no longer reflects where the cursor would have
231
+ // landed. This field stores the pre-snap cursorCol so that the next
232
+ // vertical move can resolve it to a visual column on whatever VL it belongs
233
+ // to.
234
+ snappedFromCursorCol = null;
235
+ // Undo support
236
+ undoStack = new UndoStack();
237
+ onSubmit;
238
+ onChange;
239
+ disableSubmit = false;
240
+ constructor(tui, theme, options = {}) {
241
+ this.tui = tui;
242
+ this.theme = theme;
243
+ this.borderColor = theme.borderColor;
244
+ const paddingX = options.paddingX ?? 0;
245
+ this.paddingX = Number.isFinite(paddingX) ? Math.max(0, Math.floor(paddingX)) : 0;
246
+ const maxVisible = options.autocompleteMaxVisible ?? 5;
247
+ this.autocompleteMaxVisible = Number.isFinite(maxVisible) ? Math.max(3, Math.min(20, Math.floor(maxVisible))) : 5;
248
+ }
249
+ /** Set of currently valid paste IDs, for marker-aware segmentation. */
250
+ validPasteIds() {
251
+ return new Set(this.pastes.keys());
252
+ }
253
+ /** Segment text with paste-marker awareness, only merging markers with valid IDs. */
254
+ segment(text, mode) {
255
+ return segmentWithMarkers(text, mode === "word" ? wordSegmenter : graphemeSegmenter, this.validPasteIds());
256
+ }
257
+ getPaddingX() {
258
+ return this.paddingX;
259
+ }
260
+ setPaddingX(padding) {
261
+ const newPadding = Number.isFinite(padding) ? Math.max(0, Math.floor(padding)) : 0;
262
+ if (this.paddingX !== newPadding) {
263
+ this.paddingX = newPadding;
264
+ this.tui.requestRender();
265
+ }
266
+ }
267
+ getAutocompleteMaxVisible() {
268
+ return this.autocompleteMaxVisible;
269
+ }
270
+ setAutocompleteMaxVisible(maxVisible) {
271
+ const newMaxVisible = Number.isFinite(maxVisible) ? Math.max(3, Math.min(20, Math.floor(maxVisible))) : 5;
272
+ if (this.autocompleteMaxVisible !== newMaxVisible) {
273
+ this.autocompleteMaxVisible = newMaxVisible;
274
+ this.tui.requestRender();
275
+ }
276
+ }
277
+ setAutocompleteProvider(provider) {
278
+ this.cancelAutocomplete();
279
+ this.autocompleteProvider = provider;
280
+ this.setAutocompleteTriggerCharacters(provider.triggerCharacters ?? []);
281
+ }
282
+ /**
283
+ * Add a prompt to history for up/down arrow navigation.
284
+ * Called after successful submission.
285
+ */
286
+ addToHistory(text) {
287
+ const trimmed = text.trim();
288
+ if (!trimmed)
289
+ return;
290
+ // Don't add consecutive duplicates
291
+ if (this.history.length > 0 && this.history[0] === trimmed)
292
+ return;
293
+ this.history.unshift(trimmed);
294
+ // Limit history size
295
+ if (this.history.length > 100) {
296
+ this.history.pop();
297
+ }
298
+ }
299
+ isOnFirstVisualLine() {
300
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
301
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
302
+ return currentVisualLine === 0;
303
+ }
304
+ isOnLastVisualLine() {
305
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
306
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
307
+ return currentVisualLine === visualLines.length - 1;
308
+ }
309
+ navigateHistory(direction) {
310
+ this.lastAction = null;
311
+ if (this.history.length === 0)
312
+ return;
313
+ const newIndex = this.historyIndex - direction; // Up(-1) increases index, Down(1) decreases
314
+ if (newIndex < -1 || newIndex >= this.history.length)
315
+ return;
316
+ // Capture state when first entering history browsing mode
317
+ if (this.historyIndex === -1 && newIndex >= 0) {
318
+ this.pushUndoSnapshot();
319
+ this.historyDraft = structuredClone(this.state);
320
+ }
321
+ this.historyIndex = newIndex;
322
+ if (this.historyIndex === -1) {
323
+ const draft = this.historyDraft;
324
+ this.historyDraft = null;
325
+ if (draft) {
326
+ this.state = draft;
327
+ this.preferredVisualCol = null;
328
+ this.snappedFromCursorCol = null;
329
+ this.scrollOffset = 0;
330
+ if (this.onChange)
331
+ this.onChange(this.getText());
332
+ }
333
+ else {
334
+ this.setTextInternal("");
335
+ }
336
+ }
337
+ else {
338
+ this.setTextInternal(this.history[this.historyIndex] || "", direction === -1 ? "start" : "end");
339
+ }
340
+ }
341
+ exitHistoryBrowsing() {
342
+ this.historyIndex = -1;
343
+ this.historyDraft = null;
344
+ }
345
+ /** Internal setText that doesn't reset history state - used by navigateHistory */
346
+ setTextInternal(text, cursorPlacement = "end") {
347
+ const lines = text.split("\n");
348
+ this.state.lines = lines.length === 0 ? [""] : lines;
349
+ this.state.cursorLine = cursorPlacement === "start" ? 0 : this.state.lines.length - 1;
350
+ this.setCursorCol(cursorPlacement === "start" ? 0 : this.state.lines[this.state.cursorLine]?.length || 0);
351
+ // Reset scroll - render() will adjust to show cursor
352
+ this.scrollOffset = 0;
353
+ if (this.onChange) {
354
+ this.onChange(this.getText());
355
+ }
356
+ }
357
+ invalidate() {
358
+ // No cached state to invalidate currently
359
+ }
360
+ render(width) {
361
+ const maxPadding = Math.max(0, Math.floor((width - 1) / 2));
362
+ const paddingX = Math.min(this.paddingX, maxPadding);
363
+ const contentWidth = Math.max(1, width - paddingX * 2);
364
+ // Layout width: with padding the cursor can overflow into it,
365
+ // without padding we reserve 1 column for the cursor.
366
+ const layoutWidth = Math.max(1, contentWidth - (paddingX ? 0 : 1));
367
+ // Store for cursor navigation (must match wrapping width)
368
+ this.lastWidth = layoutWidth;
369
+ const horizontal = this.borderColor("─");
370
+ // Layout the text
371
+ const layoutLines = this.layoutText(layoutWidth);
372
+ // Calculate max visible lines: 30% of terminal height, minimum 5 lines
373
+ const terminalRows = this.tui.terminal.rows;
374
+ const maxVisibleLines = Math.max(5, Math.floor(terminalRows * 0.3));
375
+ // Find the cursor line index in layoutLines
376
+ let cursorLineIndex = layoutLines.findIndex((line) => line.hasCursor);
377
+ if (cursorLineIndex === -1)
378
+ cursorLineIndex = 0;
379
+ // Adjust scroll offset to keep cursor visible
380
+ if (cursorLineIndex < this.scrollOffset) {
381
+ this.scrollOffset = cursorLineIndex;
382
+ }
383
+ else if (cursorLineIndex >= this.scrollOffset + maxVisibleLines) {
384
+ this.scrollOffset = cursorLineIndex - maxVisibleLines + 1;
385
+ }
386
+ // Clamp scroll offset to valid range
387
+ const maxScrollOffset = Math.max(0, layoutLines.length - maxVisibleLines);
388
+ this.scrollOffset = Math.max(0, Math.min(this.scrollOffset, maxScrollOffset));
389
+ // Get visible lines slice
390
+ const visibleLines = layoutLines.slice(this.scrollOffset, this.scrollOffset + maxVisibleLines);
391
+ const result = [];
392
+ const leftPadding = " ".repeat(paddingX);
393
+ const rightPadding = leftPadding;
394
+ // Render top border (with scroll indicator if scrolled down)
395
+ if (this.scrollOffset > 0) {
396
+ const indicator = `─── ↑ ${this.scrollOffset} more `;
397
+ const remaining = width - visibleWidth(indicator);
398
+ if (remaining >= 0) {
399
+ result.push(this.borderColor(indicator + "─".repeat(remaining)));
400
+ }
401
+ else {
402
+ result.push(this.borderColor(truncateToWidth(indicator, width)));
403
+ }
404
+ }
405
+ else {
406
+ result.push(horizontal.repeat(width));
407
+ }
408
+ // Render each visible layout line
409
+ // Emit hardware cursor marker when focused so TUI can position the
410
+ // hardware cursor for IME candidate-window placement even while
411
+ // autocomplete (e.g. slash-command menu) is visible.
412
+ const emitCursorMarker = this.focused;
413
+ for (const layoutLine of visibleLines) {
414
+ let displayText = layoutLine.text;
415
+ let lineVisibleWidth = visibleWidth(layoutLine.text);
416
+ let cursorInPadding = false;
417
+ // Add cursor if this line has it
418
+ if (layoutLine.hasCursor && layoutLine.cursorPos !== undefined) {
419
+ const before = displayText.slice(0, layoutLine.cursorPos);
420
+ const after = displayText.slice(layoutLine.cursorPos);
421
+ // Hardware cursor marker (zero-width, emitted before fake cursor for IME positioning)
422
+ const marker = emitCursorMarker ? CURSOR_MARKER : "";
423
+ if (after.length > 0) {
424
+ // Cursor is on a character (grapheme) - replace it with highlighted version
425
+ // Get the first grapheme from 'after'
426
+ const afterGraphemes = [...this.segment(after, "grapheme")];
427
+ const firstGrapheme = afterGraphemes[0]?.segment || "";
428
+ const restAfter = after.slice(firstGrapheme.length);
429
+ const cursor = `\x1b[7m${firstGrapheme}\x1b[0m`;
430
+ displayText = before + marker + cursor + restAfter;
431
+ // lineVisibleWidth stays the same - we're replacing, not adding
432
+ }
433
+ else {
434
+ // Cursor is at the end - add highlighted space
435
+ const cursor = "\x1b[7m \x1b[0m";
436
+ displayText = before + marker + cursor;
437
+ lineVisibleWidth = lineVisibleWidth + 1;
438
+ // If cursor overflows content width into the padding, flag it
439
+ if (lineVisibleWidth > contentWidth && paddingX > 0) {
440
+ cursorInPadding = true;
441
+ }
442
+ }
443
+ }
444
+ // Calculate padding based on actual visible width
445
+ const padding = " ".repeat(Math.max(0, contentWidth - lineVisibleWidth));
446
+ const lineRightPadding = cursorInPadding ? rightPadding.slice(1) : rightPadding;
447
+ // Render the line (no side borders, just horizontal lines above and below)
448
+ result.push(`${leftPadding}${displayText}${padding}${lineRightPadding}`);
449
+ }
450
+ // Render bottom border (with scroll indicator if more content below)
451
+ const linesBelow = layoutLines.length - (this.scrollOffset + visibleLines.length);
452
+ if (linesBelow > 0) {
453
+ const indicator = `─── ↓ ${linesBelow} more `;
454
+ const remaining = width - visibleWidth(indicator);
455
+ result.push(this.borderColor(indicator + "─".repeat(Math.max(0, remaining))));
456
+ }
457
+ else {
458
+ result.push(horizontal.repeat(width));
459
+ }
460
+ // Add autocomplete list if active
461
+ if (this.autocompleteState && this.autocompleteList) {
462
+ const autocompleteResult = this.autocompleteList.render(contentWidth);
463
+ for (const line of autocompleteResult) {
464
+ const lineWidth = visibleWidth(line);
465
+ const linePadding = " ".repeat(Math.max(0, contentWidth - lineWidth));
466
+ result.push(`${leftPadding}${line}${linePadding}${rightPadding}`);
467
+ }
468
+ }
469
+ return result;
470
+ }
471
+ // biome-ignore lint/suspicious/noConfusingVoidType: matches Component interface
472
+ handleInput(data) {
473
+ const kb = getKeybindings();
474
+ // Handle character jump mode (awaiting next character to jump to)
475
+ if (this.jumpMode !== null) {
476
+ // Cancel if the hotkey is pressed again
477
+ if (kb.matches(data, "tui.editor.jumpForward") || kb.matches(data, "tui.editor.jumpBackward")) {
478
+ this.jumpMode = null;
479
+ return;
480
+ }
481
+ const printable = decodePrintableKey(data) ?? (data.charCodeAt(0) >= 32 ? data : undefined);
482
+ if (printable !== undefined) {
483
+ // Printable character - perform the jump
484
+ const direction = this.jumpMode;
485
+ this.jumpMode = null;
486
+ this.jumpToChar(printable, direction);
487
+ return;
488
+ }
489
+ // Control character - cancel and fall through to normal handling
490
+ this.jumpMode = null;
491
+ }
492
+ // Handle bracketed paste mode
493
+ if (data.includes("\x1b[200~")) {
494
+ this.isInPaste = true;
495
+ this.pasteBuffer = "";
496
+ data = data.replace("\x1b[200~", "");
497
+ }
498
+ if (this.isInPaste) {
499
+ this.pasteBuffer += data;
500
+ const endIndex = this.pasteBuffer.indexOf("\x1b[201~");
501
+ if (endIndex !== -1) {
502
+ const pasteContent = this.pasteBuffer.substring(0, endIndex);
503
+ if (pasteContent.length > 0) {
504
+ this.handlePaste(pasteContent);
505
+ }
506
+ this.isInPaste = false;
507
+ const remaining = this.pasteBuffer.substring(endIndex + 6);
508
+ this.pasteBuffer = "";
509
+ if (remaining.length > 0) {
510
+ this.handleInput(remaining);
511
+ }
512
+ return;
513
+ }
514
+ return;
515
+ }
516
+ // Ctrl+C - let parent handle (exit/clear)
517
+ if (kb.matches(data, "tui.input.copy")) {
518
+ return;
519
+ }
520
+ // Undo
521
+ if (kb.matches(data, "tui.editor.undo")) {
522
+ this.undo();
523
+ return;
524
+ }
525
+ // Handle autocomplete mode
526
+ if (this.autocompleteState && this.autocompleteList) {
527
+ if (kb.matches(data, "tui.select.cancel")) {
528
+ this.cancelAutocomplete();
529
+ return;
530
+ }
531
+ if (kb.matches(data, "tui.select.up") || kb.matches(data, "tui.select.down")) {
532
+ this.autocompleteList.handleInput(data);
533
+ return;
534
+ }
535
+ if (kb.matches(data, "tui.input.tab")) {
536
+ const selected = this.autocompleteList.getSelectedItem();
537
+ if (selected && this.autocompleteProvider) {
538
+ this.pushUndoSnapshot();
539
+ this.lastAction = null;
540
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
541
+ this.state.lines = result.lines;
542
+ this.state.cursorLine = result.cursorLine;
543
+ this.setCursorCol(result.cursorCol);
544
+ this.cancelAutocomplete();
545
+ if (this.onChange)
546
+ this.onChange(this.getText());
547
+ }
548
+ return;
549
+ }
550
+ if (kb.matches(data, "tui.select.confirm")) {
551
+ const selected = this.autocompleteList.getSelectedItem();
552
+ if (selected && this.autocompleteProvider) {
553
+ this.pushUndoSnapshot();
554
+ this.lastAction = null;
555
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, selected, this.autocompletePrefix);
556
+ this.state.lines = result.lines;
557
+ this.state.cursorLine = result.cursorLine;
558
+ this.setCursorCol(result.cursorCol);
559
+ if (this.autocompletePrefix.startsWith("/")) {
560
+ this.cancelAutocomplete();
561
+ // Fall through to submit
562
+ }
563
+ else {
564
+ this.cancelAutocomplete();
565
+ if (this.onChange)
566
+ this.onChange(this.getText());
567
+ return;
568
+ }
569
+ }
570
+ }
571
+ }
572
+ // Tab - trigger completion
573
+ if (kb.matches(data, "tui.input.tab") && !this.autocompleteState) {
574
+ this.handleTabCompletion();
575
+ return;
576
+ }
577
+ // Deletion actions
578
+ if (kb.matches(data, "tui.editor.deleteToLineEnd")) {
579
+ this.deleteToEndOfLine();
580
+ return;
581
+ }
582
+ if (kb.matches(data, "tui.editor.deleteToLineStart")) {
583
+ this.deleteToStartOfLine();
584
+ return;
585
+ }
586
+ if (kb.matches(data, "tui.editor.deleteWordBackward")) {
587
+ this.deleteWordBackwards();
588
+ return;
589
+ }
590
+ if (kb.matches(data, "tui.editor.deleteWordForward")) {
591
+ this.deleteWordForward();
592
+ return;
593
+ }
594
+ if (kb.matches(data, "tui.editor.deleteCharBackward") || matchesKey(data, "shift+backspace")) {
595
+ this.handleBackspace();
596
+ return;
597
+ }
598
+ if (kb.matches(data, "tui.editor.deleteCharForward") || matchesKey(data, "shift+delete")) {
599
+ this.handleForwardDelete();
600
+ return;
601
+ }
602
+ // Kill ring actions
603
+ if (kb.matches(data, "tui.editor.yank")) {
604
+ this.yank();
605
+ return;
606
+ }
607
+ if (kb.matches(data, "tui.editor.yankPop")) {
608
+ this.yankPop();
609
+ return;
610
+ }
611
+ // Cursor movement actions
612
+ if (kb.matches(data, "tui.editor.cursorLineStart")) {
613
+ this.moveToLineStart();
614
+ return;
615
+ }
616
+ if (kb.matches(data, "tui.editor.cursorLineEnd")) {
617
+ this.moveToLineEnd();
618
+ return;
619
+ }
620
+ if (kb.matches(data, "tui.editor.cursorWordLeft")) {
621
+ this.moveWordBackwards();
622
+ return;
623
+ }
624
+ if (kb.matches(data, "tui.editor.cursorWordRight")) {
625
+ this.moveWordForwards();
626
+ return;
627
+ }
628
+ // New line
629
+ if (kb.matches(data, "tui.input.newLine") ||
630
+ (data.charCodeAt(0) === 10 && data.length > 1) ||
631
+ data === "\x1b\r" ||
632
+ data === "\x1b[13;2~" ||
633
+ (data.length > 1 && data.includes("\x1b") && data.includes("\r"))) {
634
+ if (this.shouldSubmitOnBackslashEnter(data, kb)) {
635
+ this.handleBackspace();
636
+ this.submitValue();
637
+ return;
638
+ }
639
+ this.addNewLine();
640
+ return;
641
+ }
642
+ // Submit (Enter)
643
+ if (kb.matches(data, "tui.input.submit")) {
644
+ if (this.disableSubmit)
645
+ return;
646
+ // Workaround for terminals without Shift+Enter support:
647
+ // If char before cursor is \, delete it and insert newline instead of submitting.
648
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
649
+ if (this.state.cursorCol > 0 && currentLine[this.state.cursorCol - 1] === "\\") {
650
+ this.handleBackspace();
651
+ this.addNewLine();
652
+ return;
653
+ }
654
+ this.submitValue();
655
+ return;
656
+ }
657
+ // Arrow key navigation (with history support)
658
+ if (kb.matches(data, "tui.editor.cursorUp")) {
659
+ if (this.isOnFirstVisualLine() && this.history.length > 0) {
660
+ this.navigateHistory(-1);
661
+ }
662
+ else if (this.isOnFirstVisualLine()) {
663
+ // Already at top - jump to start of line
664
+ this.moveToLineStart();
665
+ }
666
+ else {
667
+ this.moveCursor(-1, 0);
668
+ }
669
+ return;
670
+ }
671
+ if (kb.matches(data, "tui.editor.cursorDown")) {
672
+ if (this.historyIndex > -1 && this.isOnLastVisualLine()) {
673
+ this.navigateHistory(1);
674
+ }
675
+ else if (this.isOnLastVisualLine()) {
676
+ // Already at bottom - jump to end of line
677
+ this.moveToLineEnd();
678
+ }
679
+ else {
680
+ this.moveCursor(1, 0);
681
+ }
682
+ return;
683
+ }
684
+ if (kb.matches(data, "tui.editor.cursorRight")) {
685
+ this.moveCursor(0, 1);
686
+ return;
687
+ }
688
+ if (kb.matches(data, "tui.editor.cursorLeft")) {
689
+ this.moveCursor(0, -1);
690
+ return;
691
+ }
692
+ // Page up/down - scroll by page and move cursor
693
+ if (kb.matches(data, "tui.editor.pageUp")) {
694
+ this.pageScroll(-1);
695
+ return;
696
+ }
697
+ if (kb.matches(data, "tui.editor.pageDown")) {
698
+ this.pageScroll(1);
699
+ return;
700
+ }
701
+ // Character jump mode triggers
702
+ if (kb.matches(data, "tui.editor.jumpForward")) {
703
+ this.jumpMode = "forward";
704
+ return;
705
+ }
706
+ if (kb.matches(data, "tui.editor.jumpBackward")) {
707
+ this.jumpMode = "backward";
708
+ return;
709
+ }
710
+ // Shift+Space - insert regular space
711
+ if (matchesKey(data, "shift+space")) {
712
+ this.insertCharacter(" ");
713
+ return;
714
+ }
715
+ const printable = decodePrintableKey(data);
716
+ if (printable !== undefined) {
717
+ this.insertCharacter(printable);
718
+ return;
719
+ }
720
+ // Regular characters
721
+ if (data.charCodeAt(0) >= 32) {
722
+ this.insertCharacter(data);
723
+ }
724
+ }
725
+ layoutText(contentWidth) {
726
+ const layoutLines = [];
727
+ if (this.state.lines.length === 0 || (this.state.lines.length === 1 && this.state.lines[0] === "")) {
728
+ // Empty editor
729
+ layoutLines.push({
730
+ text: "",
731
+ hasCursor: true,
732
+ cursorPos: 0,
733
+ });
734
+ return layoutLines;
735
+ }
736
+ // Process each logical line
737
+ for (let i = 0; i < this.state.lines.length; i++) {
738
+ const line = this.state.lines[i] || "";
739
+ const isCurrentLine = i === this.state.cursorLine;
740
+ const lineVisibleWidth = visibleWidth(line);
741
+ if (lineVisibleWidth <= contentWidth) {
742
+ // Line fits in one layout line
743
+ if (isCurrentLine) {
744
+ layoutLines.push({
745
+ text: line,
746
+ hasCursor: true,
747
+ cursorPos: this.state.cursorCol,
748
+ });
749
+ }
750
+ else {
751
+ layoutLines.push({
752
+ text: line,
753
+ hasCursor: false,
754
+ });
755
+ }
756
+ }
757
+ else {
758
+ // Line needs wrapping - use word-aware wrapping
759
+ const chunks = wordWrapLine(line, contentWidth, [...this.segment(line, "grapheme")]);
760
+ for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
761
+ const chunk = chunks[chunkIndex];
762
+ if (!chunk)
763
+ continue;
764
+ const cursorPos = this.state.cursorCol;
765
+ const isLastChunk = chunkIndex === chunks.length - 1;
766
+ // Determine if cursor is in this chunk
767
+ // For word-wrapped chunks, we need to handle the case where
768
+ // cursor might be in trimmed whitespace at end of chunk
769
+ let hasCursorInChunk = false;
770
+ let adjustedCursorPos = 0;
771
+ if (isCurrentLine) {
772
+ if (isLastChunk) {
773
+ // Last chunk: cursor belongs here if >= startIndex
774
+ hasCursorInChunk = cursorPos >= chunk.startIndex;
775
+ adjustedCursorPos = cursorPos - chunk.startIndex;
776
+ }
777
+ else {
778
+ // Non-last chunk: cursor belongs here if in range [startIndex, endIndex)
779
+ // But we need to handle the visual position in the trimmed text
780
+ hasCursorInChunk = cursorPos >= chunk.startIndex && cursorPos < chunk.endIndex;
781
+ if (hasCursorInChunk) {
782
+ adjustedCursorPos = cursorPos - chunk.startIndex;
783
+ // Clamp to text length (in case cursor was in trimmed whitespace)
784
+ if (adjustedCursorPos > chunk.text.length) {
785
+ adjustedCursorPos = chunk.text.length;
786
+ }
787
+ }
788
+ }
789
+ }
790
+ if (hasCursorInChunk) {
791
+ layoutLines.push({
792
+ text: chunk.text,
793
+ hasCursor: true,
794
+ cursorPos: adjustedCursorPos,
795
+ });
796
+ }
797
+ else {
798
+ layoutLines.push({
799
+ text: chunk.text,
800
+ hasCursor: false,
801
+ });
802
+ }
803
+ }
804
+ }
805
+ }
806
+ return layoutLines;
807
+ }
808
+ getText() {
809
+ return this.state.lines.join("\n");
810
+ }
811
+ expandPasteMarkers(text) {
812
+ let result = text;
813
+ for (const [pasteId, pasteContent] of this.pastes) {
814
+ const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
815
+ result = result.replace(markerRegex, () => pasteContent);
816
+ }
817
+ return result;
818
+ }
819
+ /**
820
+ * Get text with paste markers expanded to their actual content.
821
+ * Use this when you need the full content (e.g., for external editor).
822
+ */
823
+ getExpandedText() {
824
+ return this.expandPasteMarkers(this.state.lines.join("\n"));
825
+ }
826
+ getLines() {
827
+ return [...this.state.lines];
828
+ }
829
+ getCursor() {
830
+ return { line: this.state.cursorLine, col: this.state.cursorCol };
831
+ }
832
+ setText(text) {
833
+ this.cancelAutocomplete();
834
+ this.lastAction = null;
835
+ this.exitHistoryBrowsing();
836
+ const normalized = this.normalizeText(text);
837
+ // Push undo snapshot if content differs (makes programmatic changes undoable)
838
+ if (this.getText() !== normalized) {
839
+ this.pushUndoSnapshot();
840
+ }
841
+ this.setTextInternal(normalized);
842
+ }
843
+ /**
844
+ * Insert text at the current cursor position.
845
+ * Used for programmatic insertion (e.g., clipboard image markers).
846
+ * This is atomic for undo - single undo restores entire pre-insert state.
847
+ */
848
+ insertTextAtCursor(text) {
849
+ if (!text)
850
+ return;
851
+ this.cancelAutocomplete();
852
+ this.pushUndoSnapshot();
853
+ this.lastAction = null;
854
+ this.exitHistoryBrowsing();
855
+ this.insertTextAtCursorInternal(text);
856
+ }
857
+ /**
858
+ * Normalize text for editor storage:
859
+ * - Normalize line endings (\r\n and \r -> \n)
860
+ * - Expand tabs to 4 spaces
861
+ */
862
+ normalizeText(text) {
863
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\t/g, " ");
864
+ }
865
+ /**
866
+ * Internal text insertion at cursor. Handles single and multi-line text.
867
+ * Does not push undo snapshots or trigger autocomplete - caller is responsible.
868
+ * Normalizes line endings and calls onChange once at the end.
869
+ */
870
+ insertTextAtCursorInternal(text) {
871
+ if (!text)
872
+ return;
873
+ // Normalize line endings and tabs
874
+ const normalized = this.normalizeText(text);
875
+ const insertedLines = normalized.split("\n");
876
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
877
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
878
+ const afterCursor = currentLine.slice(this.state.cursorCol);
879
+ if (insertedLines.length === 1) {
880
+ // Single line - insert at cursor position
881
+ this.state.lines[this.state.cursorLine] = beforeCursor + normalized + afterCursor;
882
+ this.setCursorCol(this.state.cursorCol + normalized.length);
883
+ }
884
+ else {
885
+ // Multi-line insertion
886
+ this.state.lines = [
887
+ // All lines before current line
888
+ ...this.state.lines.slice(0, this.state.cursorLine),
889
+ // The first inserted line merged with text before cursor
890
+ beforeCursor + insertedLines[0],
891
+ // All middle inserted lines
892
+ ...insertedLines.slice(1, -1),
893
+ // The last inserted line with text after cursor
894
+ insertedLines[insertedLines.length - 1] + afterCursor,
895
+ // All lines after current line
896
+ ...this.state.lines.slice(this.state.cursorLine + 1),
897
+ ];
898
+ this.state.cursorLine += insertedLines.length - 1;
899
+ this.setCursorCol((insertedLines[insertedLines.length - 1] || "").length);
900
+ }
901
+ if (this.onChange) {
902
+ this.onChange(this.getText());
903
+ }
904
+ }
905
+ // All the editor methods from before...
906
+ insertCharacter(char, skipUndoCoalescing) {
907
+ this.exitHistoryBrowsing();
908
+ // Undo coalescing (fish-style):
909
+ // - Consecutive word chars coalesce into one undo unit
910
+ // - Space captures state before itself (so undo removes space+following word together)
911
+ // - Each space is separately undoable
912
+ // Skip coalescing when called from atomic operations (e.g., handlePaste)
913
+ if (!skipUndoCoalescing) {
914
+ if (isWhitespaceChar(char) || this.lastAction !== "type-word") {
915
+ this.pushUndoSnapshot();
916
+ }
917
+ this.lastAction = "type-word";
918
+ }
919
+ const line = this.state.lines[this.state.cursorLine] || "";
920
+ const before = line.slice(0, this.state.cursorCol);
921
+ const after = line.slice(this.state.cursorCol);
922
+ this.state.lines[this.state.cursorLine] = before + char + after;
923
+ this.setCursorCol(this.state.cursorCol + char.length);
924
+ if (this.onChange) {
925
+ this.onChange(this.getText());
926
+ }
927
+ // Check if we should trigger or update autocomplete
928
+ if (!this.autocompleteState) {
929
+ // Auto-trigger for "/" at the start of a line (slash commands)
930
+ if (char === "/" && this.isAtStartOfMessage()) {
931
+ this.tryTriggerAutocomplete();
932
+ }
933
+ // Auto-trigger for symbol-based completion like @, #, or provider triggers at token boundaries
934
+ else if (this.autocompleteTriggerCharacters.includes(char)) {
935
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
936
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
937
+ const charBeforeSymbol = textBeforeCursor[textBeforeCursor.length - 2];
938
+ if (textBeforeCursor.length === 1 || charBeforeSymbol === " " || charBeforeSymbol === "\t") {
939
+ this.tryTriggerAutocomplete();
940
+ }
941
+ }
942
+ // Also auto-trigger when typing letters in a slash command or symbol completion context
943
+ else if (/[a-zA-Z0-9.\-_]/.test(char)) {
944
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
945
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
946
+ // Check if we're in a slash command (with or without space for arguments)
947
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
948
+ this.tryTriggerAutocomplete();
949
+ }
950
+ // Check if we're in a symbol-based completion context like @, #, or provider triggers
951
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
952
+ this.tryTriggerAutocomplete();
953
+ }
954
+ }
955
+ }
956
+ else {
957
+ this.updateAutocomplete();
958
+ }
959
+ }
960
+ handlePaste(pastedText) {
961
+ this.cancelAutocomplete();
962
+ this.exitHistoryBrowsing();
963
+ this.lastAction = null;
964
+ this.pushUndoSnapshot();
965
+ // Some terminals (e.g. tmux popups with extended-keys-format=csi-u) re-encode
966
+ // control bytes inside bracketed paste as CSI-u Ctrl+<letter> sequences
967
+ // (ESC [ <codepoint> ; 5 u). Decode those back to their literal byte so the
968
+ // per-char filter below preserves newlines instead of stripping ESC and
969
+ // leaking the printable tail (e.g. "[106;5u") into the editor.
970
+ const decodedText = pastedText.replace(/\x1b\[(\d+);5u/g, (match, code) => {
971
+ const cp = Number(code);
972
+ if (cp >= 97 && cp <= 122)
973
+ return String.fromCharCode(cp - 96);
974
+ if (cp >= 65 && cp <= 90)
975
+ return String.fromCharCode(cp - 64);
976
+ return match;
977
+ });
978
+ // Clean the pasted text: normalize line endings, expand tabs
979
+ const cleanText = this.normalizeText(decodedText);
980
+ // Filter out non-printable characters except newlines
981
+ let filteredText = cleanText
982
+ .split("")
983
+ .filter((char) => char === "\n" || char.charCodeAt(0) >= 32)
984
+ .join("");
985
+ // If pasting a file path (starts with /, ~, or .) and the character before
986
+ // the cursor is a word character, prepend a space for better readability
987
+ if (/^[/~.]/.test(filteredText)) {
988
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
989
+ const charBeforeCursor = this.state.cursorCol > 0 ? currentLine[this.state.cursorCol - 1] : "";
990
+ if (charBeforeCursor && /\w/.test(charBeforeCursor)) {
991
+ filteredText = ` ${filteredText}`;
992
+ }
993
+ }
994
+ // Split into lines to check for large paste
995
+ const pastedLines = filteredText.split("\n");
996
+ // Check if this is a large paste (> 10 lines or > 1000 characters)
997
+ const totalChars = filteredText.length;
998
+ if (pastedLines.length > 10 || totalChars > 1000) {
999
+ // Store the paste and insert a marker
1000
+ this.pasteCounter++;
1001
+ const pasteId = this.pasteCounter;
1002
+ this.pastes.set(pasteId, filteredText);
1003
+ // Insert marker like "[paste #1 +123 lines]" or "[paste #1 1234 chars]"
1004
+ const marker = pastedLines.length > 10
1005
+ ? `[paste #${pasteId} +${pastedLines.length} lines]`
1006
+ : `[paste #${pasteId} ${totalChars} chars]`;
1007
+ this.insertTextAtCursorInternal(marker);
1008
+ return;
1009
+ }
1010
+ if (pastedLines.length === 1) {
1011
+ // Single line - insert atomically (do not trigger autocomplete during paste)
1012
+ this.insertTextAtCursorInternal(filteredText);
1013
+ return;
1014
+ }
1015
+ // Multi-line paste - use direct state manipulation
1016
+ this.insertTextAtCursorInternal(filteredText);
1017
+ }
1018
+ addNewLine() {
1019
+ this.cancelAutocomplete();
1020
+ this.exitHistoryBrowsing();
1021
+ this.lastAction = null;
1022
+ this.pushUndoSnapshot();
1023
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1024
+ const before = currentLine.slice(0, this.state.cursorCol);
1025
+ const after = currentLine.slice(this.state.cursorCol);
1026
+ // Split current line
1027
+ this.state.lines[this.state.cursorLine] = before;
1028
+ this.state.lines.splice(this.state.cursorLine + 1, 0, after);
1029
+ // Move cursor to start of new line
1030
+ this.state.cursorLine++;
1031
+ this.setCursorCol(0);
1032
+ if (this.onChange) {
1033
+ this.onChange(this.getText());
1034
+ }
1035
+ }
1036
+ shouldSubmitOnBackslashEnter(data, kb) {
1037
+ if (this.disableSubmit)
1038
+ return false;
1039
+ if (!matchesKey(data, "enter"))
1040
+ return false;
1041
+ const submitKeys = kb.getKeys("tui.input.submit");
1042
+ const hasShiftEnter = submitKeys.includes("shift+enter") || submitKeys.includes("shift+return");
1043
+ if (!hasShiftEnter)
1044
+ return false;
1045
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1046
+ return this.state.cursorCol > 0 && currentLine[this.state.cursorCol - 1] === "\\";
1047
+ }
1048
+ submitValue() {
1049
+ this.cancelAutocomplete();
1050
+ const result = this.expandPasteMarkers(this.state.lines.join("\n")).trim();
1051
+ this.state = { lines: [""], cursorLine: 0, cursorCol: 0 };
1052
+ this.pastes.clear();
1053
+ this.pasteCounter = 0;
1054
+ this.exitHistoryBrowsing();
1055
+ this.scrollOffset = 0;
1056
+ this.undoStack.clear();
1057
+ this.lastAction = null;
1058
+ if (this.onChange)
1059
+ this.onChange("");
1060
+ if (this.onSubmit)
1061
+ this.onSubmit(result);
1062
+ }
1063
+ handleBackspace() {
1064
+ this.exitHistoryBrowsing();
1065
+ this.lastAction = null;
1066
+ if (this.state.cursorCol > 0) {
1067
+ this.pushUndoSnapshot();
1068
+ // Delete grapheme before cursor (handles emojis, combining characters, etc.)
1069
+ const line = this.state.lines[this.state.cursorLine] || "";
1070
+ const beforeCursor = line.slice(0, this.state.cursorCol);
1071
+ // Find the last grapheme in the text before cursor
1072
+ const graphemes = [...this.segment(beforeCursor, "grapheme")];
1073
+ const lastGrapheme = graphemes[graphemes.length - 1];
1074
+ const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
1075
+ const before = line.slice(0, this.state.cursorCol - graphemeLength);
1076
+ const after = line.slice(this.state.cursorCol);
1077
+ this.state.lines[this.state.cursorLine] = before + after;
1078
+ this.setCursorCol(this.state.cursorCol - graphemeLength);
1079
+ }
1080
+ else if (this.state.cursorLine > 0) {
1081
+ this.pushUndoSnapshot();
1082
+ // Merge with previous line
1083
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1084
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1085
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1086
+ this.state.lines.splice(this.state.cursorLine, 1);
1087
+ this.state.cursorLine--;
1088
+ this.setCursorCol(previousLine.length);
1089
+ }
1090
+ if (this.onChange) {
1091
+ this.onChange(this.getText());
1092
+ }
1093
+ // Update or re-trigger autocomplete after backspace
1094
+ if (this.autocompleteState) {
1095
+ this.updateAutocomplete();
1096
+ }
1097
+ else {
1098
+ // If autocomplete was cancelled (no matches), re-trigger if we're in a completable context
1099
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1100
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1101
+ // Slash command context
1102
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
1103
+ this.tryTriggerAutocomplete();
1104
+ }
1105
+ // Symbol-based completion context like @, #, or provider triggers
1106
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1107
+ this.tryTriggerAutocomplete();
1108
+ }
1109
+ }
1110
+ }
1111
+ /**
1112
+ * Set cursor column and clear preferredVisualCol.
1113
+ * Use this for all non-vertical cursor movements to reset sticky column behavior.
1114
+ */
1115
+ setCursorCol(col) {
1116
+ this.state.cursorCol = col;
1117
+ this.preferredVisualCol = null;
1118
+ this.snappedFromCursorCol = null;
1119
+ }
1120
+ /**
1121
+ * Move cursor to a target visual line, applying sticky column logic.
1122
+ * Shared by moveCursor() and pageScroll().
1123
+ */
1124
+ moveToVisualLine(visualLines, currentVisualLine, targetVisualLine) {
1125
+ const currentVL = visualLines[currentVisualLine];
1126
+ const targetVL = visualLines[targetVisualLine];
1127
+ if (!(currentVL && targetVL))
1128
+ return;
1129
+ // When the cursor was snapped to a segment start, resolve the pre-snap
1130
+ // position against the VL it belongs to. This gives the correct visual
1131
+ // column even after a resize reshuffles VLs.
1132
+ let currentVisualCol;
1133
+ if (this.snappedFromCursorCol !== null) {
1134
+ const vlIndex = this.findVisualLineAt(visualLines, currentVL.logicalLine, this.snappedFromCursorCol);
1135
+ currentVisualCol = this.snappedFromCursorCol - visualLines[vlIndex].startCol;
1136
+ }
1137
+ else {
1138
+ currentVisualCol = this.state.cursorCol - currentVL.startCol;
1139
+ }
1140
+ // For non-last segments, clamp to length-1 to stay within the segment
1141
+ const isLastSourceSegment = currentVisualLine === visualLines.length - 1 ||
1142
+ visualLines[currentVisualLine + 1]?.logicalLine !== currentVL.logicalLine;
1143
+ const sourceMaxVisualCol = isLastSourceSegment ? currentVL.length : Math.max(0, currentVL.length - 1);
1144
+ const isLastTargetSegment = targetVisualLine === visualLines.length - 1 ||
1145
+ visualLines[targetVisualLine + 1]?.logicalLine !== targetVL.logicalLine;
1146
+ const targetMaxVisualCol = isLastTargetSegment ? targetVL.length : Math.max(0, targetVL.length - 1);
1147
+ const moveToVisualCol = this.computeVerticalMoveColumn(currentVisualCol, sourceMaxVisualCol, targetMaxVisualCol);
1148
+ // Set cursor position
1149
+ this.state.cursorLine = targetVL.logicalLine;
1150
+ const targetCol = targetVL.startCol + moveToVisualCol;
1151
+ const logicalLine = this.state.lines[targetVL.logicalLine] || "";
1152
+ this.state.cursorCol = Math.min(targetCol, logicalLine.length);
1153
+ // Snap cursor to atomic segment boundary (e.g. paste markers)
1154
+ // so the cursor never lands in the middle of a multi-grapheme unit.
1155
+ // Single-grapheme segments don't need snapping.
1156
+ const segments = [...this.segment(logicalLine, "grapheme")];
1157
+ for (const seg of segments) {
1158
+ if (seg.index > this.state.cursorCol)
1159
+ break;
1160
+ if (seg.segment.length <= 1)
1161
+ continue;
1162
+ if (this.state.cursorCol < seg.index + seg.segment.length) {
1163
+ const isContinuation = seg.index < targetVL.startCol;
1164
+ const isMovingDown = targetVisualLine > currentVisualLine;
1165
+ if (isContinuation && isMovingDown) {
1166
+ // The segment started on a previous visual line, and we
1167
+ // already visited it on the way down. Skip all remaining
1168
+ // continuation VLs and land on the first VL past it.
1169
+ const segEnd = seg.index + seg.segment.length;
1170
+ let next = targetVisualLine + 1;
1171
+ while (next < visualLines.length &&
1172
+ visualLines[next].logicalLine === targetVL.logicalLine &&
1173
+ visualLines[next].startCol < segEnd) {
1174
+ next++;
1175
+ }
1176
+ if (next < visualLines.length) {
1177
+ this.moveToVisualLine(visualLines, currentVisualLine, next);
1178
+ return;
1179
+ }
1180
+ }
1181
+ // Snap to the start of the segment so it gets highlighted.
1182
+ // Store the pre-snap position so the next vertical move can
1183
+ // resolve it to the correct visual column.
1184
+ this.snappedFromCursorCol = this.state.cursorCol;
1185
+ this.state.cursorCol = seg.index;
1186
+ return;
1187
+ }
1188
+ }
1189
+ // No snap occurred – we moved out of the atomic segment.
1190
+ this.snappedFromCursorCol = null;
1191
+ }
1192
+ /**
1193
+ * Compute the target visual column for vertical cursor movement.
1194
+ * Implements the sticky column decision table:
1195
+ *
1196
+ * | P | S | T | U | Scenario | Set Preferred | Move To |
1197
+ * |---|---|---|---| ---------------------------------------------------- |---------------|-------------|
1198
+ * | 0 | * | 0 | - | Start nav, target fits | null | current |
1199
+ * | 0 | * | 1 | - | Start nav, target shorter | current | target end |
1200
+ * | 1 | 0 | 0 | 0 | Clamped, target fits preferred | null | preferred |
1201
+ * | 1 | 0 | 0 | 1 | Clamped, target longer but still can't fit preferred | keep | target end |
1202
+ * | 1 | 0 | 1 | - | Clamped, target even shorter | keep | target end |
1203
+ * | 1 | 1 | 0 | - | Rewrapped, target fits current | null | current |
1204
+ * | 1 | 1 | 1 | - | Rewrapped, target shorter than current | current | target end |
1205
+ *
1206
+ * Where:
1207
+ * - P = preferred col is set
1208
+ * - S = cursor in middle of source line (not clamped to end)
1209
+ * - T = target line shorter than current visual col
1210
+ * - U = target line shorter than preferred col
1211
+ */
1212
+ computeVerticalMoveColumn(currentVisualCol, sourceMaxVisualCol, targetMaxVisualCol) {
1213
+ const hasPreferred = this.preferredVisualCol !== null; // P
1214
+ const cursorInMiddle = currentVisualCol < sourceMaxVisualCol; // S
1215
+ const targetTooShort = targetMaxVisualCol < currentVisualCol; // T
1216
+ if (!hasPreferred || cursorInMiddle) {
1217
+ if (targetTooShort) {
1218
+ // Cases 2 and 7
1219
+ this.preferredVisualCol = currentVisualCol;
1220
+ return targetMaxVisualCol;
1221
+ }
1222
+ // Cases 1 and 6
1223
+ this.preferredVisualCol = null;
1224
+ return currentVisualCol;
1225
+ }
1226
+ const targetCantFitPreferred = targetMaxVisualCol < this.preferredVisualCol; // U
1227
+ if (targetTooShort || targetCantFitPreferred) {
1228
+ // Cases 4 and 5
1229
+ return targetMaxVisualCol;
1230
+ }
1231
+ // Case 3
1232
+ const result = this.preferredVisualCol;
1233
+ this.preferredVisualCol = null;
1234
+ return result;
1235
+ }
1236
+ moveToLineStart() {
1237
+ this.lastAction = null;
1238
+ this.setCursorCol(0);
1239
+ }
1240
+ moveToLineEnd() {
1241
+ this.lastAction = null;
1242
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1243
+ this.setCursorCol(currentLine.length);
1244
+ }
1245
+ deleteToStartOfLine() {
1246
+ this.exitHistoryBrowsing();
1247
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1248
+ if (this.state.cursorCol > 0) {
1249
+ this.pushUndoSnapshot();
1250
+ // Calculate text to be deleted and save to kill ring (backward deletion = prepend)
1251
+ const deletedText = currentLine.slice(0, this.state.cursorCol);
1252
+ this.killRing.push(deletedText, { prepend: true, accumulate: this.lastAction === "kill" });
1253
+ this.lastAction = "kill";
1254
+ // Delete from start of line up to cursor
1255
+ this.state.lines[this.state.cursorLine] = currentLine.slice(this.state.cursorCol);
1256
+ this.setCursorCol(0);
1257
+ }
1258
+ else if (this.state.cursorLine > 0) {
1259
+ this.pushUndoSnapshot();
1260
+ // At start of line - merge with previous line, treating newline as deleted text
1261
+ this.killRing.push("\n", { prepend: true, accumulate: this.lastAction === "kill" });
1262
+ this.lastAction = "kill";
1263
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1264
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1265
+ this.state.lines.splice(this.state.cursorLine, 1);
1266
+ this.state.cursorLine--;
1267
+ this.setCursorCol(previousLine.length);
1268
+ }
1269
+ if (this.onChange) {
1270
+ this.onChange(this.getText());
1271
+ }
1272
+ }
1273
+ deleteToEndOfLine() {
1274
+ this.exitHistoryBrowsing();
1275
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1276
+ if (this.state.cursorCol < currentLine.length) {
1277
+ this.pushUndoSnapshot();
1278
+ // Calculate text to be deleted and save to kill ring (forward deletion = append)
1279
+ const deletedText = currentLine.slice(this.state.cursorCol);
1280
+ this.killRing.push(deletedText, { prepend: false, accumulate: this.lastAction === "kill" });
1281
+ this.lastAction = "kill";
1282
+ // Delete from cursor to end of line
1283
+ this.state.lines[this.state.cursorLine] = currentLine.slice(0, this.state.cursorCol);
1284
+ }
1285
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1286
+ this.pushUndoSnapshot();
1287
+ // At end of line - merge with next line, treating newline as deleted text
1288
+ this.killRing.push("\n", { prepend: false, accumulate: this.lastAction === "kill" });
1289
+ this.lastAction = "kill";
1290
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1291
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1292
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1293
+ }
1294
+ if (this.onChange) {
1295
+ this.onChange(this.getText());
1296
+ }
1297
+ }
1298
+ deleteWordBackwards() {
1299
+ this.exitHistoryBrowsing();
1300
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1301
+ // If at start of line, behave like backspace at column 0 (merge with previous line)
1302
+ if (this.state.cursorCol === 0) {
1303
+ if (this.state.cursorLine > 0) {
1304
+ this.pushUndoSnapshot();
1305
+ // Treat newline as deleted text (backward deletion = prepend)
1306
+ this.killRing.push("\n", { prepend: true, accumulate: this.lastAction === "kill" });
1307
+ this.lastAction = "kill";
1308
+ const previousLine = this.state.lines[this.state.cursorLine - 1] || "";
1309
+ this.state.lines[this.state.cursorLine - 1] = previousLine + currentLine;
1310
+ this.state.lines.splice(this.state.cursorLine, 1);
1311
+ this.state.cursorLine--;
1312
+ this.setCursorCol(previousLine.length);
1313
+ }
1314
+ }
1315
+ else {
1316
+ this.pushUndoSnapshot();
1317
+ // Save lastAction before cursor movement (moveWordBackwards resets it)
1318
+ const wasKill = this.lastAction === "kill";
1319
+ const oldCursorCol = this.state.cursorCol;
1320
+ this.moveWordBackwards();
1321
+ const deleteFrom = this.state.cursorCol;
1322
+ this.setCursorCol(oldCursorCol);
1323
+ const deletedText = currentLine.slice(deleteFrom, this.state.cursorCol);
1324
+ this.killRing.push(deletedText, { prepend: true, accumulate: wasKill });
1325
+ this.lastAction = "kill";
1326
+ this.state.lines[this.state.cursorLine] =
1327
+ currentLine.slice(0, deleteFrom) + currentLine.slice(this.state.cursorCol);
1328
+ this.setCursorCol(deleteFrom);
1329
+ }
1330
+ if (this.onChange) {
1331
+ this.onChange(this.getText());
1332
+ }
1333
+ }
1334
+ deleteWordForward() {
1335
+ this.exitHistoryBrowsing();
1336
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1337
+ // If at end of line, merge with next line (delete the newline)
1338
+ if (this.state.cursorCol >= currentLine.length) {
1339
+ if (this.state.cursorLine < this.state.lines.length - 1) {
1340
+ this.pushUndoSnapshot();
1341
+ // Treat newline as deleted text (forward deletion = append)
1342
+ this.killRing.push("\n", { prepend: false, accumulate: this.lastAction === "kill" });
1343
+ this.lastAction = "kill";
1344
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1345
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1346
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1347
+ }
1348
+ }
1349
+ else {
1350
+ this.pushUndoSnapshot();
1351
+ // Save lastAction before cursor movement (moveWordForwards resets it)
1352
+ const wasKill = this.lastAction === "kill";
1353
+ const oldCursorCol = this.state.cursorCol;
1354
+ this.moveWordForwards();
1355
+ const deleteTo = this.state.cursorCol;
1356
+ this.setCursorCol(oldCursorCol);
1357
+ const deletedText = currentLine.slice(this.state.cursorCol, deleteTo);
1358
+ this.killRing.push(deletedText, { prepend: false, accumulate: wasKill });
1359
+ this.lastAction = "kill";
1360
+ this.state.lines[this.state.cursorLine] =
1361
+ currentLine.slice(0, this.state.cursorCol) + currentLine.slice(deleteTo);
1362
+ }
1363
+ if (this.onChange) {
1364
+ this.onChange(this.getText());
1365
+ }
1366
+ }
1367
+ handleForwardDelete() {
1368
+ this.exitHistoryBrowsing();
1369
+ this.lastAction = null;
1370
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1371
+ if (this.state.cursorCol < currentLine.length) {
1372
+ this.pushUndoSnapshot();
1373
+ // Delete grapheme at cursor position (handles emojis, combining characters, etc.)
1374
+ const afterCursor = currentLine.slice(this.state.cursorCol);
1375
+ // Find the first grapheme at cursor
1376
+ const graphemes = [...this.segment(afterCursor, "grapheme")];
1377
+ const firstGrapheme = graphemes[0];
1378
+ const graphemeLength = firstGrapheme ? firstGrapheme.segment.length : 1;
1379
+ const before = currentLine.slice(0, this.state.cursorCol);
1380
+ const after = currentLine.slice(this.state.cursorCol + graphemeLength);
1381
+ this.state.lines[this.state.cursorLine] = before + after;
1382
+ }
1383
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1384
+ this.pushUndoSnapshot();
1385
+ // At end of line - merge with next line
1386
+ const nextLine = this.state.lines[this.state.cursorLine + 1] || "";
1387
+ this.state.lines[this.state.cursorLine] = currentLine + nextLine;
1388
+ this.state.lines.splice(this.state.cursorLine + 1, 1);
1389
+ }
1390
+ if (this.onChange) {
1391
+ this.onChange(this.getText());
1392
+ }
1393
+ // Update or re-trigger autocomplete after forward delete
1394
+ if (this.autocompleteState) {
1395
+ this.updateAutocomplete();
1396
+ }
1397
+ else {
1398
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1399
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1400
+ // Slash command context
1401
+ if (this.isInSlashCommandContext(textBeforeCursor)) {
1402
+ this.tryTriggerAutocomplete();
1403
+ }
1404
+ // Symbol-based completion context like @, #, or provider triggers
1405
+ else if (this.autocompleteTriggerPattern.test(textBeforeCursor)) {
1406
+ this.tryTriggerAutocomplete();
1407
+ }
1408
+ }
1409
+ }
1410
+ /**
1411
+ * Build a mapping from visual lines to logical positions.
1412
+ * Returns an array where each element represents a visual line with:
1413
+ * - logicalLine: index into this.state.lines
1414
+ * - startCol: starting column in the logical line
1415
+ * - length: length of this visual line segment
1416
+ */
1417
+ buildVisualLineMap(width) {
1418
+ const visualLines = [];
1419
+ for (let i = 0; i < this.state.lines.length; i++) {
1420
+ const line = this.state.lines[i] || "";
1421
+ const lineVisWidth = visibleWidth(line);
1422
+ if (line.length === 0) {
1423
+ // Empty line still takes one visual line
1424
+ visualLines.push({ logicalLine: i, startCol: 0, length: 0 });
1425
+ }
1426
+ else if (lineVisWidth <= width) {
1427
+ visualLines.push({ logicalLine: i, startCol: 0, length: line.length });
1428
+ }
1429
+ else {
1430
+ // Line needs wrapping - use word-aware wrapping
1431
+ const chunks = wordWrapLine(line, width, [...this.segment(line, "grapheme")]);
1432
+ for (const chunk of chunks) {
1433
+ visualLines.push({
1434
+ logicalLine: i,
1435
+ startCol: chunk.startIndex,
1436
+ length: chunk.endIndex - chunk.startIndex,
1437
+ });
1438
+ }
1439
+ }
1440
+ }
1441
+ return visualLines;
1442
+ }
1443
+ /**
1444
+ * Find the visual line index that contains the given logical position.
1445
+ */
1446
+ findVisualLineAt(visualLines, line, col) {
1447
+ for (let i = 0; i < visualLines.length; i++) {
1448
+ const vl = visualLines[i];
1449
+ if (!vl || vl.logicalLine !== line)
1450
+ continue;
1451
+ const offset = col - vl.startCol;
1452
+ // Cursor is in this segment if it's within range. For the last
1453
+ // segment of a logical line, cursor can be at length (end position)
1454
+ const isLastSegmentOfLine = i === visualLines.length - 1 || visualLines[i + 1]?.logicalLine !== vl.logicalLine;
1455
+ if (offset >= 0 && (offset < vl.length || (isLastSegmentOfLine && offset === vl.length))) {
1456
+ return i;
1457
+ }
1458
+ }
1459
+ return visualLines.length - 1;
1460
+ }
1461
+ /**
1462
+ * Find the visual line index for the current cursor position.
1463
+ */
1464
+ findCurrentVisualLine(visualLines) {
1465
+ return this.findVisualLineAt(visualLines, this.state.cursorLine, this.state.cursorCol);
1466
+ }
1467
+ moveCursor(deltaLine, deltaCol) {
1468
+ this.lastAction = null;
1469
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
1470
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
1471
+ if (deltaLine !== 0) {
1472
+ const targetVisualLine = currentVisualLine + deltaLine;
1473
+ if (targetVisualLine >= 0 && targetVisualLine < visualLines.length) {
1474
+ this.moveToVisualLine(visualLines, currentVisualLine, targetVisualLine);
1475
+ }
1476
+ }
1477
+ if (deltaCol !== 0) {
1478
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1479
+ if (deltaCol > 0) {
1480
+ // Moving right - move by one grapheme (handles emojis, combining characters, etc.)
1481
+ if (this.state.cursorCol < currentLine.length) {
1482
+ const afterCursor = currentLine.slice(this.state.cursorCol);
1483
+ const graphemes = [...this.segment(afterCursor, "grapheme")];
1484
+ const firstGrapheme = graphemes[0];
1485
+ this.setCursorCol(this.state.cursorCol + (firstGrapheme ? firstGrapheme.segment.length : 1));
1486
+ }
1487
+ else if (this.state.cursorLine < this.state.lines.length - 1) {
1488
+ // Wrap to start of next logical line
1489
+ this.state.cursorLine++;
1490
+ this.setCursorCol(0);
1491
+ }
1492
+ else {
1493
+ // At end of last line - can't move, but set preferredVisualCol for up/down navigation
1494
+ const currentVL = visualLines[currentVisualLine];
1495
+ if (currentVL) {
1496
+ this.preferredVisualCol = this.state.cursorCol - currentVL.startCol;
1497
+ }
1498
+ }
1499
+ }
1500
+ else {
1501
+ // Moving left - move by one grapheme (handles emojis, combining characters, etc.)
1502
+ if (this.state.cursorCol > 0) {
1503
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1504
+ const graphemes = [...this.segment(beforeCursor, "grapheme")];
1505
+ const lastGrapheme = graphemes[graphemes.length - 1];
1506
+ this.setCursorCol(this.state.cursorCol - (lastGrapheme ? lastGrapheme.segment.length : 1));
1507
+ }
1508
+ else if (this.state.cursorLine > 0) {
1509
+ // Wrap to end of previous logical line
1510
+ this.state.cursorLine--;
1511
+ const prevLine = this.state.lines[this.state.cursorLine] || "";
1512
+ this.setCursorCol(prevLine.length);
1513
+ }
1514
+ }
1515
+ }
1516
+ // Keep an open autocomplete picker in sync with the new cursor
1517
+ // position: cursor movement changes the text before the cursor, so a
1518
+ // picker computed for the old position is stale. Re-query so it
1519
+ // refreshes — or closes when the new position yields no suggestions —
1520
+ // mirroring insertCharacter()/handleBackspace(). Without this, arrowing
1521
+ // left from `/cmd ` back into the command name leaves the argument
1522
+ // picker showing against a `/cmd` prefix (and a Tab there would
1523
+ // concatenate the stale suggestion onto the partial command name).
1524
+ if (this.autocompleteState) {
1525
+ this.updateAutocomplete();
1526
+ }
1527
+ }
1528
+ /**
1529
+ * Scroll by a page (direction: -1 for up, 1 for down).
1530
+ * Moves cursor by the page size while keeping it in bounds.
1531
+ */
1532
+ pageScroll(direction) {
1533
+ this.lastAction = null;
1534
+ const terminalRows = this.tui.terminal.rows;
1535
+ const pageSize = Math.max(5, Math.floor(terminalRows * 0.3));
1536
+ const visualLines = this.buildVisualLineMap(this.lastWidth);
1537
+ const currentVisualLine = this.findCurrentVisualLine(visualLines);
1538
+ const targetVisualLine = Math.max(0, Math.min(visualLines.length - 1, currentVisualLine + direction * pageSize));
1539
+ this.moveToVisualLine(visualLines, currentVisualLine, targetVisualLine);
1540
+ }
1541
+ moveWordBackwards() {
1542
+ this.lastAction = null;
1543
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1544
+ // If at start of line, move to end of previous line
1545
+ if (this.state.cursorCol === 0) {
1546
+ if (this.state.cursorLine > 0) {
1547
+ this.state.cursorLine--;
1548
+ const prevLine = this.state.lines[this.state.cursorLine] || "";
1549
+ this.setCursorCol(prevLine.length);
1550
+ }
1551
+ return;
1552
+ }
1553
+ this.setCursorCol(findWordBackward(currentLine, this.state.cursorCol, {
1554
+ segment: (text) => this.segment(text, "word"),
1555
+ isAtomicSegment: isPasteMarker,
1556
+ }));
1557
+ }
1558
+ /**
1559
+ * Yank (paste) the most recent kill ring entry at cursor position.
1560
+ */
1561
+ yank() {
1562
+ if (this.killRing.length === 0)
1563
+ return;
1564
+ this.pushUndoSnapshot();
1565
+ const text = this.killRing.peek();
1566
+ this.insertYankedText(text);
1567
+ this.lastAction = "yank";
1568
+ }
1569
+ /**
1570
+ * Cycle through kill ring (only works immediately after yank or yank-pop).
1571
+ * Replaces the last yanked text with the previous entry in the ring.
1572
+ */
1573
+ yankPop() {
1574
+ // Only works if we just yanked and have more than one entry
1575
+ if (this.lastAction !== "yank" || this.killRing.length <= 1)
1576
+ return;
1577
+ this.pushUndoSnapshot();
1578
+ // Delete the previously yanked text (still at end of ring before rotation)
1579
+ this.deleteYankedText();
1580
+ // Rotate the ring: move end to front
1581
+ this.killRing.rotate();
1582
+ // Insert the new most recent entry (now at end after rotation)
1583
+ const text = this.killRing.peek();
1584
+ this.insertYankedText(text);
1585
+ this.lastAction = "yank";
1586
+ }
1587
+ /**
1588
+ * Insert text at cursor position (used by yank operations).
1589
+ */
1590
+ insertYankedText(text) {
1591
+ this.exitHistoryBrowsing();
1592
+ const lines = text.split("\n");
1593
+ if (lines.length === 1) {
1594
+ // Single line - insert at cursor
1595
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1596
+ const before = currentLine.slice(0, this.state.cursorCol);
1597
+ const after = currentLine.slice(this.state.cursorCol);
1598
+ this.state.lines[this.state.cursorLine] = before + text + after;
1599
+ this.setCursorCol(this.state.cursorCol + text.length);
1600
+ }
1601
+ else {
1602
+ // Multi-line insert
1603
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1604
+ const before = currentLine.slice(0, this.state.cursorCol);
1605
+ const after = currentLine.slice(this.state.cursorCol);
1606
+ // First line merges with text before cursor
1607
+ this.state.lines[this.state.cursorLine] = before + (lines[0] || "");
1608
+ // Insert middle lines
1609
+ for (let i = 1; i < lines.length - 1; i++) {
1610
+ this.state.lines.splice(this.state.cursorLine + i, 0, lines[i] || "");
1611
+ }
1612
+ // Last line merges with text after cursor
1613
+ const lastLineIndex = this.state.cursorLine + lines.length - 1;
1614
+ this.state.lines.splice(lastLineIndex, 0, (lines[lines.length - 1] || "") + after);
1615
+ // Update cursor position
1616
+ this.state.cursorLine = lastLineIndex;
1617
+ this.setCursorCol((lines[lines.length - 1] || "").length);
1618
+ }
1619
+ if (this.onChange) {
1620
+ this.onChange(this.getText());
1621
+ }
1622
+ }
1623
+ /**
1624
+ * Delete the previously yanked text (used by yank-pop).
1625
+ * The yanked text is derived from killRing[end] since it hasn't been rotated yet.
1626
+ */
1627
+ deleteYankedText() {
1628
+ const yankedText = this.killRing.peek();
1629
+ if (!yankedText)
1630
+ return;
1631
+ const yankLines = yankedText.split("\n");
1632
+ if (yankLines.length === 1) {
1633
+ // Single line - delete backward from cursor
1634
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1635
+ const deleteLen = yankedText.length;
1636
+ const before = currentLine.slice(0, this.state.cursorCol - deleteLen);
1637
+ const after = currentLine.slice(this.state.cursorCol);
1638
+ this.state.lines[this.state.cursorLine] = before + after;
1639
+ this.setCursorCol(this.state.cursorCol - deleteLen);
1640
+ }
1641
+ else {
1642
+ // Multi-line delete - cursor is at end of last yanked line
1643
+ const startLine = this.state.cursorLine - (yankLines.length - 1);
1644
+ const startCol = (this.state.lines[startLine] || "").length - (yankLines[0] || "").length;
1645
+ // Get text after cursor on current line
1646
+ const afterCursor = (this.state.lines[this.state.cursorLine] || "").slice(this.state.cursorCol);
1647
+ // Get text before yank start position
1648
+ const beforeYank = (this.state.lines[startLine] || "").slice(0, startCol);
1649
+ // Remove all lines from startLine to cursorLine and replace with merged line
1650
+ this.state.lines.splice(startLine, yankLines.length, beforeYank + afterCursor);
1651
+ // Update cursor
1652
+ this.state.cursorLine = startLine;
1653
+ this.setCursorCol(startCol);
1654
+ }
1655
+ if (this.onChange) {
1656
+ this.onChange(this.getText());
1657
+ }
1658
+ }
1659
+ pushUndoSnapshot() {
1660
+ this.undoStack.push(this.state);
1661
+ }
1662
+ undo() {
1663
+ this.exitHistoryBrowsing();
1664
+ const snapshot = this.undoStack.pop();
1665
+ if (!snapshot)
1666
+ return;
1667
+ Object.assign(this.state, snapshot);
1668
+ this.lastAction = null;
1669
+ this.preferredVisualCol = null;
1670
+ if (this.onChange) {
1671
+ this.onChange(this.getText());
1672
+ }
1673
+ }
1674
+ /**
1675
+ * Jump to the first occurrence of a character in the specified direction.
1676
+ * Multi-line search. Case-sensitive. Skips the current cursor position.
1677
+ */
1678
+ jumpToChar(char, direction) {
1679
+ this.lastAction = null;
1680
+ const isForward = direction === "forward";
1681
+ const lines = this.state.lines;
1682
+ const end = isForward ? lines.length : -1;
1683
+ const step = isForward ? 1 : -1;
1684
+ for (let lineIdx = this.state.cursorLine; lineIdx !== end; lineIdx += step) {
1685
+ const line = lines[lineIdx] || "";
1686
+ const isCurrentLine = lineIdx === this.state.cursorLine;
1687
+ // Current line: start after/before cursor; other lines: search full line
1688
+ const searchFrom = isCurrentLine
1689
+ ? isForward
1690
+ ? this.state.cursorCol + 1
1691
+ : this.state.cursorCol - 1
1692
+ : undefined;
1693
+ const idx = isForward ? line.indexOf(char, searchFrom) : line.lastIndexOf(char, searchFrom);
1694
+ if (idx !== -1) {
1695
+ this.state.cursorLine = lineIdx;
1696
+ this.setCursorCol(idx);
1697
+ return;
1698
+ }
1699
+ }
1700
+ // No match found - cursor stays in place
1701
+ }
1702
+ moveWordForwards() {
1703
+ this.lastAction = null;
1704
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1705
+ // If at end of line, move to start of next line
1706
+ if (this.state.cursorCol >= currentLine.length) {
1707
+ if (this.state.cursorLine < this.state.lines.length - 1) {
1708
+ this.state.cursorLine++;
1709
+ this.setCursorCol(0);
1710
+ }
1711
+ return;
1712
+ }
1713
+ this.setCursorCol(findWordForward(currentLine, this.state.cursorCol, {
1714
+ segment: (text) => this.segment(text, "word"),
1715
+ isAtomicSegment: isPasteMarker,
1716
+ }));
1717
+ }
1718
+ // Slash menu only allowed on the first line of the editor
1719
+ isSlashMenuAllowed() {
1720
+ return this.state.cursorLine === 0;
1721
+ }
1722
+ // Helper method to check if cursor is at start of message (for slash command detection)
1723
+ isAtStartOfMessage() {
1724
+ if (!this.isSlashMenuAllowed())
1725
+ return false;
1726
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1727
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1728
+ return beforeCursor.trim() === "" || beforeCursor.trim() === "/";
1729
+ }
1730
+ isInSlashCommandContext(textBeforeCursor) {
1731
+ return this.isSlashMenuAllowed() && textBeforeCursor.trimStart().startsWith("/");
1732
+ }
1733
+ // Autocomplete methods
1734
+ /**
1735
+ * Find the best autocomplete item index for the given prefix.
1736
+ * Returns -1 if no match is found.
1737
+ *
1738
+ * Match priority:
1739
+ * 1. Exact match (prefix === item.value) -> always selected
1740
+ * 2. Prefix match -> first item whose value starts with prefix
1741
+ * 3. No match -> -1 (keep default highlight)
1742
+ *
1743
+ * Matching is case-sensitive and checks item.value only.
1744
+ */
1745
+ getBestAutocompleteMatchIndex(items, prefix) {
1746
+ if (!prefix)
1747
+ return -1;
1748
+ let firstPrefixIndex = -1;
1749
+ for (let i = 0; i < items.length; i++) {
1750
+ const value = items[i].value;
1751
+ if (value === prefix) {
1752
+ return i; // Exact match always wins
1753
+ }
1754
+ if (firstPrefixIndex === -1 && value.startsWith(prefix)) {
1755
+ firstPrefixIndex = i;
1756
+ }
1757
+ }
1758
+ return firstPrefixIndex;
1759
+ }
1760
+ createAutocompleteList(prefix, items) {
1761
+ const layout = prefix.startsWith("/") ? SLASH_COMMAND_SELECT_LIST_LAYOUT : undefined;
1762
+ return new SelectList(items, this.autocompleteMaxVisible, this.theme.selectList, layout);
1763
+ }
1764
+ tryTriggerAutocomplete(explicitTab = false) {
1765
+ this.requestAutocomplete({ force: false, explicitTab });
1766
+ }
1767
+ handleTabCompletion() {
1768
+ if (!this.autocompleteProvider)
1769
+ return;
1770
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1771
+ const beforeCursor = currentLine.slice(0, this.state.cursorCol);
1772
+ if (this.isInSlashCommandContext(beforeCursor) && !beforeCursor.trimStart().includes(" ")) {
1773
+ this.handleSlashCommandCompletion();
1774
+ }
1775
+ else {
1776
+ this.forceFileAutocomplete(true);
1777
+ }
1778
+ }
1779
+ handleSlashCommandCompletion() {
1780
+ this.requestAutocomplete({ force: false, explicitTab: true });
1781
+ }
1782
+ forceFileAutocomplete(explicitTab = false) {
1783
+ this.requestAutocomplete({ force: true, explicitTab });
1784
+ }
1785
+ requestAutocomplete(options) {
1786
+ if (!this.autocompleteProvider)
1787
+ return;
1788
+ if (options.force) {
1789
+ const shouldTrigger = !this.autocompleteProvider.shouldTriggerFileCompletion ||
1790
+ this.autocompleteProvider.shouldTriggerFileCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol);
1791
+ if (!shouldTrigger) {
1792
+ return;
1793
+ }
1794
+ }
1795
+ this.cancelAutocompleteRequest();
1796
+ const startToken = ++this.autocompleteStartToken;
1797
+ const debounceMs = this.getAutocompleteDebounceMs(options);
1798
+ if (debounceMs > 0) {
1799
+ this.autocompleteDebounceTimer = setTimeout(() => {
1800
+ this.autocompleteDebounceTimer = undefined;
1801
+ void this.startAutocompleteRequest(startToken, options);
1802
+ }, debounceMs);
1803
+ return;
1804
+ }
1805
+ void this.startAutocompleteRequest(startToken, options);
1806
+ }
1807
+ async startAutocompleteRequest(startToken, options) {
1808
+ const previousTask = this.autocompleteRequestTask;
1809
+ this.autocompleteRequestTask = (async () => {
1810
+ await previousTask;
1811
+ if (startToken !== this.autocompleteStartToken || !this.autocompleteProvider) {
1812
+ return;
1813
+ }
1814
+ const controller = new AbortController();
1815
+ this.autocompleteAbort = controller;
1816
+ const requestId = ++this.autocompleteRequestId;
1817
+ const snapshotText = this.getText();
1818
+ const snapshotLine = this.state.cursorLine;
1819
+ const snapshotCol = this.state.cursorCol;
1820
+ await this.runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options);
1821
+ })();
1822
+ await this.autocompleteRequestTask;
1823
+ }
1824
+ setAutocompleteTriggerCharacters(triggerCharacters) {
1825
+ const next = [...DEFAULT_AUTOCOMPLETE_TRIGGER_CHARACTERS];
1826
+ for (const character of triggerCharacters) {
1827
+ if (character.length !== 1 || character === "/" || isWhitespaceChar(character) || next.includes(character)) {
1828
+ continue;
1829
+ }
1830
+ next.push(character);
1831
+ }
1832
+ this.autocompleteTriggerCharacters = next;
1833
+ this.autocompleteTriggerPattern = buildTriggerPattern(next);
1834
+ this.autocompleteDebouncePattern = buildDebouncePattern(next);
1835
+ }
1836
+ getAutocompleteDebounceMs(options) {
1837
+ if (options.explicitTab || options.force) {
1838
+ return 0;
1839
+ }
1840
+ const currentLine = this.state.lines[this.state.cursorLine] || "";
1841
+ const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
1842
+ return this.autocompleteDebouncePattern.test(textBeforeCursor) ? ATTACHMENT_AUTOCOMPLETE_DEBOUNCE_MS : 0;
1843
+ }
1844
+ async runAutocompleteRequest(requestId, controller, snapshotText, snapshotLine, snapshotCol, options) {
1845
+ if (!this.autocompleteProvider)
1846
+ return;
1847
+ const suggestions = await this.autocompleteProvider.getSuggestions(this.state.lines, this.state.cursorLine, this.state.cursorCol, { signal: controller.signal, force: options.force });
1848
+ if (!this.isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol)) {
1849
+ return;
1850
+ }
1851
+ this.autocompleteAbort = undefined;
1852
+ if (!suggestions || !Array.isArray(suggestions.items) || suggestions.items.length === 0) {
1853
+ this.cancelAutocomplete();
1854
+ this.tui.requestRender();
1855
+ return;
1856
+ }
1857
+ if (options.force && options.explicitTab && suggestions.items.length === 1) {
1858
+ const item = suggestions.items[0];
1859
+ this.pushUndoSnapshot();
1860
+ this.lastAction = null;
1861
+ const result = this.autocompleteProvider.applyCompletion(this.state.lines, this.state.cursorLine, this.state.cursorCol, item, suggestions.prefix);
1862
+ this.state.lines = result.lines;
1863
+ this.state.cursorLine = result.cursorLine;
1864
+ this.setCursorCol(result.cursorCol);
1865
+ if (this.onChange)
1866
+ this.onChange(this.getText());
1867
+ this.tui.requestRender();
1868
+ return;
1869
+ }
1870
+ this.applyAutocompleteSuggestions(suggestions, options.force ? "force" : "regular");
1871
+ this.tui.requestRender();
1872
+ }
1873
+ isAutocompleteRequestCurrent(requestId, controller, snapshotText, snapshotLine, snapshotCol) {
1874
+ return (!controller.signal.aborted &&
1875
+ requestId === this.autocompleteRequestId &&
1876
+ this.getText() === snapshotText &&
1877
+ this.state.cursorLine === snapshotLine &&
1878
+ this.state.cursorCol === snapshotCol);
1879
+ }
1880
+ applyAutocompleteSuggestions(suggestions, state) {
1881
+ this.autocompletePrefix = suggestions.prefix;
1882
+ this.autocompleteList = this.createAutocompleteList(suggestions.prefix, suggestions.items);
1883
+ const bestMatchIndex = this.getBestAutocompleteMatchIndex(suggestions.items, suggestions.prefix);
1884
+ if (bestMatchIndex >= 0) {
1885
+ this.autocompleteList.setSelectedIndex(bestMatchIndex);
1886
+ }
1887
+ this.autocompleteState = state;
1888
+ }
1889
+ cancelAutocompleteRequest() {
1890
+ this.autocompleteStartToken += 1;
1891
+ if (this.autocompleteDebounceTimer) {
1892
+ clearTimeout(this.autocompleteDebounceTimer);
1893
+ this.autocompleteDebounceTimer = undefined;
1894
+ }
1895
+ this.autocompleteAbort?.abort();
1896
+ this.autocompleteAbort = undefined;
1897
+ }
1898
+ clearAutocompleteUi() {
1899
+ this.autocompleteState = null;
1900
+ this.autocompleteList = undefined;
1901
+ this.autocompletePrefix = "";
1902
+ }
1903
+ cancelAutocomplete() {
1904
+ this.cancelAutocompleteRequest();
1905
+ this.clearAutocompleteUi();
1906
+ }
1907
+ isShowingAutocomplete() {
1908
+ return this.autocompleteState !== null;
1909
+ }
1910
+ updateAutocomplete() {
1911
+ if (!this.autocompleteState || !this.autocompleteProvider)
1912
+ return;
1913
+ this.requestAutocomplete({ force: this.autocompleteState === "force", explicitTab: false });
1914
+ }
1915
+ }
1916
+ //# sourceMappingURL=editor.js.map