@vybestack/llxprt-code 0.1.14 → 0.1.16

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 (238) hide show
  1. package/README.md +90 -2
  2. package/dist/package.json +4 -5
  3. package/dist/src/config/config.d.ts +4 -1
  4. package/dist/src/config/config.js +151 -54
  5. package/dist/src/config/config.js.map +1 -1
  6. package/dist/src/config/extension.d.ts +1 -0
  7. package/dist/src/config/extension.js +4 -0
  8. package/dist/src/config/extension.js.map +1 -1
  9. package/dist/src/config/settings.d.ts +13 -3
  10. package/dist/src/config/settings.js +84 -23
  11. package/dist/src/config/settings.js.map +1 -1
  12. package/dist/src/gemini.d.ts +3 -0
  13. package/dist/src/gemini.js +212 -36
  14. package/dist/src/gemini.js.map +1 -1
  15. package/dist/src/generated/git-commit.d.ts +1 -1
  16. package/dist/src/generated/git-commit.js +1 -1
  17. package/dist/src/generated/git-commit.js.map +1 -1
  18. package/dist/src/integration-tests/GITHUB_ACTIONS_README.md +41 -0
  19. package/dist/src/integration-tests/test-utils.d.ts +68 -0
  20. package/dist/src/integration-tests/test-utils.js +167 -0
  21. package/dist/src/integration-tests/test-utils.js.map +1 -0
  22. package/dist/src/nonInteractiveCli.js +24 -66
  23. package/dist/src/nonInteractiveCli.js.map +1 -1
  24. package/dist/src/providers/IFileSystem.d.ts +42 -0
  25. package/dist/src/providers/IFileSystem.js +46 -0
  26. package/dist/src/providers/IFileSystem.js.map +1 -0
  27. package/dist/src/providers/providerConfigUtils.d.ts +0 -4
  28. package/dist/src/providers/providerConfigUtils.js +21 -52
  29. package/dist/src/providers/providerConfigUtils.js.map +1 -1
  30. package/dist/src/providers/providerManagerInstance.d.ts +6 -1
  31. package/dist/src/providers/providerManagerInstance.js +117 -82
  32. package/dist/src/providers/providerManagerInstance.js.map +1 -1
  33. package/dist/src/services/BuiltinCommandLoader.js +13 -0
  34. package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
  35. package/dist/src/services/CommandService.d.ts +8 -4
  36. package/dist/src/services/CommandService.js +24 -8
  37. package/dist/src/services/CommandService.js.map +1 -1
  38. package/dist/src/services/FileCommandLoader.d.ts +15 -3
  39. package/dist/src/services/FileCommandLoader.js +94 -42
  40. package/dist/src/services/FileCommandLoader.js.map +1 -1
  41. package/dist/src/services/McpPromptLoader.d.ts +25 -0
  42. package/dist/src/services/McpPromptLoader.js +192 -0
  43. package/dist/src/services/McpPromptLoader.js.map +1 -0
  44. package/dist/src/services/prompt-processors/shellProcessor.d.ts +32 -0
  45. package/dist/src/services/prompt-processors/shellProcessor.js +77 -0
  46. package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -0
  47. package/dist/src/services/prompt-processors/types.d.ts +4 -0
  48. package/dist/src/services/prompt-processors/types.js +4 -0
  49. package/dist/src/services/prompt-processors/types.js.map +1 -1
  50. package/dist/src/ui/App.js +325 -195
  51. package/dist/src/ui/App.js.map +1 -1
  52. package/dist/src/ui/commands/aboutCommand.js +2 -5
  53. package/dist/src/ui/commands/aboutCommand.js.map +1 -1
  54. package/dist/src/ui/commands/baseurlCommand.js +54 -9
  55. package/dist/src/ui/commands/baseurlCommand.js.map +1 -1
  56. package/dist/src/ui/commands/chatCommand.js +39 -1
  57. package/dist/src/ui/commands/chatCommand.js.map +1 -1
  58. package/dist/src/ui/commands/diagnosticsCommand.d.ts +10 -0
  59. package/dist/src/ui/commands/diagnosticsCommand.js +122 -0
  60. package/dist/src/ui/commands/diagnosticsCommand.js.map +1 -0
  61. package/dist/src/ui/commands/directoryCommand.d.ts +8 -0
  62. package/dist/src/ui/commands/directoryCommand.js +116 -0
  63. package/dist/src/ui/commands/directoryCommand.js.map +1 -0
  64. package/dist/src/ui/commands/ideCommand.js +101 -105
  65. package/dist/src/ui/commands/ideCommand.js.map +1 -1
  66. package/dist/src/ui/commands/initCommand.d.ts +7 -0
  67. package/dist/src/ui/commands/initCommand.js +108 -0
  68. package/dist/src/ui/commands/initCommand.js.map +1 -0
  69. package/dist/src/ui/commands/keyCommand.js +75 -11
  70. package/dist/src/ui/commands/keyCommand.js.map +1 -1
  71. package/dist/src/ui/commands/keyfileCommand.js +54 -13
  72. package/dist/src/ui/commands/keyfileCommand.js.map +1 -1
  73. package/dist/src/ui/commands/mcpCommand.js +53 -8
  74. package/dist/src/ui/commands/mcpCommand.js.map +1 -1
  75. package/dist/src/ui/commands/memoryCommand.js +2 -1
  76. package/dist/src/ui/commands/memoryCommand.js.map +1 -1
  77. package/dist/src/ui/commands/modelCommand.js +2 -5
  78. package/dist/src/ui/commands/modelCommand.js.map +1 -1
  79. package/dist/src/ui/commands/profileCommand.d.ts +10 -0
  80. package/dist/src/ui/commands/profileCommand.js +592 -0
  81. package/dist/src/ui/commands/profileCommand.js.map +1 -0
  82. package/dist/src/ui/commands/providerCommand.js +46 -3
  83. package/dist/src/ui/commands/providerCommand.js.map +1 -1
  84. package/dist/src/ui/commands/setCommand.d.ts +7 -0
  85. package/dist/src/ui/commands/setCommand.js +431 -0
  86. package/dist/src/ui/commands/setCommand.js.map +1 -0
  87. package/dist/src/ui/commands/setupGithubCommand.d.ts +7 -0
  88. package/dist/src/ui/commands/setupGithubCommand.js +49 -0
  89. package/dist/src/ui/commands/setupGithubCommand.js.map +1 -0
  90. package/dist/src/ui/commands/types.d.ts +23 -4
  91. package/dist/src/ui/commands/types.js +1 -0
  92. package/dist/src/ui/commands/types.js.map +1 -1
  93. package/dist/src/ui/commands/vimCommand.js +0 -7
  94. package/dist/src/ui/commands/vimCommand.js.map +1 -1
  95. package/dist/src/ui/components/ContextSummaryDisplay.d.ts +3 -3
  96. package/dist/src/ui/components/ContextSummaryDisplay.js +8 -8
  97. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
  98. package/dist/src/ui/components/DebugProfiler.d.ts +6 -0
  99. package/dist/src/ui/components/DebugProfiler.js +26 -0
  100. package/dist/src/ui/components/DebugProfiler.js.map +1 -0
  101. package/dist/src/ui/components/Footer.d.ts +2 -0
  102. package/dist/src/ui/components/Footer.js +5 -4
  103. package/dist/src/ui/components/Footer.js.map +1 -1
  104. package/dist/src/ui/components/Header.js +1 -1
  105. package/dist/src/ui/components/Header.js.map +1 -1
  106. package/dist/src/ui/components/Help.js +2 -2
  107. package/dist/src/ui/components/Help.js.map +1 -1
  108. package/dist/src/ui/components/IDEContextDetailDisplay.d.ts +5 -4
  109. package/dist/src/ui/components/IDEContextDetailDisplay.js +6 -8
  110. package/dist/src/ui/components/IDEContextDetailDisplay.js.map +1 -1
  111. package/dist/src/ui/components/InputPrompt.d.ts +2 -0
  112. package/dist/src/ui/components/InputPrompt.js +128 -13
  113. package/dist/src/ui/components/InputPrompt.js.map +1 -1
  114. package/dist/src/ui/components/LoadProfileDialog.d.ts +13 -0
  115. package/dist/src/ui/components/LoadProfileDialog.js +57 -0
  116. package/dist/src/ui/components/LoadProfileDialog.js.map +1 -0
  117. package/dist/src/ui/components/PrepareLabel.d.ts +15 -0
  118. package/dist/src/ui/components/PrepareLabel.js +16 -0
  119. package/dist/src/ui/components/PrepareLabel.js.map +1 -0
  120. package/dist/src/ui/components/ProviderModelDialog.js +75 -28
  121. package/dist/src/ui/components/ProviderModelDialog.js.map +1 -1
  122. package/dist/src/ui/components/SecureKeyInput.d.ts +15 -0
  123. package/dist/src/ui/components/SecureKeyInput.js +58 -0
  124. package/dist/src/ui/components/SecureKeyInput.js.map +1 -0
  125. package/dist/src/ui/components/ShellConfirmationDialog.d.ts +15 -0
  126. package/dist/src/ui/components/ShellConfirmationDialog.js +45 -0
  127. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -0
  128. package/dist/src/ui/components/SuggestionsDisplay.d.ts +1 -0
  129. package/dist/src/ui/components/SuggestionsDisplay.js +3 -3
  130. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
  131. package/dist/src/ui/components/Tips.js +1 -1
  132. package/dist/src/ui/components/Tips.js.map +1 -1
  133. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +15 -4
  134. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
  135. package/dist/src/ui/components/messages/UserMessage.js +4 -1
  136. package/dist/src/ui/components/messages/UserMessage.js.map +1 -1
  137. package/dist/src/ui/components/shared/text-buffer.d.ts +270 -2
  138. package/dist/src/ui/components/shared/text-buffer.js +410 -70
  139. package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
  140. package/dist/src/ui/components/shared/vim-buffer-actions.d.ts +72 -0
  141. package/dist/src/ui/components/shared/vim-buffer-actions.js +565 -0
  142. package/dist/src/ui/components/shared/vim-buffer-actions.js.map +1 -0
  143. package/dist/src/ui/containers/SessionController.js +14 -15
  144. package/dist/src/ui/containers/SessionController.js.map +1 -1
  145. package/dist/src/ui/contexts/VimModeContext.js +2 -2
  146. package/dist/src/ui/contexts/VimModeContext.js.map +1 -1
  147. package/dist/src/ui/editors/editorSettingsManager.js +2 -0
  148. package/dist/src/ui/editors/editorSettingsManager.js.map +1 -1
  149. package/dist/src/ui/hooks/atCommandProcessor.js +56 -48
  150. package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -1
  151. package/dist/src/ui/hooks/shellCommandProcessor.d.ts +1 -0
  152. package/dist/src/ui/hooks/shellCommandProcessor.js +139 -200
  153. package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -1
  154. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +7 -3
  155. package/dist/src/ui/hooks/slashCommandProcessor.js +219 -130
  156. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
  157. package/dist/src/ui/hooks/useAuthCommand.js +9 -0
  158. package/dist/src/ui/hooks/useAuthCommand.js.map +1 -1
  159. package/dist/src/ui/hooks/useCompletion.d.ts +5 -5
  160. package/dist/src/ui/hooks/useCompletion.js +7 -402
  161. package/dist/src/ui/hooks/useCompletion.js.map +1 -1
  162. package/dist/src/ui/hooks/useConsoleMessages.js +53 -37
  163. package/dist/src/ui/hooks/useConsoleMessages.js.map +1 -1
  164. package/dist/src/ui/hooks/useGeminiStream.js +58 -12
  165. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
  166. package/dist/src/ui/hooks/useKeypress.js +5 -2
  167. package/dist/src/ui/hooks/useKeypress.js.map +1 -1
  168. package/dist/src/ui/hooks/useLoadProfileDialog.d.ts +27 -0
  169. package/dist/src/ui/hooks/useLoadProfileDialog.js +138 -0
  170. package/dist/src/ui/hooks/useLoadProfileDialog.js.map +1 -0
  171. package/dist/src/ui/hooks/useReactToolScheduler.js +0 -1
  172. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
  173. package/dist/src/ui/hooks/useReverseSearchCompletion.d.ts +19 -0
  174. package/dist/src/ui/hooks/useReverseSearchCompletion.js +54 -0
  175. package/dist/src/ui/hooks/useReverseSearchCompletion.js.map +1 -0
  176. package/dist/src/ui/hooks/useShellHistory.d.ts +1 -0
  177. package/dist/src/ui/hooks/useShellHistory.js +30 -7
  178. package/dist/src/ui/hooks/useShellHistory.js.map +1 -1
  179. package/dist/src/ui/hooks/useSlashCompletion.d.ts +24 -0
  180. package/dist/src/ui/hooks/useSlashCompletion.js +451 -0
  181. package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -0
  182. package/dist/src/ui/hooks/vim.d.ts +28 -0
  183. package/dist/src/ui/hooks/vim.js +630 -0
  184. package/dist/src/ui/hooks/vim.js.map +1 -0
  185. package/dist/src/ui/reducers/appReducer.d.ts +3 -2
  186. package/dist/src/ui/reducers/appReducer.js +1 -0
  187. package/dist/src/ui/reducers/appReducer.js.map +1 -1
  188. package/dist/src/ui/themes/theme-manager.js +10 -1
  189. package/dist/src/ui/themes/theme-manager.js.map +1 -1
  190. package/dist/src/ui/themes/theme.d.ts +1 -0
  191. package/dist/src/ui/themes/theme.js +19 -4
  192. package/dist/src/ui/themes/theme.js.map +1 -1
  193. package/dist/src/ui/utils/renderLoopDetector.js +3 -3
  194. package/dist/src/ui/utils/renderLoopDetector.js.map +1 -1
  195. package/dist/src/ui/utils/secureInputHandler.d.ts +46 -0
  196. package/dist/src/ui/utils/secureInputHandler.js +128 -0
  197. package/dist/src/ui/utils/secureInputHandler.js.map +1 -0
  198. package/dist/src/ui/utils/textUtils.d.ts +0 -8
  199. package/dist/src/ui/utils/textUtils.js +0 -22
  200. package/dist/src/ui/utils/textUtils.js.map +1 -1
  201. package/dist/src/ui/utils/updateCheck.d.ts +7 -1
  202. package/dist/src/ui/utils/updateCheck.js +59 -25
  203. package/dist/src/ui/utils/updateCheck.js.map +1 -1
  204. package/dist/src/utils/events.d.ts +11 -0
  205. package/dist/src/utils/events.js +13 -0
  206. package/dist/src/utils/events.js.map +1 -0
  207. package/dist/src/utils/gitUtils.d.ts +10 -0
  208. package/dist/src/utils/gitUtils.js +24 -0
  209. package/dist/src/utils/gitUtils.js.map +1 -0
  210. package/dist/src/utils/handleAutoUpdate.d.ts +11 -0
  211. package/dist/src/utils/handleAutoUpdate.js +101 -0
  212. package/dist/src/utils/handleAutoUpdate.js.map +1 -0
  213. package/dist/src/utils/installationInfo.d.ts +23 -0
  214. package/dist/src/utils/installationInfo.js +154 -0
  215. package/dist/src/utils/installationInfo.js.map +1 -0
  216. package/dist/src/utils/sandbox-macos-permissive-closed.sb +6 -0
  217. package/dist/src/utils/sandbox-macos-permissive-open.sb +6 -0
  218. package/dist/src/utils/sandbox-macos-permissive-proxied.sb +6 -0
  219. package/dist/src/utils/sandbox-macos-restrictive-closed.sb +6 -0
  220. package/dist/src/utils/sandbox-macos-restrictive-open.sb +6 -0
  221. package/dist/src/utils/sandbox-macos-restrictive-proxied.sb +6 -0
  222. package/dist/src/utils/sandbox.d.ts +2 -2
  223. package/dist/src/utils/sandbox.js +35 -11
  224. package/dist/src/utils/sandbox.js.map +1 -1
  225. package/dist/src/utils/spawnWrapper.d.ts +7 -0
  226. package/dist/src/utils/spawnWrapper.js +8 -0
  227. package/dist/src/utils/spawnWrapper.js.map +1 -0
  228. package/dist/src/utils/updateEventEmitter.d.ts +11 -0
  229. package/dist/src/utils/updateEventEmitter.js +12 -0
  230. package/dist/src/utils/updateEventEmitter.js.map +1 -0
  231. package/dist/src/validateNonInterActiveAuth.d.ts +2 -1
  232. package/dist/src/validateNonInterActiveAuth.js +31 -5
  233. package/dist/src/validateNonInterActiveAuth.js.map +1 -1
  234. package/dist/tsconfig.tsbuildinfo +1 -1
  235. package/package.json +4 -5
  236. package/dist/src/providers/enhanceConfigWithProviders.d.ts +0 -12
  237. package/dist/src/providers/enhanceConfigWithProviders.js +0 -16
  238. package/dist/src/providers/enhanceConfigWithProviders.js.map +0 -1
@@ -12,6 +12,7 @@ import { useState, useCallback, useEffect, useMemo, useReducer } from 'react';
12
12
  import stringWidth from 'string-width';
13
13
  import { unescapePath } from '@vybestack/llxprt-code-core';
14
14
  import { toCodePoints, cpLen, cpSlice } from '../../utils/textUtils.js';
15
+ import { handleVimAction } from './vim-buffer-actions.js';
15
16
  // Simple helper for word‑wise ops.
16
17
  function isWordChar(ch) {
17
18
  if (ch === undefined) {
@@ -19,6 +20,204 @@ function isWordChar(ch) {
19
20
  }
20
21
  return !/[\s,.;!?]/.test(ch);
21
22
  }
23
+ // Vim-specific word boundary functions
24
+ export const findNextWordStart = (text, currentOffset) => {
25
+ let i = currentOffset;
26
+ if (i >= text.length)
27
+ return i;
28
+ const currentChar = text[i];
29
+ // Skip current word/sequence based on character type
30
+ if (/\w/.test(currentChar)) {
31
+ // Skip current word characters
32
+ while (i < text.length && /\w/.test(text[i])) {
33
+ i++;
34
+ }
35
+ }
36
+ else if (!/\s/.test(currentChar)) {
37
+ // Skip current non-word, non-whitespace characters (like "/", ".", etc.)
38
+ while (i < text.length && !/\w/.test(text[i]) && !/\s/.test(text[i])) {
39
+ i++;
40
+ }
41
+ }
42
+ // Skip whitespace
43
+ while (i < text.length && /\s/.test(text[i])) {
44
+ i++;
45
+ }
46
+ // If we reached the end of text and there's no next word,
47
+ // vim behavior for dw is to delete to the end of the current word
48
+ if (i >= text.length) {
49
+ // Go back to find the end of the last word
50
+ let endOfLastWord = text.length - 1;
51
+ while (endOfLastWord >= 0 && /\s/.test(text[endOfLastWord])) {
52
+ endOfLastWord--;
53
+ }
54
+ // For dw on last word, return position AFTER the last character to delete entire word
55
+ return Math.max(currentOffset + 1, endOfLastWord + 1);
56
+ }
57
+ return i;
58
+ };
59
+ export const findPrevWordStart = (text, currentOffset) => {
60
+ let i = currentOffset;
61
+ // If at beginning of text, return current position
62
+ if (i <= 0) {
63
+ return currentOffset;
64
+ }
65
+ // Move back one character to start searching
66
+ i--;
67
+ // Skip whitespace moving backwards
68
+ while (i >= 0 && (text[i] === ' ' || text[i] === '\t' || text[i] === '\n')) {
69
+ i--;
70
+ }
71
+ if (i < 0) {
72
+ return 0; // Reached beginning of text
73
+ }
74
+ const charAtI = text[i];
75
+ if (/\w/.test(charAtI)) {
76
+ // We're in a word, move to its beginning
77
+ while (i >= 0 && /\w/.test(text[i])) {
78
+ i--;
79
+ }
80
+ return i + 1; // Return first character of word
81
+ }
82
+ else {
83
+ // We're in punctuation, move to its beginning
84
+ while (i >= 0 &&
85
+ !/\w/.test(text[i]) &&
86
+ text[i] !== ' ' &&
87
+ text[i] !== '\t' &&
88
+ text[i] !== '\n') {
89
+ i--;
90
+ }
91
+ return i + 1; // Return first character of punctuation sequence
92
+ }
93
+ };
94
+ export const findWordEnd = (text, currentOffset) => {
95
+ let i = currentOffset;
96
+ // If we're already at the end of a word, advance to next word
97
+ if (i < text.length &&
98
+ /\w/.test(text[i]) &&
99
+ (i + 1 >= text.length || !/\w/.test(text[i + 1]))) {
100
+ // We're at the end of a word, move forward to find next word
101
+ i++;
102
+ // Skip whitespace/punctuation to find next word
103
+ while (i < text.length && !/\w/.test(text[i])) {
104
+ i++;
105
+ }
106
+ }
107
+ // If we're not on a word character, find the next word
108
+ if (i < text.length && !/\w/.test(text[i])) {
109
+ while (i < text.length && !/\w/.test(text[i])) {
110
+ i++;
111
+ }
112
+ }
113
+ // Move to end of current word
114
+ while (i < text.length && /\w/.test(text[i])) {
115
+ i++;
116
+ }
117
+ // Move back one to be on the last character of the word
118
+ return Math.max(currentOffset, i - 1);
119
+ };
120
+ // Helper functions for vim operations
121
+ export const getOffsetFromPosition = (row, col, lines) => {
122
+ let offset = 0;
123
+ for (let i = 0; i < row; i++) {
124
+ offset += lines[i].length + 1; // +1 for newline
125
+ }
126
+ offset += col;
127
+ return offset;
128
+ };
129
+ export const getPositionFromOffsets = (startOffset, endOffset, lines) => {
130
+ let offset = 0;
131
+ let startRow = 0;
132
+ let startCol = 0;
133
+ let endRow = 0;
134
+ let endCol = 0;
135
+ // Find start position
136
+ for (let i = 0; i < lines.length; i++) {
137
+ const lineLength = lines[i].length + 1; // +1 for newline
138
+ if (offset + lineLength > startOffset) {
139
+ startRow = i;
140
+ startCol = startOffset - offset;
141
+ break;
142
+ }
143
+ offset += lineLength;
144
+ }
145
+ // Find end position
146
+ offset = 0;
147
+ for (let i = 0; i < lines.length; i++) {
148
+ const lineLength = lines[i].length + (i < lines.length - 1 ? 1 : 0); // +1 for newline except last line
149
+ if (offset + lineLength >= endOffset) {
150
+ endRow = i;
151
+ endCol = endOffset - offset;
152
+ break;
153
+ }
154
+ offset += lineLength;
155
+ }
156
+ return { startRow, startCol, endRow, endCol };
157
+ };
158
+ export const getLineRangeOffsets = (startRow, lineCount, lines) => {
159
+ let startOffset = 0;
160
+ // Calculate start offset
161
+ for (let i = 0; i < startRow; i++) {
162
+ startOffset += lines[i].length + 1; // +1 for newline
163
+ }
164
+ // Calculate end offset
165
+ let endOffset = startOffset;
166
+ for (let i = 0; i < lineCount; i++) {
167
+ const lineIndex = startRow + i;
168
+ if (lineIndex < lines.length) {
169
+ endOffset += lines[lineIndex].length;
170
+ if (lineIndex < lines.length - 1) {
171
+ endOffset += 1; // +1 for newline
172
+ }
173
+ }
174
+ }
175
+ return { startOffset, endOffset };
176
+ };
177
+ export const replaceRangeInternal = (state, startRow, startCol, endRow, endCol, text) => {
178
+ const currentLine = (row) => state.lines[row] || '';
179
+ const currentLineLen = (row) => cpLen(currentLine(row));
180
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
181
+ if (startRow > endRow ||
182
+ (startRow === endRow && startCol > endCol) ||
183
+ startRow < 0 ||
184
+ startCol < 0 ||
185
+ endRow >= state.lines.length ||
186
+ (endRow < state.lines.length && endCol > currentLineLen(endRow))) {
187
+ return state; // Invalid range
188
+ }
189
+ const newLines = [...state.lines];
190
+ const sCol = clamp(startCol, 0, currentLineLen(startRow));
191
+ const eCol = clamp(endCol, 0, currentLineLen(endRow));
192
+ const prefix = cpSlice(currentLine(startRow), 0, sCol);
193
+ const suffix = cpSlice(currentLine(endRow), eCol);
194
+ const normalisedReplacement = text
195
+ .replace(/\r\n/g, '\n')
196
+ .replace(/\r/g, '\n');
197
+ const replacementParts = normalisedReplacement.split('\n');
198
+ // The combined first line of the new text
199
+ const firstLine = prefix + replacementParts[0];
200
+ if (replacementParts.length === 1) {
201
+ // No newlines in replacement: combine prefix, replacement, and suffix on one line.
202
+ newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
203
+ }
204
+ else {
205
+ // Newlines in replacement: create new lines.
206
+ const lastLine = replacementParts[replacementParts.length - 1] + suffix;
207
+ const middleLines = replacementParts.slice(1, -1);
208
+ newLines.splice(startRow, endRow - startRow + 1, firstLine, ...middleLines, lastLine);
209
+ }
210
+ const finalCursorRow = startRow + replacementParts.length - 1;
211
+ const finalCursorCol = (replacementParts.length > 1 ? 0 : sCol) +
212
+ cpLen(replacementParts[replacementParts.length - 1]);
213
+ return {
214
+ ...state,
215
+ lines: newLines,
216
+ cursorRow: Math.min(Math.max(finalCursorRow, 0), newLines.length - 1),
217
+ cursorCol: Math.max(0, Math.min(finalCursorCol, cpLen(newLines[finalCursorRow] || ''))),
218
+ preferredCol: null,
219
+ };
220
+ };
22
221
  /**
23
222
  * Strip characters that can break terminal rendering.
24
223
  *
@@ -106,6 +305,24 @@ export function offsetToLogicalPos(text, offset) {
106
305
  }
107
306
  return [row, col];
108
307
  }
308
+ /**
309
+ * Converts logical row/col position to absolute text offset
310
+ * Inverse operation of offsetToLogicalPos
311
+ */
312
+ export function logicalPosToOffset(lines, row, col) {
313
+ let offset = 0;
314
+ // Clamp row to valid range
315
+ const actualRow = Math.min(row, lines.length - 1);
316
+ // Add lengths of all lines before the target row
317
+ for (let i = 0; i < actualRow; i++) {
318
+ offset += cpLen(lines[i]) + 1; // +1 for newline
319
+ }
320
+ // Add column offset within the target row
321
+ if (actualRow >= 0 && actualRow < lines.length) {
322
+ offset += Math.min(col, cpLen(lines[actualRow]));
323
+ }
324
+ return offset;
325
+ }
109
326
  // Helper to calculate visual lines and map cursor positions
110
327
  function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
111
328
  const visualLines = [];
@@ -279,26 +496,27 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
279
496
  };
280
497
  }
281
498
  const historyLimit = 100;
282
- export function textBufferReducer(state, action) {
283
- const pushUndo = (currentState) => {
284
- const snapshot = {
285
- lines: [...currentState.lines],
286
- cursorRow: currentState.cursorRow,
287
- cursorCol: currentState.cursorCol,
288
- };
289
- const newStack = [...currentState.undoStack, snapshot];
290
- if (newStack.length > historyLimit) {
291
- newStack.shift();
292
- }
293
- return { ...currentState, undoStack: newStack, redoStack: [] };
499
+ export const pushUndo = (currentState) => {
500
+ const snapshot = {
501
+ lines: [...currentState.lines],
502
+ cursorRow: currentState.cursorRow,
503
+ cursorCol: currentState.cursorCol,
294
504
  };
505
+ const newStack = [...currentState.undoStack, snapshot];
506
+ if (newStack.length > historyLimit) {
507
+ newStack.shift();
508
+ }
509
+ return { ...currentState, undoStack: newStack, redoStack: [] };
510
+ };
511
+ export function textBufferReducer(state, action) {
512
+ const pushUndoLocal = pushUndo;
295
513
  const currentLine = (r) => state.lines[r] ?? '';
296
514
  const currentLineLen = (r) => cpLen(currentLine(r));
297
515
  switch (action.type) {
298
516
  case 'set_text': {
299
517
  let nextState = state;
300
518
  if (action.pushToUndo !== false) {
301
- nextState = pushUndo(state);
519
+ nextState = pushUndoLocal(state);
302
520
  }
303
521
  const newContentLines = action.payload
304
522
  .replace(/\r\n?/g, '\n')
@@ -314,7 +532,7 @@ export function textBufferReducer(state, action) {
314
532
  };
315
533
  }
316
534
  case 'insert': {
317
- const nextState = pushUndo(state);
535
+ const nextState = pushUndoLocal(state);
318
536
  const newLines = [...nextState.lines];
319
537
  let newCursorRow = nextState.cursorRow;
320
538
  let newCursorCol = nextState.cursorCol;
@@ -351,7 +569,7 @@ export function textBufferReducer(state, action) {
351
569
  };
352
570
  }
353
571
  case 'backspace': {
354
- const nextState = pushUndo(state);
572
+ const nextState = pushUndoLocal(state);
355
573
  const newLines = [...nextState.lines];
356
574
  let newCursorRow = nextState.cursorRow;
357
575
  let newCursorCol = nextState.cursorCol;
@@ -528,7 +746,7 @@ export function textBufferReducer(state, action) {
528
746
  const { cursorRow, cursorCol, lines } = state;
529
747
  const lineContent = currentLine(cursorRow);
530
748
  if (cursorCol < currentLineLen(cursorRow)) {
531
- const nextState = pushUndo(state);
749
+ const nextState = pushUndoLocal(state);
532
750
  const newLines = [...nextState.lines];
533
751
  newLines[cursorRow] =
534
752
  cpSlice(lineContent, 0, cursorCol) +
@@ -536,7 +754,7 @@ export function textBufferReducer(state, action) {
536
754
  return { ...nextState, lines: newLines, preferredCol: null };
537
755
  }
538
756
  else if (cursorRow < lines.length - 1) {
539
- const nextState = pushUndo(state);
757
+ const nextState = pushUndoLocal(state);
540
758
  const nextLineContent = currentLine(cursorRow + 1);
541
759
  const newLines = [...nextState.lines];
542
760
  newLines[cursorRow] = lineContent + nextLineContent;
@@ -551,7 +769,7 @@ export function textBufferReducer(state, action) {
551
769
  return state;
552
770
  if (cursorCol === 0) {
553
771
  // Act as a backspace
554
- const nextState = pushUndo(state);
772
+ const nextState = pushUndoLocal(state);
555
773
  const prevLineContent = currentLine(cursorRow - 1);
556
774
  const currentLineContentVal = currentLine(cursorRow);
557
775
  const newCol = cpLen(prevLineContent);
@@ -566,7 +784,7 @@ export function textBufferReducer(state, action) {
566
784
  preferredCol: null,
567
785
  };
568
786
  }
569
- const nextState = pushUndo(state);
787
+ const nextState = pushUndoLocal(state);
570
788
  const lineContent = currentLine(cursorRow);
571
789
  const arr = toCodePoints(lineContent);
572
790
  let start = cursorCol;
@@ -604,14 +822,14 @@ export function textBufferReducer(state, action) {
604
822
  return state;
605
823
  if (cursorCol >= arr.length) {
606
824
  // Act as a delete
607
- const nextState = pushUndo(state);
825
+ const nextState = pushUndoLocal(state);
608
826
  const nextLineContent = currentLine(cursorRow + 1);
609
827
  const newLines = [...nextState.lines];
610
828
  newLines[cursorRow] = lineContent + nextLineContent;
611
829
  newLines.splice(cursorRow + 1, 1);
612
830
  return { ...nextState, lines: newLines, preferredCol: null };
613
831
  }
614
- const nextState = pushUndo(state);
832
+ const nextState = pushUndoLocal(state);
615
833
  let end = cursorCol;
616
834
  while (end < arr.length && !isWordChar(arr[end]))
617
835
  end++;
@@ -626,14 +844,14 @@ export function textBufferReducer(state, action) {
626
844
  const { cursorRow, cursorCol, lines } = state;
627
845
  const lineContent = currentLine(cursorRow);
628
846
  if (cursorCol < currentLineLen(cursorRow)) {
629
- const nextState = pushUndo(state);
847
+ const nextState = pushUndoLocal(state);
630
848
  const newLines = [...nextState.lines];
631
849
  newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol);
632
850
  return { ...nextState, lines: newLines };
633
851
  }
634
852
  else if (cursorRow < lines.length - 1) {
635
853
  // Act as a delete
636
- const nextState = pushUndo(state);
854
+ const nextState = pushUndoLocal(state);
637
855
  const nextLineContent = currentLine(cursorRow + 1);
638
856
  const newLines = [...nextState.lines];
639
857
  newLines[cursorRow] = lineContent + nextLineContent;
@@ -645,7 +863,7 @@ export function textBufferReducer(state, action) {
645
863
  case 'kill_line_left': {
646
864
  const { cursorRow, cursorCol } = state;
647
865
  if (cursorCol > 0) {
648
- const nextState = pushUndo(state);
866
+ const nextState = pushUndoLocal(state);
649
867
  const lineContent = currentLine(cursorRow);
650
868
  const newLines = [...nextState.lines];
651
869
  newLines[cursorRow] = cpSlice(lineContent, cursorCol);
@@ -692,51 +910,8 @@ export function textBufferReducer(state, action) {
692
910
  }
693
911
  case 'replace_range': {
694
912
  const { startRow, startCol, endRow, endCol, text } = action.payload;
695
- if (startRow > endRow ||
696
- (startRow === endRow && startCol > endCol) ||
697
- startRow < 0 ||
698
- startCol < 0 ||
699
- endRow >= state.lines.length ||
700
- (endRow < state.lines.length && endCol > currentLineLen(endRow))) {
701
- return state; // Invalid range
702
- }
703
- const nextState = pushUndo(state);
704
- const newLines = [...nextState.lines];
705
- const sCol = clamp(startCol, 0, currentLineLen(startRow));
706
- const eCol = clamp(endCol, 0, currentLineLen(endRow));
707
- const prefix = cpSlice(currentLine(startRow), 0, sCol);
708
- const suffix = cpSlice(currentLine(endRow), eCol);
709
- const normalisedReplacement = text
710
- .replace(/\r\n/g, '\n')
711
- .replace(/\r/g, '\n');
712
- const replacementParts = normalisedReplacement.split('\n');
713
- // Replace the content
714
- if (startRow === endRow) {
715
- newLines[startRow] = prefix + normalisedReplacement + suffix;
716
- }
717
- else {
718
- const firstLine = prefix + replacementParts[0];
719
- if (replacementParts.length === 1) {
720
- // Single line of replacement text, but spanning multiple original lines
721
- newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
722
- }
723
- else {
724
- // Multi-line replacement text
725
- const lastLine = replacementParts[replacementParts.length - 1] + suffix;
726
- const middleLines = replacementParts.slice(1, -1);
727
- newLines.splice(startRow, endRow - startRow + 1, firstLine, ...middleLines, lastLine);
728
- }
729
- }
730
- const finalCursorRow = startRow + replacementParts.length - 1;
731
- const finalCursorCol = (replacementParts.length > 1 ? 0 : sCol) +
732
- cpLen(replacementParts[replacementParts.length - 1]);
733
- return {
734
- ...nextState,
735
- lines: newLines,
736
- cursorRow: finalCursorRow,
737
- cursorCol: finalCursorCol,
738
- preferredCol: null,
739
- };
913
+ const nextState = pushUndoLocal(state);
914
+ return replaceRangeInternal(nextState, startRow, startCol, endRow, endCol, text);
740
915
  }
741
916
  case 'move_to_offset': {
742
917
  const { offset } = action.payload;
@@ -749,8 +924,42 @@ export function textBufferReducer(state, action) {
749
924
  };
750
925
  }
751
926
  case 'create_undo_snapshot': {
752
- return pushUndo(state);
927
+ return pushUndoLocal(state);
753
928
  }
929
+ // Vim-specific operations
930
+ case 'vim_delete_word_forward':
931
+ case 'vim_delete_word_backward':
932
+ case 'vim_delete_word_end':
933
+ case 'vim_change_word_forward':
934
+ case 'vim_change_word_backward':
935
+ case 'vim_change_word_end':
936
+ case 'vim_delete_line':
937
+ case 'vim_change_line':
938
+ case 'vim_delete_to_end_of_line':
939
+ case 'vim_change_to_end_of_line':
940
+ case 'vim_change_movement':
941
+ case 'vim_move_left':
942
+ case 'vim_move_right':
943
+ case 'vim_move_up':
944
+ case 'vim_move_down':
945
+ case 'vim_move_word_forward':
946
+ case 'vim_move_word_backward':
947
+ case 'vim_move_word_end':
948
+ case 'vim_delete_char':
949
+ case 'vim_insert_at_cursor':
950
+ case 'vim_append_at_cursor':
951
+ case 'vim_open_line_below':
952
+ case 'vim_open_line_above':
953
+ case 'vim_append_at_line_end':
954
+ case 'vim_insert_at_line_start':
955
+ case 'vim_move_to_line_start':
956
+ case 'vim_move_to_line_end':
957
+ case 'vim_move_to_first_nonwhitespace':
958
+ case 'vim_move_to_first_line':
959
+ case 'vim_move_to_last_line':
960
+ case 'vim_move_to_line':
961
+ case 'vim_escape_insert_mode':
962
+ return handleVimAction(state, action);
754
963
  default: {
755
964
  const exhaustiveCheck = action;
756
965
  console.error(`Unknown action encountered: ${exhaustiveCheck}`);
@@ -872,6 +1081,104 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
872
1081
  const killLineLeft = useCallback(() => {
873
1082
  dispatch({ type: 'kill_line_left' });
874
1083
  }, []);
1084
+ // Vim-specific operations
1085
+ const vimDeleteWordForward = useCallback((count) => {
1086
+ dispatch({ type: 'vim_delete_word_forward', payload: { count } });
1087
+ }, []);
1088
+ const vimDeleteWordBackward = useCallback((count) => {
1089
+ dispatch({ type: 'vim_delete_word_backward', payload: { count } });
1090
+ }, []);
1091
+ const vimDeleteWordEnd = useCallback((count) => {
1092
+ dispatch({ type: 'vim_delete_word_end', payload: { count } });
1093
+ }, []);
1094
+ const vimChangeWordForward = useCallback((count) => {
1095
+ dispatch({ type: 'vim_change_word_forward', payload: { count } });
1096
+ }, []);
1097
+ const vimChangeWordBackward = useCallback((count) => {
1098
+ dispatch({ type: 'vim_change_word_backward', payload: { count } });
1099
+ }, []);
1100
+ const vimChangeWordEnd = useCallback((count) => {
1101
+ dispatch({ type: 'vim_change_word_end', payload: { count } });
1102
+ }, []);
1103
+ const vimDeleteLine = useCallback((count) => {
1104
+ dispatch({ type: 'vim_delete_line', payload: { count } });
1105
+ }, []);
1106
+ const vimChangeLine = useCallback((count) => {
1107
+ dispatch({ type: 'vim_change_line', payload: { count } });
1108
+ }, []);
1109
+ const vimDeleteToEndOfLine = useCallback(() => {
1110
+ dispatch({ type: 'vim_delete_to_end_of_line' });
1111
+ }, []);
1112
+ const vimChangeToEndOfLine = useCallback(() => {
1113
+ dispatch({ type: 'vim_change_to_end_of_line' });
1114
+ }, []);
1115
+ const vimChangeMovement = useCallback((movement, count) => {
1116
+ dispatch({ type: 'vim_change_movement', payload: { movement, count } });
1117
+ }, []);
1118
+ // New vim navigation and operation methods
1119
+ const vimMoveLeft = useCallback((count) => {
1120
+ dispatch({ type: 'vim_move_left', payload: { count } });
1121
+ }, []);
1122
+ const vimMoveRight = useCallback((count) => {
1123
+ dispatch({ type: 'vim_move_right', payload: { count } });
1124
+ }, []);
1125
+ const vimMoveUp = useCallback((count) => {
1126
+ dispatch({ type: 'vim_move_up', payload: { count } });
1127
+ }, []);
1128
+ const vimMoveDown = useCallback((count) => {
1129
+ dispatch({ type: 'vim_move_down', payload: { count } });
1130
+ }, []);
1131
+ const vimMoveWordForward = useCallback((count) => {
1132
+ dispatch({ type: 'vim_move_word_forward', payload: { count } });
1133
+ }, []);
1134
+ const vimMoveWordBackward = useCallback((count) => {
1135
+ dispatch({ type: 'vim_move_word_backward', payload: { count } });
1136
+ }, []);
1137
+ const vimMoveWordEnd = useCallback((count) => {
1138
+ dispatch({ type: 'vim_move_word_end', payload: { count } });
1139
+ }, []);
1140
+ const vimDeleteChar = useCallback((count) => {
1141
+ dispatch({ type: 'vim_delete_char', payload: { count } });
1142
+ }, []);
1143
+ const vimInsertAtCursor = useCallback(() => {
1144
+ dispatch({ type: 'vim_insert_at_cursor' });
1145
+ }, []);
1146
+ const vimAppendAtCursor = useCallback(() => {
1147
+ dispatch({ type: 'vim_append_at_cursor' });
1148
+ }, []);
1149
+ const vimOpenLineBelow = useCallback(() => {
1150
+ dispatch({ type: 'vim_open_line_below' });
1151
+ }, []);
1152
+ const vimOpenLineAbove = useCallback(() => {
1153
+ dispatch({ type: 'vim_open_line_above' });
1154
+ }, []);
1155
+ const vimAppendAtLineEnd = useCallback(() => {
1156
+ dispatch({ type: 'vim_append_at_line_end' });
1157
+ }, []);
1158
+ const vimInsertAtLineStart = useCallback(() => {
1159
+ dispatch({ type: 'vim_insert_at_line_start' });
1160
+ }, []);
1161
+ const vimMoveToLineStart = useCallback(() => {
1162
+ dispatch({ type: 'vim_move_to_line_start' });
1163
+ }, []);
1164
+ const vimMoveToLineEnd = useCallback(() => {
1165
+ dispatch({ type: 'vim_move_to_line_end' });
1166
+ }, []);
1167
+ const vimMoveToFirstNonWhitespace = useCallback(() => {
1168
+ dispatch({ type: 'vim_move_to_first_nonwhitespace' });
1169
+ }, []);
1170
+ const vimMoveToFirstLine = useCallback(() => {
1171
+ dispatch({ type: 'vim_move_to_first_line' });
1172
+ }, []);
1173
+ const vimMoveToLastLine = useCallback(() => {
1174
+ dispatch({ type: 'vim_move_to_last_line' });
1175
+ }, []);
1176
+ const vimMoveToLine = useCallback((lineNumber) => {
1177
+ dispatch({ type: 'vim_move_to_line', payload: { lineNumber } });
1178
+ }, []);
1179
+ const vimEscapeInsertMode = useCallback(() => {
1180
+ dispatch({ type: 'vim_escape_insert_mode' });
1181
+ }, []);
875
1182
  const openInExternalEditor = useCallback(async (opts = {}) => {
876
1183
  const editor = opts.editor ??
877
1184
  process.env['VISUAL'] ??
@@ -1016,6 +1323,39 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
1016
1323
  killLineLeft,
1017
1324
  handleInput,
1018
1325
  openInExternalEditor,
1326
+ // Vim-specific operations
1327
+ vimDeleteWordForward,
1328
+ vimDeleteWordBackward,
1329
+ vimDeleteWordEnd,
1330
+ vimChangeWordForward,
1331
+ vimChangeWordBackward,
1332
+ vimChangeWordEnd,
1333
+ vimDeleteLine,
1334
+ vimChangeLine,
1335
+ vimDeleteToEndOfLine,
1336
+ vimChangeToEndOfLine,
1337
+ vimChangeMovement,
1338
+ vimMoveLeft,
1339
+ vimMoveRight,
1340
+ vimMoveUp,
1341
+ vimMoveDown,
1342
+ vimMoveWordForward,
1343
+ vimMoveWordBackward,
1344
+ vimMoveWordEnd,
1345
+ vimDeleteChar,
1346
+ vimInsertAtCursor,
1347
+ vimAppendAtCursor,
1348
+ vimOpenLineBelow,
1349
+ vimOpenLineAbove,
1350
+ vimAppendAtLineEnd,
1351
+ vimInsertAtLineStart,
1352
+ vimMoveToLineStart,
1353
+ vimMoveToLineEnd,
1354
+ vimMoveToFirstNonWhitespace,
1355
+ vimMoveToFirstLine,
1356
+ vimMoveToLastLine,
1357
+ vimMoveToLine,
1358
+ vimEscapeInsertMode,
1019
1359
  };
1020
1360
  return returnValue;
1021
1361
  }