@dungle-scrubs/tallow 0.8.21 → 0.8.23

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