@google/gemini-cli 0.0.3-preview.4

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 (883) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +310 -0
  3. package/dist/.last_build +0 -0
  4. package/dist/google-gemini-cli-0.3.0-preview.3.tgz +0 -0
  5. package/dist/index.d.ts +7 -0
  6. package/dist/index.js +29 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/package.json +85 -0
  9. package/dist/src/commands/extensions/disable.d.ts +14 -0
  10. package/dist/src/commands/extensions/disable.js +42 -0
  11. package/dist/src/commands/extensions/disable.js.map +1 -0
  12. package/dist/src/commands/extensions/enable.d.ts +14 -0
  13. package/dist/src/commands/extensions/enable.js +48 -0
  14. package/dist/src/commands/extensions/enable.js.map +1 -0
  15. package/dist/src/commands/extensions/install.d.ts +13 -0
  16. package/dist/src/commands/extensions/install.js +48 -0
  17. package/dist/src/commands/extensions/install.js.map +1 -0
  18. package/dist/src/commands/extensions/install.test.d.ts +6 -0
  19. package/dist/src/commands/extensions/install.test.js +19 -0
  20. package/dist/src/commands/extensions/install.test.js.map +1 -0
  21. package/dist/src/commands/extensions/list.d.ts +8 -0
  22. package/dist/src/commands/extensions/list.js +32 -0
  23. package/dist/src/commands/extensions/list.js.map +1 -0
  24. package/dist/src/commands/extensions/uninstall.d.ts +12 -0
  25. package/dist/src/commands/extensions/uninstall.js +38 -0
  26. package/dist/src/commands/extensions/uninstall.js.map +1 -0
  27. package/dist/src/commands/extensions/uninstall.test.d.ts +6 -0
  28. package/dist/src/commands/extensions/uninstall.test.js +15 -0
  29. package/dist/src/commands/extensions/uninstall.test.js.map +1 -0
  30. package/dist/src/commands/extensions/update.d.ts +12 -0
  31. package/dist/src/commands/extensions/update.js +38 -0
  32. package/dist/src/commands/extensions/update.js.map +1 -0
  33. package/dist/src/commands/extensions.d.ts +7 -0
  34. package/dist/src/commands/extensions.js +29 -0
  35. package/dist/src/commands/extensions.js.map +1 -0
  36. package/dist/src/commands/mcp/add.d.ts +7 -0
  37. package/dist/src/commands/mcp/add.js +166 -0
  38. package/dist/src/commands/mcp/add.js.map +1 -0
  39. package/dist/src/commands/mcp/list.d.ts +8 -0
  40. package/dist/src/commands/mcp/list.js +110 -0
  41. package/dist/src/commands/mcp/list.js.map +1 -0
  42. package/dist/src/commands/mcp/remove.d.ts +7 -0
  43. package/dist/src/commands/mcp/remove.js +44 -0
  44. package/dist/src/commands/mcp/remove.js.map +1 -0
  45. package/dist/src/commands/mcp.d.ts +7 -0
  46. package/dist/src/commands/mcp.js +23 -0
  47. package/dist/src/commands/mcp.js.map +1 -0
  48. package/dist/src/config/auth.d.ts +6 -0
  49. package/dist/src/config/auth.js +34 -0
  50. package/dist/src/config/auth.js.map +1 -0
  51. package/dist/src/config/auth.test.d.ts +6 -0
  52. package/dist/src/config/auth.test.js +57 -0
  53. package/dist/src/config/auth.test.js.map +1 -0
  54. package/dist/src/config/config.d.ts +42 -0
  55. package/dist/src/config/config.js +446 -0
  56. package/dist/src/config/config.js.map +1 -0
  57. package/dist/src/config/extension.d.ts +59 -0
  58. package/dist/src/config/extension.js +372 -0
  59. package/dist/src/config/extension.js.map +1 -0
  60. package/dist/src/config/extensions/variableSchema.d.ts +28 -0
  61. package/dist/src/config/extensions/variableSchema.js +18 -0
  62. package/dist/src/config/extensions/variableSchema.js.map +1 -0
  63. package/dist/src/config/extensions/variables.d.ts +17 -0
  64. package/dist/src/config/extensions/variables.js +40 -0
  65. package/dist/src/config/extensions/variables.js.map +1 -0
  66. package/dist/src/config/extensions/variables.test.d.ts +6 -0
  67. package/dist/src/config/extensions/variables.test.js +17 -0
  68. package/dist/src/config/extensions/variables.test.js.map +1 -0
  69. package/dist/src/config/keyBindings.d.ts +66 -0
  70. package/dist/src/config/keyBindings.js +141 -0
  71. package/dist/src/config/keyBindings.js.map +1 -0
  72. package/dist/src/config/keyBindings.test.d.ts +6 -0
  73. package/dist/src/config/keyBindings.test.js +51 -0
  74. package/dist/src/config/keyBindings.test.js.map +1 -0
  75. package/dist/src/config/sandboxConfig.d.ts +13 -0
  76. package/dist/src/config/sandboxConfig.js +73 -0
  77. package/dist/src/config/sandboxConfig.js.map +1 -0
  78. package/dist/src/config/settings.d.ts +62 -0
  79. package/dist/src/config/settings.js +656 -0
  80. package/dist/src/config/settings.js.map +1 -0
  81. package/dist/src/config/settingsSchema.d.ts +750 -0
  82. package/dist/src/config/settingsSchema.js +723 -0
  83. package/dist/src/config/settingsSchema.js.map +1 -0
  84. package/dist/src/config/settingsSchema.test.d.ts +6 -0
  85. package/dist/src/config/settingsSchema.test.js +193 -0
  86. package/dist/src/config/settingsSchema.test.js.map +1 -0
  87. package/dist/src/config/trustedFolders.d.ts +37 -0
  88. package/dist/src/config/trustedFolders.js +118 -0
  89. package/dist/src/config/trustedFolders.js.map +1 -0
  90. package/dist/src/config/trustedFolders.test.d.ts +6 -0
  91. package/dist/src/config/trustedFolders.test.js +164 -0
  92. package/dist/src/config/trustedFolders.test.js.map +1 -0
  93. package/dist/src/gemini.d.ts +11 -0
  94. package/dist/src/gemini.js +289 -0
  95. package/dist/src/gemini.js.map +1 -0
  96. package/dist/src/gemini.test.d.ts +6 -0
  97. package/dist/src/gemini.test.js +247 -0
  98. package/dist/src/gemini.test.js.map +1 -0
  99. package/dist/src/generated/git-commit.d.ts +7 -0
  100. package/dist/src/generated/git-commit.js +10 -0
  101. package/dist/src/generated/git-commit.js.map +1 -0
  102. package/dist/src/nonInteractiveCli.d.ts +7 -0
  103. package/dist/src/nonInteractiveCli.js +92 -0
  104. package/dist/src/nonInteractiveCli.js.map +1 -0
  105. package/dist/src/patches/is-in-ci.d.ts +7 -0
  106. package/dist/src/patches/is-in-ci.js +15 -0
  107. package/dist/src/patches/is-in-ci.js.map +1 -0
  108. package/dist/src/services/BuiltinCommandLoader.d.ts +24 -0
  109. package/dist/src/services/BuiltinCommandLoader.js +82 -0
  110. package/dist/src/services/BuiltinCommandLoader.js.map +1 -0
  111. package/dist/src/services/BuiltinCommandLoader.test.d.ts +6 -0
  112. package/dist/src/services/BuiltinCommandLoader.test.js +108 -0
  113. package/dist/src/services/BuiltinCommandLoader.test.js.map +1 -0
  114. package/dist/src/services/CommandService.d.ts +55 -0
  115. package/dist/src/services/CommandService.js +90 -0
  116. package/dist/src/services/CommandService.js.map +1 -0
  117. package/dist/src/services/CommandService.test.d.ts +6 -0
  118. package/dist/src/services/CommandService.test.js +233 -0
  119. package/dist/src/services/CommandService.test.js.map +1 -0
  120. package/dist/src/services/FileCommandLoader.d.ts +49 -0
  121. package/dist/src/services/FileCommandLoader.js +220 -0
  122. package/dist/src/services/FileCommandLoader.js.map +1 -0
  123. package/dist/src/services/McpPromptLoader.d.ts +35 -0
  124. package/dist/src/services/McpPromptLoader.js +218 -0
  125. package/dist/src/services/McpPromptLoader.js.map +1 -0
  126. package/dist/src/services/McpPromptLoader.test.d.ts +6 -0
  127. package/dist/src/services/McpPromptLoader.test.js +114 -0
  128. package/dist/src/services/McpPromptLoader.test.js.map +1 -0
  129. package/dist/src/services/prompt-processors/argumentProcessor.d.ts +16 -0
  130. package/dist/src/services/prompt-processors/argumentProcessor.js +21 -0
  131. package/dist/src/services/prompt-processors/argumentProcessor.js.map +1 -0
  132. package/dist/src/services/prompt-processors/atFileProcessor.d.ts +12 -0
  133. package/dist/src/services/prompt-processors/atFileProcessor.js +62 -0
  134. package/dist/src/services/prompt-processors/atFileProcessor.js.map +1 -0
  135. package/dist/src/services/prompt-processors/atFileProcessor.test.d.ts +6 -0
  136. package/dist/src/services/prompt-processors/atFileProcessor.test.js +174 -0
  137. package/dist/src/services/prompt-processors/atFileProcessor.test.js.map +1 -0
  138. package/dist/src/services/prompt-processors/injectionParser.d.ts +29 -0
  139. package/dist/src/services/prompt-processors/injectionParser.js +60 -0
  140. package/dist/src/services/prompt-processors/injectionParser.js.map +1 -0
  141. package/dist/src/services/prompt-processors/injectionParser.test.d.ts +6 -0
  142. package/dist/src/services/prompt-processors/injectionParser.test.js +189 -0
  143. package/dist/src/services/prompt-processors/injectionParser.test.js.map +1 -0
  144. package/dist/src/services/prompt-processors/shellProcessor.d.ts +27 -0
  145. package/dist/src/services/prompt-processors/shellProcessor.js +121 -0
  146. package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -0
  147. package/dist/src/services/prompt-processors/types.d.ts +45 -0
  148. package/dist/src/services/prompt-processors/types.js +20 -0
  149. package/dist/src/services/prompt-processors/types.js.map +1 -0
  150. package/dist/src/services/types.d.ts +22 -0
  151. package/dist/src/services/types.js +7 -0
  152. package/dist/src/services/types.js.map +1 -0
  153. package/dist/src/test-utils/customMatchers.d.ts +14 -0
  154. package/dist/src/test-utils/customMatchers.js +40 -0
  155. package/dist/src/test-utils/customMatchers.js.map +1 -0
  156. package/dist/src/test-utils/mockCommandContext.d.ts +18 -0
  157. package/dist/src/test-utils/mockCommandContext.js +86 -0
  158. package/dist/src/test-utils/mockCommandContext.js.map +1 -0
  159. package/dist/src/test-utils/mockCommandContext.test.d.ts +6 -0
  160. package/dist/src/test-utils/mockCommandContext.test.js +51 -0
  161. package/dist/src/test-utils/mockCommandContext.test.js.map +1 -0
  162. package/dist/src/test-utils/render.d.ts +8 -0
  163. package/dist/src/test-utils/render.js +10 -0
  164. package/dist/src/test-utils/render.js.map +1 -0
  165. package/dist/src/ui/App.d.ts +15 -0
  166. package/dist/src/ui/App.js +676 -0
  167. package/dist/src/ui/App.js.map +1 -0
  168. package/dist/src/ui/IdeIntegrationNudge.d.ts +16 -0
  169. package/dist/src/ui/IdeIntegrationNudge.js +47 -0
  170. package/dist/src/ui/IdeIntegrationNudge.js.map +1 -0
  171. package/dist/src/ui/colors.d.ts +7 -0
  172. package/dist/src/ui/colors.js +54 -0
  173. package/dist/src/ui/colors.js.map +1 -0
  174. package/dist/src/ui/commands/aboutCommand.d.ts +7 -0
  175. package/dist/src/ui/commands/aboutCommand.js +43 -0
  176. package/dist/src/ui/commands/aboutCommand.js.map +1 -0
  177. package/dist/src/ui/commands/authCommand.d.ts +7 -0
  178. package/dist/src/ui/commands/authCommand.js +16 -0
  179. package/dist/src/ui/commands/authCommand.js.map +1 -0
  180. package/dist/src/ui/commands/bugCommand.d.ts +7 -0
  181. package/dist/src/ui/commands/bugCommand.js +71 -0
  182. package/dist/src/ui/commands/bugCommand.js.map +1 -0
  183. package/dist/src/ui/commands/chatCommand.d.ts +7 -0
  184. package/dist/src/ui/commands/chatCommand.js +235 -0
  185. package/dist/src/ui/commands/chatCommand.js.map +1 -0
  186. package/dist/src/ui/commands/clearCommand.d.ts +7 -0
  187. package/dist/src/ui/commands/clearCommand.js +27 -0
  188. package/dist/src/ui/commands/clearCommand.js.map +1 -0
  189. package/dist/src/ui/commands/compressCommand.d.ts +7 -0
  190. package/dist/src/ui/commands/compressCommand.js +66 -0
  191. package/dist/src/ui/commands/compressCommand.js.map +1 -0
  192. package/dist/src/ui/commands/copyCommand.d.ts +7 -0
  193. package/dist/src/ui/commands/copyCommand.js +59 -0
  194. package/dist/src/ui/commands/copyCommand.js.map +1 -0
  195. package/dist/src/ui/commands/corgiCommand.d.ts +7 -0
  196. package/dist/src/ui/commands/corgiCommand.js +15 -0
  197. package/dist/src/ui/commands/corgiCommand.js.map +1 -0
  198. package/dist/src/ui/commands/directoryCommand.d.ts +8 -0
  199. package/dist/src/ui/commands/directoryCommand.js +135 -0
  200. package/dist/src/ui/commands/directoryCommand.js.map +1 -0
  201. package/dist/src/ui/commands/docsCommand.d.ts +7 -0
  202. package/dist/src/ui/commands/docsCommand.js +31 -0
  203. package/dist/src/ui/commands/docsCommand.js.map +1 -0
  204. package/dist/src/ui/commands/editorCommand.d.ts +7 -0
  205. package/dist/src/ui/commands/editorCommand.js +16 -0
  206. package/dist/src/ui/commands/editorCommand.js.map +1 -0
  207. package/dist/src/ui/commands/extensionsCommand.d.ts +7 -0
  208. package/dist/src/ui/commands/extensionsCommand.js +31 -0
  209. package/dist/src/ui/commands/extensionsCommand.js.map +1 -0
  210. package/dist/src/ui/commands/helpCommand.d.ts +7 -0
  211. package/dist/src/ui/commands/helpCommand.js +21 -0
  212. package/dist/src/ui/commands/helpCommand.js.map +1 -0
  213. package/dist/src/ui/commands/ideCommand.d.ts +8 -0
  214. package/dist/src/ui/commands/ideCommand.js +216 -0
  215. package/dist/src/ui/commands/ideCommand.js.map +1 -0
  216. package/dist/src/ui/commands/initCommand.d.ts +7 -0
  217. package/dist/src/ui/commands/initCommand.js +76 -0
  218. package/dist/src/ui/commands/initCommand.js.map +1 -0
  219. package/dist/src/ui/commands/mcpCommand.d.ts +7 -0
  220. package/dist/src/ui/commands/mcpCommand.js +424 -0
  221. package/dist/src/ui/commands/mcpCommand.js.map +1 -0
  222. package/dist/src/ui/commands/memoryCommand.d.ts +7 -0
  223. package/dist/src/ui/commands/memoryCommand.js +92 -0
  224. package/dist/src/ui/commands/memoryCommand.js.map +1 -0
  225. package/dist/src/ui/commands/privacyCommand.d.ts +7 -0
  226. package/dist/src/ui/commands/privacyCommand.js +16 -0
  227. package/dist/src/ui/commands/privacyCommand.js.map +1 -0
  228. package/dist/src/ui/commands/quitCommand.d.ts +7 -0
  229. package/dist/src/ui/commands/quitCommand.js +34 -0
  230. package/dist/src/ui/commands/quitCommand.js.map +1 -0
  231. package/dist/src/ui/commands/restoreCommand.d.ts +8 -0
  232. package/dist/src/ui/commands/restoreCommand.js +124 -0
  233. package/dist/src/ui/commands/restoreCommand.js.map +1 -0
  234. package/dist/src/ui/commands/settingsCommand.d.ts +7 -0
  235. package/dist/src/ui/commands/settingsCommand.js +16 -0
  236. package/dist/src/ui/commands/settingsCommand.js.map +1 -0
  237. package/dist/src/ui/commands/setupGithubCommand.d.ts +9 -0
  238. package/dist/src/ui/commands/setupGithubCommand.js +154 -0
  239. package/dist/src/ui/commands/setupGithubCommand.js.map +1 -0
  240. package/dist/src/ui/commands/setupGithubCommand.test.d.ts +6 -0
  241. package/dist/src/ui/commands/setupGithubCommand.test.js +167 -0
  242. package/dist/src/ui/commands/setupGithubCommand.test.js.map +1 -0
  243. package/dist/src/ui/commands/statsCommand.d.ts +7 -0
  244. package/dist/src/ui/commands/statsCommand.js +54 -0
  245. package/dist/src/ui/commands/statsCommand.js.map +1 -0
  246. package/dist/src/ui/commands/terminalSetupCommand.d.ts +13 -0
  247. package/dist/src/ui/commands/terminalSetupCommand.js +41 -0
  248. package/dist/src/ui/commands/terminalSetupCommand.js.map +1 -0
  249. package/dist/src/ui/commands/themeCommand.d.ts +7 -0
  250. package/dist/src/ui/commands/themeCommand.js +16 -0
  251. package/dist/src/ui/commands/themeCommand.js.map +1 -0
  252. package/dist/src/ui/commands/toolsCommand.d.ts +7 -0
  253. package/dist/src/ui/commands/toolsCommand.js +56 -0
  254. package/dist/src/ui/commands/toolsCommand.js.map +1 -0
  255. package/dist/src/ui/commands/types.d.ts +148 -0
  256. package/dist/src/ui/commands/types.js +13 -0
  257. package/dist/src/ui/commands/types.js.map +1 -0
  258. package/dist/src/ui/commands/vimCommand.d.ts +7 -0
  259. package/dist/src/ui/commands/vimCommand.js +23 -0
  260. package/dist/src/ui/commands/vimCommand.js.map +1 -0
  261. package/dist/src/ui/components/AboutBox.d.ts +17 -0
  262. package/dist/src/ui/components/AboutBox.js +6 -0
  263. package/dist/src/ui/components/AboutBox.js.map +1 -0
  264. package/dist/src/ui/components/AsciiArt.d.ts +8 -0
  265. package/dist/src/ui/components/AsciiArt.js +36 -0
  266. package/dist/src/ui/components/AsciiArt.js.map +1 -0
  267. package/dist/src/ui/components/AuthDialog.d.ts +16 -0
  268. package/dist/src/ui/components/AuthDialog.js +92 -0
  269. package/dist/src/ui/components/AuthDialog.js.map +1 -0
  270. package/dist/src/ui/components/AuthDialog.test.d.ts +6 -0
  271. package/dist/src/ui/components/AuthDialog.test.js +276 -0
  272. package/dist/src/ui/components/AuthDialog.test.js.map +1 -0
  273. package/dist/src/ui/components/AuthInProgress.d.ts +11 -0
  274. package/dist/src/ui/components/AuthInProgress.js +23 -0
  275. package/dist/src/ui/components/AuthInProgress.js.map +1 -0
  276. package/dist/src/ui/components/AutoAcceptIndicator.d.ts +12 -0
  277. package/dist/src/ui/components/AutoAcceptIndicator.js +26 -0
  278. package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -0
  279. package/dist/src/ui/components/ConsoleSummaryDisplay.d.ts +11 -0
  280. package/dist/src/ui/components/ConsoleSummaryDisplay.js +11 -0
  281. package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -0
  282. package/dist/src/ui/components/ContextSummaryDisplay.d.ts +20 -0
  283. package/dist/src/ui/components/ContextSummaryDisplay.js +66 -0
  284. package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -0
  285. package/dist/src/ui/components/ContextUsageDisplay.d.ts +9 -0
  286. package/dist/src/ui/components/ContextUsageDisplay.js +14 -0
  287. package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -0
  288. package/dist/src/ui/components/DebugProfiler.d.ts +6 -0
  289. package/dist/src/ui/components/DebugProfiler.js +27 -0
  290. package/dist/src/ui/components/DebugProfiler.js.map +1 -0
  291. package/dist/src/ui/components/DetailedMessagesDisplay.d.ts +14 -0
  292. package/dist/src/ui/components/DetailedMessagesDisplay.js +34 -0
  293. package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -0
  294. package/dist/src/ui/components/EditorSettingsDialog.d.ts +16 -0
  295. package/dist/src/ui/components/EditorSettingsDialog.js +71 -0
  296. package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -0
  297. package/dist/src/ui/components/FolderTrustDialog.d.ts +17 -0
  298. package/dist/src/ui/components/FolderTrustDialog.js +45 -0
  299. package/dist/src/ui/components/FolderTrustDialog.js.map +1 -0
  300. package/dist/src/ui/components/FolderTrustDialog.test.d.ts +6 -0
  301. package/dist/src/ui/components/FolderTrustDialog.test.js +63 -0
  302. package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -0
  303. package/dist/src/ui/components/Footer.d.ts +23 -0
  304. package/dist/src/ui/components/Footer.js +25 -0
  305. package/dist/src/ui/components/Footer.js.map +1 -0
  306. package/dist/src/ui/components/GeminiRespondingSpinner.d.ts +17 -0
  307. package/dist/src/ui/components/GeminiRespondingSpinner.js +18 -0
  308. package/dist/src/ui/components/GeminiRespondingSpinner.js.map +1 -0
  309. package/dist/src/ui/components/Header.d.ts +13 -0
  310. package/dist/src/ui/components/Header.js +28 -0
  311. package/dist/src/ui/components/Header.js.map +1 -0
  312. package/dist/src/ui/components/Header.test.d.ts +6 -0
  313. package/dist/src/ui/components/Header.test.js +37 -0
  314. package/dist/src/ui/components/Header.test.js.map +1 -0
  315. package/dist/src/ui/components/Help.d.ts +12 -0
  316. package/dist/src/ui/components/Help.js +10 -0
  317. package/dist/src/ui/components/Help.js.map +1 -0
  318. package/dist/src/ui/components/HistoryItemDisplay.d.ts +20 -0
  319. package/dist/src/ui/components/HistoryItemDisplay.js +18 -0
  320. package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -0
  321. package/dist/src/ui/components/HistoryItemDisplay.test.d.ts +6 -0
  322. package/dist/src/ui/components/HistoryItemDisplay.test.js +93 -0
  323. package/dist/src/ui/components/HistoryItemDisplay.test.js.map +1 -0
  324. package/dist/src/ui/components/InputPrompt.d.ts +28 -0
  325. package/dist/src/ui/components/InputPrompt.js +562 -0
  326. package/dist/src/ui/components/InputPrompt.js.map +1 -0
  327. package/dist/src/ui/components/LoadingIndicator.d.ts +15 -0
  328. package/dist/src/ui/components/LoadingIndicator.js +25 -0
  329. package/dist/src/ui/components/LoadingIndicator.js.map +1 -0
  330. package/dist/src/ui/components/LoadingIndicator.test.d.ts +6 -0
  331. package/dist/src/ui/components/LoadingIndicator.test.js +190 -0
  332. package/dist/src/ui/components/LoadingIndicator.test.js.map +1 -0
  333. package/dist/src/ui/components/MemoryUsageDisplay.d.ts +7 -0
  334. package/dist/src/ui/components/MemoryUsageDisplay.js +22 -0
  335. package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -0
  336. package/dist/src/ui/components/ModelStatsDisplay.d.ts +7 -0
  337. package/dist/src/ui/components/ModelStatsDisplay.js +33 -0
  338. package/dist/src/ui/components/ModelStatsDisplay.js.map +1 -0
  339. package/dist/src/ui/components/PrepareLabel.d.ts +15 -0
  340. package/dist/src/ui/components/PrepareLabel.js +16 -0
  341. package/dist/src/ui/components/PrepareLabel.js.map +1 -0
  342. package/dist/src/ui/components/SessionSummaryDisplay.d.ts +11 -0
  343. package/dist/src/ui/components/SessionSummaryDisplay.js +4 -0
  344. package/dist/src/ui/components/SessionSummaryDisplay.js.map +1 -0
  345. package/dist/src/ui/components/SettingsDialog.d.ts +15 -0
  346. package/dist/src/ui/components/SettingsDialog.js +550 -0
  347. package/dist/src/ui/components/SettingsDialog.js.map +1 -0
  348. package/dist/src/ui/components/SettingsDialog.test.d.ts +6 -0
  349. package/dist/src/ui/components/SettingsDialog.test.js +646 -0
  350. package/dist/src/ui/components/SettingsDialog.test.js.map +1 -0
  351. package/dist/src/ui/components/ShellConfirmationDialog.d.ts +15 -0
  352. package/dist/src/ui/components/ShellConfirmationDialog.js +46 -0
  353. package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -0
  354. package/dist/src/ui/components/ShellConfirmationDialog.test.d.ts +6 -0
  355. package/dist/src/ui/components/ShellConfirmationDialog.test.js +40 -0
  356. package/dist/src/ui/components/ShellConfirmationDialog.test.js.map +1 -0
  357. package/dist/src/ui/components/ShellModeIndicator.d.ts +7 -0
  358. package/dist/src/ui/components/ShellModeIndicator.js +5 -0
  359. package/dist/src/ui/components/ShellModeIndicator.js.map +1 -0
  360. package/dist/src/ui/components/ShowMoreLines.d.ts +10 -0
  361. package/dist/src/ui/components/ShowMoreLines.js +24 -0
  362. package/dist/src/ui/components/ShowMoreLines.js.map +1 -0
  363. package/dist/src/ui/components/StatsDisplay.d.ts +12 -0
  364. package/dist/src/ui/components/StatsDisplay.js +43 -0
  365. package/dist/src/ui/components/StatsDisplay.js.map +1 -0
  366. package/dist/src/ui/components/SuggestionsDisplay.d.ts +22 -0
  367. package/dist/src/ui/components/SuggestionsDisplay.js +40 -0
  368. package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -0
  369. package/dist/src/ui/components/ThemeDialog.d.ts +20 -0
  370. package/dist/src/ui/components/ThemeDialog.js +138 -0
  371. package/dist/src/ui/components/ThemeDialog.js.map +1 -0
  372. package/dist/src/ui/components/Tips.d.ts +12 -0
  373. package/dist/src/ui/components/Tips.js +9 -0
  374. package/dist/src/ui/components/Tips.js.map +1 -0
  375. package/dist/src/ui/components/ToolStatsDisplay.d.ts +7 -0
  376. package/dist/src/ui/components/ToolStatsDisplay.js +41 -0
  377. package/dist/src/ui/components/ToolStatsDisplay.js.map +1 -0
  378. package/dist/src/ui/components/UpdateNotification.d.ts +10 -0
  379. package/dist/src/ui/components/UpdateNotification.js +10 -0
  380. package/dist/src/ui/components/UpdateNotification.js.map +1 -0
  381. package/dist/src/ui/components/WorkspaceMigrationDialog.d.ts +11 -0
  382. package/dist/src/ui/components/WorkspaceMigrationDialog.js +42 -0
  383. package/dist/src/ui/components/WorkspaceMigrationDialog.js.map +1 -0
  384. package/dist/src/ui/components/messages/CompressionMessage.d.ts +11 -0
  385. package/dist/src/ui/components/messages/CompressionMessage.js +17 -0
  386. package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -0
  387. package/dist/src/ui/components/messages/DiffRenderer.d.ts +16 -0
  388. package/dist/src/ui/components/messages/DiffRenderer.js +226 -0
  389. package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -0
  390. package/dist/src/ui/components/messages/DiffRenderer.test.d.ts +6 -0
  391. package/dist/src/ui/components/messages/DiffRenderer.test.js +239 -0
  392. package/dist/src/ui/components/messages/DiffRenderer.test.js.map +1 -0
  393. package/dist/src/ui/components/messages/ErrorMessage.d.ts +11 -0
  394. package/dist/src/ui/components/messages/ErrorMessage.js +9 -0
  395. package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -0
  396. package/dist/src/ui/components/messages/GeminiMessage.d.ts +14 -0
  397. package/dist/src/ui/components/messages/GeminiMessage.js +11 -0
  398. package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -0
  399. package/dist/src/ui/components/messages/GeminiMessageContent.d.ts +14 -0
  400. package/dist/src/ui/components/messages/GeminiMessageContent.js +15 -0
  401. package/dist/src/ui/components/messages/GeminiMessageContent.js.map +1 -0
  402. package/dist/src/ui/components/messages/InfoMessage.d.ts +11 -0
  403. package/dist/src/ui/components/messages/InfoMessage.js +10 -0
  404. package/dist/src/ui/components/messages/InfoMessage.js.map +1 -0
  405. package/dist/src/ui/components/messages/ToolConfirmationMessage.d.ts +15 -0
  406. package/dist/src/ui/components/messages/ToolConfirmationMessage.js +162 -0
  407. package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -0
  408. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.d.ts +6 -0
  409. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js +122 -0
  410. package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js.map +1 -0
  411. package/dist/src/ui/components/messages/ToolGroupMessage.d.ts +18 -0
  412. package/dist/src/ui/components/messages/ToolGroupMessage.js +50 -0
  413. package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -0
  414. package/dist/src/ui/components/messages/ToolGroupMessage.test.d.ts +6 -0
  415. package/dist/src/ui/components/messages/ToolGroupMessage.test.js +259 -0
  416. package/dist/src/ui/components/messages/ToolGroupMessage.test.js.map +1 -0
  417. package/dist/src/ui/components/messages/ToolMessage.d.ts +15 -0
  418. package/dist/src/ui/components/messages/ToolMessage.js +62 -0
  419. package/dist/src/ui/components/messages/ToolMessage.js.map +1 -0
  420. package/dist/src/ui/components/messages/ToolMessage.test.d.ts +6 -0
  421. package/dist/src/ui/components/messages/ToolMessage.test.js +118 -0
  422. package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -0
  423. package/dist/src/ui/components/messages/UserMessage.d.ts +11 -0
  424. package/dist/src/ui/components/messages/UserMessage.js +14 -0
  425. package/dist/src/ui/components/messages/UserMessage.js.map +1 -0
  426. package/dist/src/ui/components/messages/UserShellMessage.d.ts +11 -0
  427. package/dist/src/ui/components/messages/UserShellMessage.js +9 -0
  428. package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -0
  429. package/dist/src/ui/components/shared/MaxSizedBox.d.ts +61 -0
  430. package/dist/src/ui/components/shared/MaxSizedBox.js +451 -0
  431. package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -0
  432. package/dist/src/ui/components/shared/MaxSizedBox.test.d.ts +6 -0
  433. package/dist/src/ui/components/shared/MaxSizedBox.test.js +154 -0
  434. package/dist/src/ui/components/shared/MaxSizedBox.test.js.map +1 -0
  435. package/dist/src/ui/components/shared/RadioButtonSelect.d.ts +46 -0
  436. package/dist/src/ui/components/shared/RadioButtonSelect.js +116 -0
  437. package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -0
  438. package/dist/src/ui/components/shared/RadioButtonSelect.test.d.ts +6 -0
  439. package/dist/src/ui/components/shared/RadioButtonSelect.test.js +111 -0
  440. package/dist/src/ui/components/shared/RadioButtonSelect.test.js.map +1 -0
  441. package/dist/src/ui/components/shared/text-buffer.d.ts +467 -0
  442. package/dist/src/ui/components/shared/text-buffer.js +1489 -0
  443. package/dist/src/ui/components/shared/text-buffer.js.map +1 -0
  444. package/dist/src/ui/components/shared/vim-buffer-actions.d.ts +72 -0
  445. package/dist/src/ui/components/shared/vim-buffer-actions.js +552 -0
  446. package/dist/src/ui/components/shared/vim-buffer-actions.js.map +1 -0
  447. package/dist/src/ui/constants.d.ts +17 -0
  448. package/dist/src/ui/constants.js +22 -0
  449. package/dist/src/ui/constants.js.map +1 -0
  450. package/dist/src/ui/contexts/KeypressContext.d.ts +31 -0
  451. package/dist/src/ui/contexts/KeypressContext.js +318 -0
  452. package/dist/src/ui/contexts/KeypressContext.js.map +1 -0
  453. package/dist/src/ui/contexts/KeypressContext.test.d.ts +6 -0
  454. package/dist/src/ui/contexts/KeypressContext.test.js +385 -0
  455. package/dist/src/ui/contexts/KeypressContext.test.js.map +1 -0
  456. package/dist/src/ui/contexts/OverflowContext.d.ts +19 -0
  457. package/dist/src/ui/contexts/OverflowContext.js +38 -0
  458. package/dist/src/ui/contexts/OverflowContext.js.map +1 -0
  459. package/dist/src/ui/contexts/SessionContext.d.ts +39 -0
  460. package/dist/src/ui/contexts/SessionContext.js +55 -0
  461. package/dist/src/ui/contexts/SessionContext.js.map +1 -0
  462. package/dist/src/ui/contexts/SettingsContext.d.ts +9 -0
  463. package/dist/src/ui/contexts/SettingsContext.js +15 -0
  464. package/dist/src/ui/contexts/SettingsContext.js.map +1 -0
  465. package/dist/src/ui/contexts/StreamingContext.d.ts +9 -0
  466. package/dist/src/ui/contexts/StreamingContext.js +15 -0
  467. package/dist/src/ui/contexts/StreamingContext.js.map +1 -0
  468. package/dist/src/ui/contexts/VimModeContext.d.ts +19 -0
  469. package/dist/src/ui/contexts/VimModeContext.js +48 -0
  470. package/dist/src/ui/contexts/VimModeContext.js.map +1 -0
  471. package/dist/src/ui/editors/editorSettingsManager.d.ts +19 -0
  472. package/dist/src/ui/editors/editorSettingsManager.js +47 -0
  473. package/dist/src/ui/editors/editorSettingsManager.js.map +1 -0
  474. package/dist/src/ui/hooks/atCommandProcessor.d.ts +31 -0
  475. package/dist/src/ui/hooks/atCommandProcessor.js +364 -0
  476. package/dist/src/ui/hooks/atCommandProcessor.js.map +1 -0
  477. package/dist/src/ui/hooks/atCommandProcessor.test.d.ts +6 -0
  478. package/dist/src/ui/hooks/atCommandProcessor.test.js +832 -0
  479. package/dist/src/ui/hooks/atCommandProcessor.test.js.map +1 -0
  480. package/dist/src/ui/hooks/shellCommandProcessor.d.ts +17 -0
  481. package/dist/src/ui/hooks/shellCommandProcessor.js +234 -0
  482. package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -0
  483. package/dist/src/ui/hooks/shellCommandProcessor.test.d.ts +6 -0
  484. package/dist/src/ui/hooks/shellCommandProcessor.test.js +325 -0
  485. package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -0
  486. package/dist/src/ui/hooks/slashCommandProcessor.d.ts +29 -0
  487. package/dist/src/ui/hooks/slashCommandProcessor.js +443 -0
  488. package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -0
  489. package/dist/src/ui/hooks/useAtCompletion.d.ts +23 -0
  490. package/dist/src/ui/hooks/useAtCompletion.js +179 -0
  491. package/dist/src/ui/hooks/useAtCompletion.js.map +1 -0
  492. package/dist/src/ui/hooks/useAuthCommand.d.ts +14 -0
  493. package/dist/src/ui/hooks/useAuthCommand.js +66 -0
  494. package/dist/src/ui/hooks/useAuthCommand.js.map +1 -0
  495. package/dist/src/ui/hooks/useAutoAcceptIndicator.d.ts +12 -0
  496. package/dist/src/ui/hooks/useAutoAcceptIndicator.js +46 -0
  497. package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -0
  498. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.d.ts +6 -0
  499. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js +311 -0
  500. package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js.map +1 -0
  501. package/dist/src/ui/hooks/useBracketedPaste.d.ts +12 -0
  502. package/dist/src/ui/hooks/useBracketedPaste.js +32 -0
  503. package/dist/src/ui/hooks/useBracketedPaste.js.map +1 -0
  504. package/dist/src/ui/hooks/useCommandCompletion.d.ts +32 -0
  505. package/dist/src/ui/hooks/useCommandCompletion.js +186 -0
  506. package/dist/src/ui/hooks/useCommandCompletion.js.map +1 -0
  507. package/dist/src/ui/hooks/useCompletion.d.ts +24 -0
  508. package/dist/src/ui/hooks/useCompletion.js +88 -0
  509. package/dist/src/ui/hooks/useCompletion.js.map +1 -0
  510. package/dist/src/ui/hooks/useConsoleMessages.d.ts +12 -0
  511. package/dist/src/ui/hooks/useConsoleMessages.js +76 -0
  512. package/dist/src/ui/hooks/useConsoleMessages.js.map +1 -0
  513. package/dist/src/ui/hooks/useEditorSettings.d.ts +16 -0
  514. package/dist/src/ui/hooks/useEditorSettings.js +43 -0
  515. package/dist/src/ui/hooks/useEditorSettings.js.map +1 -0
  516. package/dist/src/ui/hooks/useEditorSettings.test.d.ts +6 -0
  517. package/dist/src/ui/hooks/useEditorSettings.test.js +164 -0
  518. package/dist/src/ui/hooks/useEditorSettings.test.js.map +1 -0
  519. package/dist/src/ui/hooks/useFocus.d.ts +10 -0
  520. package/dist/src/ui/hooks/useFocus.js +41 -0
  521. package/dist/src/ui/hooks/useFocus.js.map +1 -0
  522. package/dist/src/ui/hooks/useFolderTrust.d.ts +13 -0
  523. package/dist/src/ui/hooks/useFolderTrust.js +64 -0
  524. package/dist/src/ui/hooks/useFolderTrust.js.map +1 -0
  525. package/dist/src/ui/hooks/useGeminiStream.d.ts +24 -0
  526. package/dist/src/ui/hooks/useGeminiStream.js +634 -0
  527. package/dist/src/ui/hooks/useGeminiStream.js.map +1 -0
  528. package/dist/src/ui/hooks/useGitBranchName.d.ts +6 -0
  529. package/dist/src/ui/hooks/useGitBranchName.js +61 -0
  530. package/dist/src/ui/hooks/useGitBranchName.js.map +1 -0
  531. package/dist/src/ui/hooks/useGitBranchName.test.d.ts +6 -0
  532. package/dist/src/ui/hooks/useGitBranchName.test.js +175 -0
  533. package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -0
  534. package/dist/src/ui/hooks/useHistoryManager.d.ts +22 -0
  535. package/dist/src/ui/hooks/useHistoryManager.js +72 -0
  536. package/dist/src/ui/hooks/useHistoryManager.js.map +1 -0
  537. package/dist/src/ui/hooks/useHistoryManager.test.d.ts +6 -0
  538. package/dist/src/ui/hooks/useHistoryManager.test.js +171 -0
  539. package/dist/src/ui/hooks/useHistoryManager.test.js.map +1 -0
  540. package/dist/src/ui/hooks/useInputHistory.d.ts +19 -0
  541. package/dist/src/ui/hooks/useInputHistory.js +84 -0
  542. package/dist/src/ui/hooks/useInputHistory.js.map +1 -0
  543. package/dist/src/ui/hooks/useInputHistory.test.d.ts +6 -0
  544. package/dist/src/ui/hooks/useInputHistory.test.js +207 -0
  545. package/dist/src/ui/hooks/useInputHistory.test.js.map +1 -0
  546. package/dist/src/ui/hooks/useKeypress.d.ts +17 -0
  547. package/dist/src/ui/hooks/useKeypress.js +27 -0
  548. package/dist/src/ui/hooks/useKeypress.js.map +1 -0
  549. package/dist/src/ui/hooks/useKittyKeyboardProtocol.d.ts +15 -0
  550. package/dist/src/ui/hooks/useKittyKeyboardProtocol.js +20 -0
  551. package/dist/src/ui/hooks/useKittyKeyboardProtocol.js.map +1 -0
  552. package/dist/src/ui/hooks/useLoadingIndicator.d.ts +10 -0
  553. package/dist/src/ui/hooks/useLoadingIndicator.js +44 -0
  554. package/dist/src/ui/hooks/useLoadingIndicator.js.map +1 -0
  555. package/dist/src/ui/hooks/useLoadingIndicator.test.d.ts +6 -0
  556. package/dist/src/ui/hooks/useLoadingIndicator.test.js +91 -0
  557. package/dist/src/ui/hooks/useLoadingIndicator.test.js.map +1 -0
  558. package/dist/src/ui/hooks/useLogger.d.ts +11 -0
  559. package/dist/src/ui/hooks/useLogger.js +29 -0
  560. package/dist/src/ui/hooks/useLogger.js.map +1 -0
  561. package/dist/src/ui/hooks/useMessageQueue.d.ts +22 -0
  562. package/dist/src/ui/hooks/useMessageQueue.js +49 -0
  563. package/dist/src/ui/hooks/useMessageQueue.js.map +1 -0
  564. package/dist/src/ui/hooks/useMessageQueue.test.d.ts +6 -0
  565. package/dist/src/ui/hooks/useMessageQueue.test.js +158 -0
  566. package/dist/src/ui/hooks/useMessageQueue.test.js.map +1 -0
  567. package/dist/src/ui/hooks/usePhraseCycler.d.ts +14 -0
  568. package/dist/src/ui/hooks/usePhraseCycler.js +187 -0
  569. package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -0
  570. package/dist/src/ui/hooks/usePrivacySettings.d.ts +16 -0
  571. package/dist/src/ui/hooks/usePrivacySettings.js +119 -0
  572. package/dist/src/ui/hooks/usePrivacySettings.js.map +1 -0
  573. package/dist/src/ui/hooks/usePrivacySettings.test.d.ts +6 -0
  574. package/dist/src/ui/hooks/usePrivacySettings.test.js +154 -0
  575. package/dist/src/ui/hooks/usePrivacySettings.test.js.map +1 -0
  576. package/dist/src/ui/hooks/usePromptCompletion.d.ts +23 -0
  577. package/dist/src/ui/hooks/usePromptCompletion.js +177 -0
  578. package/dist/src/ui/hooks/usePromptCompletion.js.map +1 -0
  579. package/dist/src/ui/hooks/useReactToolScheduler.d.ts +33 -0
  580. package/dist/src/ui/hooks/useReactToolScheduler.js +186 -0
  581. package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -0
  582. package/dist/src/ui/hooks/useRefreshMemoryCommand.d.ts +6 -0
  583. package/dist/src/ui/hooks/useRefreshMemoryCommand.js +7 -0
  584. package/dist/src/ui/hooks/useRefreshMemoryCommand.js.map +1 -0
  585. package/dist/src/ui/hooks/useReverseSearchCompletion.d.ts +19 -0
  586. package/dist/src/ui/hooks/useReverseSearchCompletion.js +56 -0
  587. package/dist/src/ui/hooks/useReverseSearchCompletion.js.map +1 -0
  588. package/dist/src/ui/hooks/useReverseSearchCompletion.test.d.ts +6 -0
  589. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js +163 -0
  590. package/dist/src/ui/hooks/useReverseSearchCompletion.test.js.map +1 -0
  591. package/dist/src/ui/hooks/useSettingsCommand.d.ts +10 -0
  592. package/dist/src/ui/hooks/useSettingsCommand.js +21 -0
  593. package/dist/src/ui/hooks/useSettingsCommand.js.map +1 -0
  594. package/dist/src/ui/hooks/useShellHistory.d.ts +14 -0
  595. package/dist/src/ui/hooks/useShellHistory.js +111 -0
  596. package/dist/src/ui/hooks/useShellHistory.js.map +1 -0
  597. package/dist/src/ui/hooks/useShellHistory.test.d.ts +6 -0
  598. package/dist/src/ui/hooks/useShellHistory.test.js +187 -0
  599. package/dist/src/ui/hooks/useShellHistory.test.js.map +1 -0
  600. package/dist/src/ui/hooks/useShowMemoryCommand.d.ts +9 -0
  601. package/dist/src/ui/hooks/useShowMemoryCommand.js +58 -0
  602. package/dist/src/ui/hooks/useShowMemoryCommand.js.map +1 -0
  603. package/dist/src/ui/hooks/useSlashCompletion.d.ts +20 -0
  604. package/dist/src/ui/hooks/useSlashCompletion.js +135 -0
  605. package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -0
  606. package/dist/src/ui/hooks/useSlashCompletion.test.d.ts +6 -0
  607. package/dist/src/ui/hooks/useSlashCompletion.test.js +272 -0
  608. package/dist/src/ui/hooks/useSlashCompletion.test.js.map +1 -0
  609. package/dist/src/ui/hooks/useStateAndRef.d.ts +7 -0
  610. package/dist/src/ui/hooks/useStateAndRef.js +26 -0
  611. package/dist/src/ui/hooks/useStateAndRef.js.map +1 -0
  612. package/dist/src/ui/hooks/useTerminalSize.d.ts +9 -0
  613. package/dist/src/ui/hooks/useTerminalSize.js +27 -0
  614. package/dist/src/ui/hooks/useTerminalSize.js.map +1 -0
  615. package/dist/src/ui/hooks/useThemeCommand.d.ts +15 -0
  616. package/dist/src/ui/hooks/useThemeCommand.js +79 -0
  617. package/dist/src/ui/hooks/useThemeCommand.js.map +1 -0
  618. package/dist/src/ui/hooks/useTimer.d.ts +12 -0
  619. package/dist/src/ui/hooks/useTimer.js +58 -0
  620. package/dist/src/ui/hooks/useTimer.js.map +1 -0
  621. package/dist/src/ui/hooks/useTimer.test.d.ts +6 -0
  622. package/dist/src/ui/hooks/useTimer.test.js +90 -0
  623. package/dist/src/ui/hooks/useTimer.test.js.map +1 -0
  624. package/dist/src/ui/hooks/useToolScheduler.test.d.ts +6 -0
  625. package/dist/src/ui/hooks/useToolScheduler.test.js +850 -0
  626. package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -0
  627. package/dist/src/ui/hooks/useWorkspaceMigration.d.ts +13 -0
  628. package/dist/src/ui/hooks/useWorkspaceMigration.js +53 -0
  629. package/dist/src/ui/hooks/useWorkspaceMigration.js.map +1 -0
  630. package/dist/src/ui/hooks/vim.d.ts +28 -0
  631. package/dist/src/ui/hooks/vim.js +639 -0
  632. package/dist/src/ui/hooks/vim.js.map +1 -0
  633. package/dist/src/ui/keyMatchers.d.ts +27 -0
  634. package/dist/src/ui/keyMatchers.js +68 -0
  635. package/dist/src/ui/keyMatchers.js.map +1 -0
  636. package/dist/src/ui/keyMatchers.test.d.ts +6 -0
  637. package/dist/src/ui/keyMatchers.test.js +276 -0
  638. package/dist/src/ui/keyMatchers.test.js.map +1 -0
  639. package/dist/src/ui/privacy/CloudFreePrivacyNotice.d.ts +12 -0
  640. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js +41 -0
  641. package/dist/src/ui/privacy/CloudFreePrivacyNotice.js.map +1 -0
  642. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.d.ts +10 -0
  643. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js +18 -0
  644. package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js.map +1 -0
  645. package/dist/src/ui/privacy/GeminiPrivacyNotice.d.ts +10 -0
  646. package/dist/src/ui/privacy/GeminiPrivacyNotice.js +18 -0
  647. package/dist/src/ui/privacy/GeminiPrivacyNotice.js.map +1 -0
  648. package/dist/src/ui/privacy/PrivacyNotice.d.ts +12 -0
  649. package/dist/src/ui/privacy/PrivacyNotice.js +25 -0
  650. package/dist/src/ui/privacy/PrivacyNotice.js.map +1 -0
  651. package/dist/src/ui/semantic-colors.d.ts +7 -0
  652. package/dist/src/ui/semantic-colors.js +24 -0
  653. package/dist/src/ui/semantic-colors.js.map +1 -0
  654. package/dist/src/ui/textConstants.d.ts +9 -0
  655. package/dist/src/ui/textConstants.js +10 -0
  656. package/dist/src/ui/textConstants.js.map +1 -0
  657. package/dist/src/ui/themes/ansi-light.d.ts +7 -0
  658. package/dist/src/ui/themes/ansi-light.js +142 -0
  659. package/dist/src/ui/themes/ansi-light.js.map +1 -0
  660. package/dist/src/ui/themes/ansi.d.ts +7 -0
  661. package/dist/src/ui/themes/ansi.js +152 -0
  662. package/dist/src/ui/themes/ansi.js.map +1 -0
  663. package/dist/src/ui/themes/atom-one-dark.d.ts +7 -0
  664. package/dist/src/ui/themes/atom-one-dark.js +138 -0
  665. package/dist/src/ui/themes/atom-one-dark.js.map +1 -0
  666. package/dist/src/ui/themes/ayu-light.d.ts +7 -0
  667. package/dist/src/ui/themes/ayu-light.js +130 -0
  668. package/dist/src/ui/themes/ayu-light.js.map +1 -0
  669. package/dist/src/ui/themes/ayu.d.ts +7 -0
  670. package/dist/src/ui/themes/ayu.js +104 -0
  671. package/dist/src/ui/themes/ayu.js.map +1 -0
  672. package/dist/src/ui/themes/color-utils.d.ts +21 -0
  673. package/dist/src/ui/themes/color-utils.js +221 -0
  674. package/dist/src/ui/themes/color-utils.js.map +1 -0
  675. package/dist/src/ui/themes/color-utils.test.d.ts +6 -0
  676. package/dist/src/ui/themes/color-utils.test.js +197 -0
  677. package/dist/src/ui/themes/color-utils.test.js.map +1 -0
  678. package/dist/src/ui/themes/default-light.d.ts +7 -0
  679. package/dist/src/ui/themes/default-light.js +100 -0
  680. package/dist/src/ui/themes/default-light.js.map +1 -0
  681. package/dist/src/ui/themes/default.d.ts +7 -0
  682. package/dist/src/ui/themes/default.js +143 -0
  683. package/dist/src/ui/themes/default.js.map +1 -0
  684. package/dist/src/ui/themes/dracula.d.ts +7 -0
  685. package/dist/src/ui/themes/dracula.js +115 -0
  686. package/dist/src/ui/themes/dracula.js.map +1 -0
  687. package/dist/src/ui/themes/github-dark.d.ts +7 -0
  688. package/dist/src/ui/themes/github-dark.js +138 -0
  689. package/dist/src/ui/themes/github-dark.js.map +1 -0
  690. package/dist/src/ui/themes/github-light.d.ts +7 -0
  691. package/dist/src/ui/themes/github-light.js +140 -0
  692. package/dist/src/ui/themes/github-light.js.map +1 -0
  693. package/dist/src/ui/themes/googlecode.d.ts +7 -0
  694. package/dist/src/ui/themes/googlecode.js +137 -0
  695. package/dist/src/ui/themes/googlecode.js.map +1 -0
  696. package/dist/src/ui/themes/no-color.d.ts +7 -0
  697. package/dist/src/ui/themes/no-color.js +115 -0
  698. package/dist/src/ui/themes/no-color.js.map +1 -0
  699. package/dist/src/ui/themes/semantic-tokens.d.ts +37 -0
  700. package/dist/src/ui/themes/semantic-tokens.js +94 -0
  701. package/dist/src/ui/themes/semantic-tokens.js.map +1 -0
  702. package/dist/src/ui/themes/shades-of-purple.d.ts +11 -0
  703. package/dist/src/ui/themes/shades-of-purple.js +304 -0
  704. package/dist/src/ui/themes/shades-of-purple.js.map +1 -0
  705. package/dist/src/ui/themes/theme-manager.d.ts +66 -0
  706. package/dist/src/ui/themes/theme-manager.js +262 -0
  707. package/dist/src/ui/themes/theme-manager.js.map +1 -0
  708. package/dist/src/ui/themes/theme-manager.test.d.ts +6 -0
  709. package/dist/src/ui/themes/theme-manager.test.js +142 -0
  710. package/dist/src/ui/themes/theme-manager.test.js.map +1 -0
  711. package/dist/src/ui/themes/theme.d.ts +130 -0
  712. package/dist/src/ui/themes/theme.js +379 -0
  713. package/dist/src/ui/themes/theme.js.map +1 -0
  714. package/dist/src/ui/themes/xcode.d.ts +7 -0
  715. package/dist/src/ui/themes/xcode.js +145 -0
  716. package/dist/src/ui/themes/xcode.js.map +1 -0
  717. package/dist/src/ui/types.d.ts +193 -0
  718. package/dist/src/ui/types.js +44 -0
  719. package/dist/src/ui/types.js.map +1 -0
  720. package/dist/src/ui/utils/CodeColorizer.d.ts +17 -0
  721. package/dist/src/ui/utils/CodeColorizer.js +110 -0
  722. package/dist/src/ui/utils/CodeColorizer.js.map +1 -0
  723. package/dist/src/ui/utils/ConsolePatcher.d.ts +25 -0
  724. package/dist/src/ui/utils/ConsolePatcher.js +52 -0
  725. package/dist/src/ui/utils/ConsolePatcher.js.map +1 -0
  726. package/dist/src/ui/utils/InlineMarkdownRenderer.d.ts +16 -0
  727. package/dist/src/ui/utils/InlineMarkdownRenderer.js +111 -0
  728. package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -0
  729. package/dist/src/ui/utils/MarkdownDisplay.d.ts +14 -0
  730. package/dist/src/ui/utils/MarkdownDisplay.js +208 -0
  731. package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -0
  732. package/dist/src/ui/utils/MarkdownDisplay.test.d.ts +6 -0
  733. package/dist/src/ui/utils/MarkdownDisplay.test.js +152 -0
  734. package/dist/src/ui/utils/MarkdownDisplay.test.js.map +1 -0
  735. package/dist/src/ui/utils/TableRenderer.d.ts +17 -0
  736. package/dist/src/ui/utils/TableRenderer.js +84 -0
  737. package/dist/src/ui/utils/TableRenderer.js.map +1 -0
  738. package/dist/src/ui/utils/clipboardUtils.d.ts +22 -0
  739. package/dist/src/ui/utils/clipboardUtils.js +127 -0
  740. package/dist/src/ui/utils/clipboardUtils.js.map +1 -0
  741. package/dist/src/ui/utils/clipboardUtils.test.d.ts +6 -0
  742. package/dist/src/ui/utils/clipboardUtils.test.js +65 -0
  743. package/dist/src/ui/utils/clipboardUtils.test.js.map +1 -0
  744. package/dist/src/ui/utils/commandUtils.d.ts +24 -0
  745. package/dist/src/ui/utils/commandUtils.js +131 -0
  746. package/dist/src/ui/utils/commandUtils.js.map +1 -0
  747. package/dist/src/ui/utils/commandUtils.test.d.ts +6 -0
  748. package/dist/src/ui/utils/commandUtils.test.js +349 -0
  749. package/dist/src/ui/utils/commandUtils.test.js.map +1 -0
  750. package/dist/src/ui/utils/computeStats.d.ts +10 -0
  751. package/dist/src/ui/utils/computeStats.js +57 -0
  752. package/dist/src/ui/utils/computeStats.js.map +1 -0
  753. package/dist/src/ui/utils/displayUtils.d.ts +17 -0
  754. package/dist/src/ui/utils/displayUtils.js +24 -0
  755. package/dist/src/ui/utils/displayUtils.js.map +1 -0
  756. package/dist/src/ui/utils/displayUtils.test.d.ts +6 -0
  757. package/dist/src/ui/utils/displayUtils.test.js +42 -0
  758. package/dist/src/ui/utils/displayUtils.test.js.map +1 -0
  759. package/dist/src/ui/utils/formatters.d.ts +13 -0
  760. package/dist/src/ui/utils/formatters.js +56 -0
  761. package/dist/src/ui/utils/formatters.js.map +1 -0
  762. package/dist/src/ui/utils/formatters.test.d.ts +6 -0
  763. package/dist/src/ui/utils/formatters.test.js +56 -0
  764. package/dist/src/ui/utils/formatters.test.js.map +1 -0
  765. package/dist/src/ui/utils/isNarrowWidth.d.ts +6 -0
  766. package/dist/src/ui/utils/isNarrowWidth.js +9 -0
  767. package/dist/src/ui/utils/isNarrowWidth.js.map +1 -0
  768. package/dist/src/ui/utils/kittyProtocolDetector.d.ts +13 -0
  769. package/dist/src/ui/utils/kittyProtocolDetector.js +88 -0
  770. package/dist/src/ui/utils/kittyProtocolDetector.js.map +1 -0
  771. package/dist/src/ui/utils/markdownUtilities.d.ts +6 -0
  772. package/dist/src/ui/utils/markdownUtilities.js +110 -0
  773. package/dist/src/ui/utils/markdownUtilities.js.map +1 -0
  774. package/dist/src/ui/utils/markdownUtilities.test.d.ts +6 -0
  775. package/dist/src/ui/utils/markdownUtilities.test.js +42 -0
  776. package/dist/src/ui/utils/markdownUtilities.test.js.map +1 -0
  777. package/dist/src/ui/utils/platformConstants.d.ts +52 -0
  778. package/dist/src/ui/utils/platformConstants.js +53 -0
  779. package/dist/src/ui/utils/platformConstants.js.map +1 -0
  780. package/dist/src/ui/utils/terminalSetup.d.ts +30 -0
  781. package/dist/src/ui/utils/terminalSetup.js +281 -0
  782. package/dist/src/ui/utils/terminalSetup.js.map +1 -0
  783. package/dist/src/ui/utils/textUtils.d.ts +32 -0
  784. package/dist/src/ui/utils/textUtils.js +80 -0
  785. package/dist/src/ui/utils/textUtils.js.map +1 -0
  786. package/dist/src/ui/utils/updateCheck.d.ts +12 -0
  787. package/dist/src/ui/utils/updateCheck.js +78 -0
  788. package/dist/src/ui/utils/updateCheck.js.map +1 -0
  789. package/dist/src/ui/utils/updateCheck.test.d.ts +6 -0
  790. package/dist/src/ui/utils/updateCheck.test.js +145 -0
  791. package/dist/src/ui/utils/updateCheck.test.js.map +1 -0
  792. package/dist/src/utils/checks.d.ts +19 -0
  793. package/dist/src/utils/checks.js +24 -0
  794. package/dist/src/utils/checks.js.map +1 -0
  795. package/dist/src/utils/cleanup.d.ts +8 -0
  796. package/dist/src/utils/cleanup.js +35 -0
  797. package/dist/src/utils/cleanup.js.map +1 -0
  798. package/dist/src/utils/dialogScopeUtils.d.ts +32 -0
  799. package/dist/src/utils/dialogScopeUtils.js +48 -0
  800. package/dist/src/utils/dialogScopeUtils.js.map +1 -0
  801. package/dist/src/utils/errors.d.ts +6 -0
  802. package/dist/src/utils/errors.js +12 -0
  803. package/dist/src/utils/errors.js.map +1 -0
  804. package/dist/src/utils/events.d.ts +11 -0
  805. package/dist/src/utils/events.js +13 -0
  806. package/dist/src/utils/events.js.map +1 -0
  807. package/dist/src/utils/gitUtils.d.ts +30 -0
  808. package/dist/src/utils/gitUtils.js +89 -0
  809. package/dist/src/utils/gitUtils.js.map +1 -0
  810. package/dist/src/utils/gitUtils.test.d.ts +6 -0
  811. package/dist/src/utils/gitUtils.test.js +113 -0
  812. package/dist/src/utils/gitUtils.test.js.map +1 -0
  813. package/dist/src/utils/handleAutoUpdate.d.ts +11 -0
  814. package/dist/src/utils/handleAutoUpdate.js +102 -0
  815. package/dist/src/utils/handleAutoUpdate.js.map +1 -0
  816. package/dist/src/utils/installationInfo.d.ts +23 -0
  817. package/dist/src/utils/installationInfo.js +154 -0
  818. package/dist/src/utils/installationInfo.js.map +1 -0
  819. package/dist/src/utils/installationInfo.test.d.ts +6 -0
  820. package/dist/src/utils/installationInfo.test.js +242 -0
  821. package/dist/src/utils/installationInfo.test.js.map +1 -0
  822. package/dist/src/utils/package.d.ts +12 -0
  823. package/dist/src/utils/package.js +24 -0
  824. package/dist/src/utils/package.js.map +1 -0
  825. package/dist/src/utils/readStdin.d.ts +6 -0
  826. package/dist/src/utils/readStdin.js +59 -0
  827. package/dist/src/utils/readStdin.js.map +1 -0
  828. package/dist/src/utils/readStdin.test.d.ts +6 -0
  829. package/dist/src/utils/readStdin.test.js +88 -0
  830. package/dist/src/utils/readStdin.test.js.map +1 -0
  831. package/dist/src/utils/resolvePath.d.ts +6 -0
  832. package/dist/src/utils/resolvePath.js +21 -0
  833. package/dist/src/utils/resolvePath.js.map +1 -0
  834. package/dist/src/utils/sandbox-macos-permissive-closed.sb +32 -0
  835. package/dist/src/utils/sandbox-macos-permissive-open.sb +25 -0
  836. package/dist/src/utils/sandbox-macos-permissive-proxied.sb +37 -0
  837. package/dist/src/utils/sandbox-macos-restrictive-closed.sb +93 -0
  838. package/dist/src/utils/sandbox-macos-restrictive-open.sb +96 -0
  839. package/dist/src/utils/sandbox-macos-restrictive-proxied.sb +98 -0
  840. package/dist/src/utils/sandbox.d.ts +7 -0
  841. package/dist/src/utils/sandbox.js +724 -0
  842. package/dist/src/utils/sandbox.js.map +1 -0
  843. package/dist/src/utils/settingsUtils.d.ts +134 -0
  844. package/dist/src/utils/settingsUtils.js +330 -0
  845. package/dist/src/utils/settingsUtils.js.map +1 -0
  846. package/dist/src/utils/settingsUtils.test.d.ts +6 -0
  847. package/dist/src/utils/settingsUtils.test.js +511 -0
  848. package/dist/src/utils/settingsUtils.test.js.map +1 -0
  849. package/dist/src/utils/spawnWrapper.d.ts +7 -0
  850. package/dist/src/utils/spawnWrapper.js +8 -0
  851. package/dist/src/utils/spawnWrapper.js.map +1 -0
  852. package/dist/src/utils/startupWarnings.d.ts +6 -0
  853. package/dist/src/utils/startupWarnings.js +40 -0
  854. package/dist/src/utils/startupWarnings.js.map +1 -0
  855. package/dist/src/utils/updateEventEmitter.d.ts +11 -0
  856. package/dist/src/utils/updateEventEmitter.js +12 -0
  857. package/dist/src/utils/updateEventEmitter.js.map +1 -0
  858. package/dist/src/utils/userStartupWarnings.d.ts +6 -0
  859. package/dist/src/utils/userStartupWarnings.js +54 -0
  860. package/dist/src/utils/userStartupWarnings.js.map +1 -0
  861. package/dist/src/utils/userStartupWarnings.test.d.ts +6 -0
  862. package/dist/src/utils/userStartupWarnings.test.js +67 -0
  863. package/dist/src/utils/userStartupWarnings.test.js.map +1 -0
  864. package/dist/src/utils/version.d.ts +6 -0
  865. package/dist/src/utils/version.js +11 -0
  866. package/dist/src/utils/version.js.map +1 -0
  867. package/dist/src/validateNonInterActiveAuth.d.ts +8 -0
  868. package/dist/src/validateNonInterActiveAuth.js +37 -0
  869. package/dist/src/validateNonInterActiveAuth.js.map +1 -0
  870. package/dist/src/zed-integration/acp.d.ts +63 -0
  871. package/dist/src/zed-integration/acp.js +226 -0
  872. package/dist/src/zed-integration/acp.js.map +1 -0
  873. package/dist/src/zed-integration/fileSystemService.d.ts +19 -0
  874. package/dist/src/zed-integration/fileSystemService.js +43 -0
  875. package/dist/src/zed-integration/fileSystemService.js.map +1 -0
  876. package/dist/src/zed-integration/schema.d.ts +11782 -0
  877. package/dist/src/zed-integration/schema.js +311 -0
  878. package/dist/src/zed-integration/schema.js.map +1 -0
  879. package/dist/src/zed-integration/zedIntegration.d.ts +10 -0
  880. package/dist/src/zed-integration/zedIntegration.js +740 -0
  881. package/dist/src/zed-integration/zedIntegration.js.map +1 -0
  882. package/dist/tsconfig.tsbuildinfo +1 -0
  883. package/package.json +85 -0
@@ -0,0 +1,1489 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { spawnSync } from 'node:child_process';
7
+ import fs from 'node:fs';
8
+ import os from 'node:os';
9
+ import pathMod from 'node:path';
10
+ import { useState, useCallback, useEffect, useMemo, useReducer } from 'react';
11
+ import stringWidth from 'string-width';
12
+ import { unescapePath } from '@google/gemini-cli-core';
13
+ import { toCodePoints, cpLen, cpSlice, stripUnsafeCharacters, } from '../../utils/textUtils.js';
14
+ import { handleVimAction } from './vim-buffer-actions.js';
15
+ // Simple helper for word‑wise ops.
16
+ function isWordChar(ch) {
17
+ if (ch === undefined) {
18
+ return false;
19
+ }
20
+ return !/[\s,.;!?]/.test(ch);
21
+ }
22
+ // Helper functions for line-based word navigation
23
+ export const isWordCharStrict = (char) => /[\w\p{L}\p{N}]/u.test(char); // Matches a single character that is any Unicode letter, any Unicode number, or an underscore
24
+ export const isWhitespace = (char) => /\s/.test(char);
25
+ // Check if a character is a combining mark (only diacritics for now)
26
+ export const isCombiningMark = (char) => /\p{M}/u.test(char);
27
+ // Check if a character should be considered part of a word (including combining marks)
28
+ export const isWordCharWithCombining = (char) => isWordCharStrict(char) || isCombiningMark(char);
29
+ // Get the script of a character (simplified for common scripts)
30
+ export const getCharScript = (char) => {
31
+ if (/[\p{Script=Latin}]/u.test(char))
32
+ return 'latin'; // All Latin script chars including diacritics
33
+ if (/[\p{Script=Han}]/u.test(char))
34
+ return 'han'; // Chinese
35
+ if (/[\p{Script=Arabic}]/u.test(char))
36
+ return 'arabic';
37
+ if (/[\p{Script=Hiragana}]/u.test(char))
38
+ return 'hiragana';
39
+ if (/[\p{Script=Katakana}]/u.test(char))
40
+ return 'katakana';
41
+ if (/[\p{Script=Cyrillic}]/u.test(char))
42
+ return 'cyrillic';
43
+ return 'other';
44
+ };
45
+ // Check if two characters are from different scripts (indicating word boundary)
46
+ export const isDifferentScript = (char1, char2) => {
47
+ if (!isWordCharStrict(char1) || !isWordCharStrict(char2))
48
+ return false;
49
+ return getCharScript(char1) !== getCharScript(char2);
50
+ };
51
+ // Find next word start within a line, starting from col
52
+ export const findNextWordStartInLine = (line, col) => {
53
+ const chars = toCodePoints(line);
54
+ let i = col;
55
+ if (i >= chars.length)
56
+ return null;
57
+ const currentChar = chars[i];
58
+ // Skip current word/sequence based on character type
59
+ if (isWordCharStrict(currentChar)) {
60
+ while (i < chars.length && isWordCharWithCombining(chars[i])) {
61
+ // Check for script boundary - if next character is from different script, stop here
62
+ if (i + 1 < chars.length &&
63
+ isWordCharStrict(chars[i + 1]) &&
64
+ isDifferentScript(chars[i], chars[i + 1])) {
65
+ i++; // Include current character
66
+ break; // Stop at script boundary
67
+ }
68
+ i++;
69
+ }
70
+ }
71
+ else if (!isWhitespace(currentChar)) {
72
+ while (i < chars.length &&
73
+ !isWordCharStrict(chars[i]) &&
74
+ !isWhitespace(chars[i])) {
75
+ i++;
76
+ }
77
+ }
78
+ // Skip whitespace
79
+ while (i < chars.length && isWhitespace(chars[i])) {
80
+ i++;
81
+ }
82
+ return i < chars.length ? i : null;
83
+ };
84
+ // Find previous word start within a line
85
+ export const findPrevWordStartInLine = (line, col) => {
86
+ const chars = toCodePoints(line);
87
+ let i = col;
88
+ if (i <= 0)
89
+ return null;
90
+ i--;
91
+ // Skip whitespace moving backwards
92
+ while (i >= 0 && isWhitespace(chars[i])) {
93
+ i--;
94
+ }
95
+ if (i < 0)
96
+ return null;
97
+ if (isWordCharStrict(chars[i])) {
98
+ // We're in a word, move to its beginning
99
+ while (i >= 0 && isWordCharStrict(chars[i])) {
100
+ // Check for script boundary - if previous character is from different script, stop here
101
+ if (i - 1 >= 0 &&
102
+ isWordCharStrict(chars[i - 1]) &&
103
+ isDifferentScript(chars[i], chars[i - 1])) {
104
+ return i; // Return current position at script boundary
105
+ }
106
+ i--;
107
+ }
108
+ return i + 1;
109
+ }
110
+ else {
111
+ // We're in punctuation, move to its beginning
112
+ while (i >= 0 && !isWordCharStrict(chars[i]) && !isWhitespace(chars[i])) {
113
+ i--;
114
+ }
115
+ return i + 1;
116
+ }
117
+ };
118
+ // Find word end within a line
119
+ export const findWordEndInLine = (line, col) => {
120
+ const chars = toCodePoints(line);
121
+ let i = col;
122
+ // If we're already at the end of a word (including punctuation sequences), advance to next word
123
+ // This includes both regular word endings and script boundaries
124
+ const atEndOfWordChar = i < chars.length &&
125
+ isWordCharWithCombining(chars[i]) &&
126
+ (i + 1 >= chars.length ||
127
+ !isWordCharWithCombining(chars[i + 1]) ||
128
+ (isWordCharStrict(chars[i]) &&
129
+ i + 1 < chars.length &&
130
+ isWordCharStrict(chars[i + 1]) &&
131
+ isDifferentScript(chars[i], chars[i + 1])));
132
+ const atEndOfPunctuation = i < chars.length &&
133
+ !isWordCharWithCombining(chars[i]) &&
134
+ !isWhitespace(chars[i]) &&
135
+ (i + 1 >= chars.length ||
136
+ isWhitespace(chars[i + 1]) ||
137
+ isWordCharWithCombining(chars[i + 1]));
138
+ if (atEndOfWordChar || atEndOfPunctuation) {
139
+ // We're at the end of a word or punctuation sequence, move forward to find next word
140
+ i++;
141
+ // Skip whitespace to find next word or punctuation
142
+ while (i < chars.length && isWhitespace(chars[i])) {
143
+ i++;
144
+ }
145
+ }
146
+ // If we're not on a word character, find the next word or punctuation sequence
147
+ if (i < chars.length && !isWordCharWithCombining(chars[i])) {
148
+ // Skip whitespace to find next word or punctuation
149
+ while (i < chars.length && isWhitespace(chars[i])) {
150
+ i++;
151
+ }
152
+ }
153
+ // Move to end of current word (including combining marks, but stop at script boundaries)
154
+ let foundWord = false;
155
+ let lastBaseCharPos = -1;
156
+ if (i < chars.length && isWordCharWithCombining(chars[i])) {
157
+ // Handle word characters
158
+ while (i < chars.length && isWordCharWithCombining(chars[i])) {
159
+ foundWord = true;
160
+ // Track the position of the last base character (not combining mark)
161
+ if (isWordCharStrict(chars[i])) {
162
+ lastBaseCharPos = i;
163
+ }
164
+ // Check if next character is from a different script (word boundary)
165
+ if (i + 1 < chars.length &&
166
+ isWordCharStrict(chars[i + 1]) &&
167
+ isDifferentScript(chars[i], chars[i + 1])) {
168
+ i++; // Include current character
169
+ if (isWordCharStrict(chars[i - 1])) {
170
+ lastBaseCharPos = i - 1;
171
+ }
172
+ break; // Stop at script boundary
173
+ }
174
+ i++;
175
+ }
176
+ }
177
+ else if (i < chars.length && !isWhitespace(chars[i])) {
178
+ // Handle punctuation sequences (like ████)
179
+ while (i < chars.length &&
180
+ !isWordCharStrict(chars[i]) &&
181
+ !isWhitespace(chars[i])) {
182
+ foundWord = true;
183
+ lastBaseCharPos = i;
184
+ i++;
185
+ }
186
+ }
187
+ // Only return a position if we actually found a word
188
+ // Return the position of the last base character, not combining marks
189
+ if (foundWord && lastBaseCharPos >= col) {
190
+ return lastBaseCharPos;
191
+ }
192
+ return null;
193
+ };
194
+ // Find next word across lines
195
+ export const findNextWordAcrossLines = (lines, cursorRow, cursorCol, searchForWordStart) => {
196
+ // First try current line
197
+ const currentLine = lines[cursorRow] || '';
198
+ const colInCurrentLine = searchForWordStart
199
+ ? findNextWordStartInLine(currentLine, cursorCol)
200
+ : findWordEndInLine(currentLine, cursorCol);
201
+ if (colInCurrentLine !== null) {
202
+ return { row: cursorRow, col: colInCurrentLine };
203
+ }
204
+ // Search subsequent lines
205
+ for (let row = cursorRow + 1; row < lines.length; row++) {
206
+ const line = lines[row] || '';
207
+ const chars = toCodePoints(line);
208
+ // For empty lines, if we haven't found any words yet, return the empty line
209
+ if (chars.length === 0) {
210
+ // Check if there are any words in remaining lines
211
+ let hasWordsInLaterLines = false;
212
+ for (let laterRow = row + 1; laterRow < lines.length; laterRow++) {
213
+ const laterLine = lines[laterRow] || '';
214
+ const laterChars = toCodePoints(laterLine);
215
+ let firstNonWhitespace = 0;
216
+ while (firstNonWhitespace < laterChars.length &&
217
+ isWhitespace(laterChars[firstNonWhitespace])) {
218
+ firstNonWhitespace++;
219
+ }
220
+ if (firstNonWhitespace < laterChars.length) {
221
+ hasWordsInLaterLines = true;
222
+ break;
223
+ }
224
+ }
225
+ // If no words in later lines, return the empty line
226
+ if (!hasWordsInLaterLines) {
227
+ return { row, col: 0 };
228
+ }
229
+ continue;
230
+ }
231
+ // Find first non-whitespace
232
+ let firstNonWhitespace = 0;
233
+ while (firstNonWhitespace < chars.length &&
234
+ isWhitespace(chars[firstNonWhitespace])) {
235
+ firstNonWhitespace++;
236
+ }
237
+ if (firstNonWhitespace < chars.length) {
238
+ if (searchForWordStart) {
239
+ return { row, col: firstNonWhitespace };
240
+ }
241
+ else {
242
+ // For word end, find the end of the first word
243
+ const endCol = findWordEndInLine(line, firstNonWhitespace);
244
+ if (endCol !== null) {
245
+ return { row, col: endCol };
246
+ }
247
+ }
248
+ }
249
+ }
250
+ return null;
251
+ };
252
+ // Find previous word across lines
253
+ export const findPrevWordAcrossLines = (lines, cursorRow, cursorCol) => {
254
+ // First try current line
255
+ const currentLine = lines[cursorRow] || '';
256
+ const colInCurrentLine = findPrevWordStartInLine(currentLine, cursorCol);
257
+ if (colInCurrentLine !== null) {
258
+ return { row: cursorRow, col: colInCurrentLine };
259
+ }
260
+ // Search previous lines
261
+ for (let row = cursorRow - 1; row >= 0; row--) {
262
+ const line = lines[row] || '';
263
+ const chars = toCodePoints(line);
264
+ if (chars.length === 0)
265
+ continue;
266
+ // Find last word start
267
+ let lastWordStart = chars.length;
268
+ while (lastWordStart > 0 && isWhitespace(chars[lastWordStart - 1])) {
269
+ lastWordStart--;
270
+ }
271
+ if (lastWordStart > 0) {
272
+ // Find start of this word
273
+ const wordStart = findPrevWordStartInLine(line, lastWordStart);
274
+ if (wordStart !== null) {
275
+ return { row, col: wordStart };
276
+ }
277
+ }
278
+ }
279
+ return null;
280
+ };
281
+ // Helper functions for vim line operations
282
+ export const getPositionFromOffsets = (startOffset, endOffset, lines) => {
283
+ let offset = 0;
284
+ let startRow = 0;
285
+ let startCol = 0;
286
+ let endRow = 0;
287
+ let endCol = 0;
288
+ // Find start position
289
+ for (let i = 0; i < lines.length; i++) {
290
+ const lineLength = lines[i].length + 1; // +1 for newline
291
+ if (offset + lineLength > startOffset) {
292
+ startRow = i;
293
+ startCol = startOffset - offset;
294
+ break;
295
+ }
296
+ offset += lineLength;
297
+ }
298
+ // Find end position
299
+ offset = 0;
300
+ for (let i = 0; i < lines.length; i++) {
301
+ const lineLength = lines[i].length + (i < lines.length - 1 ? 1 : 0); // +1 for newline except last line
302
+ if (offset + lineLength >= endOffset) {
303
+ endRow = i;
304
+ endCol = endOffset - offset;
305
+ break;
306
+ }
307
+ offset += lineLength;
308
+ }
309
+ return { startRow, startCol, endRow, endCol };
310
+ };
311
+ export const getLineRangeOffsets = (startRow, lineCount, lines) => {
312
+ let startOffset = 0;
313
+ // Calculate start offset
314
+ for (let i = 0; i < startRow; i++) {
315
+ startOffset += lines[i].length + 1; // +1 for newline
316
+ }
317
+ // Calculate end offset
318
+ let endOffset = startOffset;
319
+ for (let i = 0; i < lineCount; i++) {
320
+ const lineIndex = startRow + i;
321
+ if (lineIndex < lines.length) {
322
+ endOffset += lines[lineIndex].length;
323
+ if (lineIndex < lines.length - 1) {
324
+ endOffset += 1; // +1 for newline
325
+ }
326
+ }
327
+ }
328
+ return { startOffset, endOffset };
329
+ };
330
+ export const replaceRangeInternal = (state, startRow, startCol, endRow, endCol, text) => {
331
+ const currentLine = (row) => state.lines[row] || '';
332
+ const currentLineLen = (row) => cpLen(currentLine(row));
333
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
334
+ if (startRow > endRow ||
335
+ (startRow === endRow && startCol > endCol) ||
336
+ startRow < 0 ||
337
+ startCol < 0 ||
338
+ endRow >= state.lines.length ||
339
+ (endRow < state.lines.length && endCol > currentLineLen(endRow))) {
340
+ return state; // Invalid range
341
+ }
342
+ const newLines = [...state.lines];
343
+ const sCol = clamp(startCol, 0, currentLineLen(startRow));
344
+ const eCol = clamp(endCol, 0, currentLineLen(endRow));
345
+ const prefix = cpSlice(currentLine(startRow), 0, sCol);
346
+ const suffix = cpSlice(currentLine(endRow), eCol);
347
+ const normalisedReplacement = text
348
+ .replace(/\r\n/g, '\n')
349
+ .replace(/\r/g, '\n');
350
+ const replacementParts = normalisedReplacement.split('\n');
351
+ // The combined first line of the new text
352
+ const firstLine = prefix + replacementParts[0];
353
+ if (replacementParts.length === 1) {
354
+ // No newlines in replacement: combine prefix, replacement, and suffix on one line.
355
+ newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
356
+ }
357
+ else {
358
+ // Newlines in replacement: create new lines.
359
+ const lastLine = replacementParts[replacementParts.length - 1] + suffix;
360
+ const middleLines = replacementParts.slice(1, -1);
361
+ newLines.splice(startRow, endRow - startRow + 1, firstLine, ...middleLines, lastLine);
362
+ }
363
+ const finalCursorRow = startRow + replacementParts.length - 1;
364
+ const finalCursorCol = (replacementParts.length > 1 ? 0 : sCol) +
365
+ cpLen(replacementParts[replacementParts.length - 1]);
366
+ return {
367
+ ...state,
368
+ lines: newLines,
369
+ cursorRow: Math.min(Math.max(finalCursorRow, 0), newLines.length - 1),
370
+ cursorCol: Math.max(0, Math.min(finalCursorCol, cpLen(newLines[finalCursorRow] || ''))),
371
+ preferredCol: null,
372
+ };
373
+ };
374
+ function clamp(v, min, max) {
375
+ return v < min ? min : v > max ? max : v;
376
+ }
377
+ function calculateInitialCursorPosition(initialLines, offset) {
378
+ let remainingChars = offset;
379
+ let row = 0;
380
+ while (row < initialLines.length) {
381
+ const lineLength = cpLen(initialLines[row]);
382
+ // Add 1 for the newline character (except for the last line)
383
+ const totalCharsInLineAndNewline = lineLength + (row < initialLines.length - 1 ? 1 : 0);
384
+ if (remainingChars <= lineLength) {
385
+ // Cursor is on this line
386
+ return [row, remainingChars];
387
+ }
388
+ remainingChars -= totalCharsInLineAndNewline;
389
+ row++;
390
+ }
391
+ // Offset is beyond the text, place cursor at the end of the last line
392
+ if (initialLines.length > 0) {
393
+ const lastRow = initialLines.length - 1;
394
+ return [lastRow, cpLen(initialLines[lastRow])];
395
+ }
396
+ return [0, 0]; // Default for empty text
397
+ }
398
+ export function offsetToLogicalPos(text, offset) {
399
+ let row = 0;
400
+ let col = 0;
401
+ let currentOffset = 0;
402
+ if (offset === 0)
403
+ return [0, 0];
404
+ const lines = text.split('\n');
405
+ for (let i = 0; i < lines.length; i++) {
406
+ const line = lines[i];
407
+ const lineLength = cpLen(line);
408
+ const lineLengthWithNewline = lineLength + (i < lines.length - 1 ? 1 : 0);
409
+ if (offset <= currentOffset + lineLength) {
410
+ // Check against lineLength first
411
+ row = i;
412
+ col = offset - currentOffset;
413
+ return [row, col];
414
+ }
415
+ else if (offset <= currentOffset + lineLengthWithNewline) {
416
+ // Check if offset is the newline itself
417
+ row = i;
418
+ col = lineLength; // Position cursor at the end of the current line content
419
+ // If the offset IS the newline, and it's not the last line, advance to next line, col 0
420
+ if (offset === currentOffset + lineLengthWithNewline &&
421
+ i < lines.length - 1) {
422
+ return [i + 1, 0];
423
+ }
424
+ return [row, col]; // Otherwise, it's at the end of the current line content
425
+ }
426
+ currentOffset += lineLengthWithNewline;
427
+ }
428
+ // If offset is beyond the text length, place cursor at the end of the last line
429
+ // or [0,0] if text is empty
430
+ if (lines.length > 0) {
431
+ row = lines.length - 1;
432
+ col = cpLen(lines[row]);
433
+ }
434
+ else {
435
+ row = 0;
436
+ col = 0;
437
+ }
438
+ return [row, col];
439
+ }
440
+ /**
441
+ * Converts logical row/col position to absolute text offset
442
+ * Inverse operation of offsetToLogicalPos
443
+ */
444
+ export function logicalPosToOffset(lines, row, col) {
445
+ let offset = 0;
446
+ // Clamp row to valid range
447
+ const actualRow = Math.min(row, lines.length - 1);
448
+ // Add lengths of all lines before the target row
449
+ for (let i = 0; i < actualRow; i++) {
450
+ offset += cpLen(lines[i]) + 1; // +1 for newline
451
+ }
452
+ // Add column offset within the target row
453
+ if (actualRow >= 0 && actualRow < lines.length) {
454
+ offset += Math.min(col, cpLen(lines[actualRow]));
455
+ }
456
+ return offset;
457
+ }
458
+ // Helper to calculate visual lines and map cursor positions
459
+ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
460
+ const visualLines = [];
461
+ const logicalToVisualMap = [];
462
+ const visualToLogicalMap = [];
463
+ let currentVisualCursor = [0, 0];
464
+ logicalLines.forEach((logLine, logIndex) => {
465
+ logicalToVisualMap[logIndex] = [];
466
+ if (logLine.length === 0) {
467
+ // Handle empty logical line
468
+ logicalToVisualMap[logIndex].push([visualLines.length, 0]);
469
+ visualToLogicalMap.push([logIndex, 0]);
470
+ visualLines.push('');
471
+ if (logIndex === logicalCursor[0] && logicalCursor[1] === 0) {
472
+ currentVisualCursor = [visualLines.length - 1, 0];
473
+ }
474
+ }
475
+ else {
476
+ // Non-empty logical line
477
+ let currentPosInLogLine = 0; // Tracks position within the current logical line (code point index)
478
+ const codePointsInLogLine = toCodePoints(logLine);
479
+ while (currentPosInLogLine < codePointsInLogLine.length) {
480
+ let currentChunk = '';
481
+ let currentChunkVisualWidth = 0;
482
+ let numCodePointsInChunk = 0;
483
+ let lastWordBreakPoint = -1; // Index in codePointsInLogLine for word break
484
+ let numCodePointsAtLastWordBreak = 0;
485
+ // Iterate through code points to build the current visual line (chunk)
486
+ for (let i = currentPosInLogLine; i < codePointsInLogLine.length; i++) {
487
+ const char = codePointsInLogLine[i];
488
+ const charVisualWidth = stringWidth(char);
489
+ if (currentChunkVisualWidth + charVisualWidth > viewportWidth) {
490
+ // Character would exceed viewport width
491
+ if (lastWordBreakPoint !== -1 &&
492
+ numCodePointsAtLastWordBreak > 0 &&
493
+ currentPosInLogLine + numCodePointsAtLastWordBreak < i) {
494
+ // We have a valid word break point to use, and it's not the start of the current segment
495
+ currentChunk = codePointsInLogLine
496
+ .slice(currentPosInLogLine, currentPosInLogLine + numCodePointsAtLastWordBreak)
497
+ .join('');
498
+ numCodePointsInChunk = numCodePointsAtLastWordBreak;
499
+ }
500
+ else {
501
+ // No word break, or word break is at the start of this potential chunk, or word break leads to empty chunk.
502
+ // Hard break: take characters up to viewportWidth, or just the current char if it alone is too wide.
503
+ if (numCodePointsInChunk === 0 &&
504
+ charVisualWidth > viewportWidth) {
505
+ // Single character is wider than viewport, take it anyway
506
+ currentChunk = char;
507
+ numCodePointsInChunk = 1;
508
+ }
509
+ else if (numCodePointsInChunk === 0 &&
510
+ charVisualWidth <= viewportWidth) {
511
+ // This case should ideally be caught by the next iteration if the char fits.
512
+ // If it doesn't fit (because currentChunkVisualWidth was already > 0 from a previous char that filled the line),
513
+ // then numCodePointsInChunk would not be 0.
514
+ // This branch means the current char *itself* doesn't fit an empty line, which is handled by the above.
515
+ // If we are here, it means the loop should break and the current chunk (which is empty) is finalized.
516
+ }
517
+ }
518
+ break; // Break from inner loop to finalize this chunk
519
+ }
520
+ currentChunk += char;
521
+ currentChunkVisualWidth += charVisualWidth;
522
+ numCodePointsInChunk++;
523
+ // Check for word break opportunity (space)
524
+ if (char === ' ') {
525
+ lastWordBreakPoint = i; // Store code point index of the space
526
+ // Store the state *before* adding the space, if we decide to break here.
527
+ numCodePointsAtLastWordBreak = numCodePointsInChunk - 1; // Chars *before* the space
528
+ }
529
+ }
530
+ // If the inner loop completed without breaking (i.e., remaining text fits)
531
+ // or if the loop broke but numCodePointsInChunk is still 0 (e.g. first char too wide for empty line)
532
+ if (numCodePointsInChunk === 0 &&
533
+ currentPosInLogLine < codePointsInLogLine.length) {
534
+ // This can happen if the very first character considered for a new visual line is wider than the viewport.
535
+ // In this case, we take that single character.
536
+ const firstChar = codePointsInLogLine[currentPosInLogLine];
537
+ currentChunk = firstChar;
538
+ numCodePointsInChunk = 1; // Ensure we advance
539
+ }
540
+ // If after everything, numCodePointsInChunk is still 0 but we haven't processed the whole logical line,
541
+ // it implies an issue, like viewportWidth being 0 or less. Avoid infinite loop.
542
+ if (numCodePointsInChunk === 0 &&
543
+ currentPosInLogLine < codePointsInLogLine.length) {
544
+ // Force advance by one character to prevent infinite loop if something went wrong
545
+ currentChunk = codePointsInLogLine[currentPosInLogLine];
546
+ numCodePointsInChunk = 1;
547
+ }
548
+ logicalToVisualMap[logIndex].push([
549
+ visualLines.length,
550
+ currentPosInLogLine,
551
+ ]);
552
+ visualToLogicalMap.push([logIndex, currentPosInLogLine]);
553
+ visualLines.push(currentChunk);
554
+ // Cursor mapping logic
555
+ // Note: currentPosInLogLine here is the start of the currentChunk within the logical line.
556
+ if (logIndex === logicalCursor[0]) {
557
+ const cursorLogCol = logicalCursor[1]; // This is a code point index
558
+ if (cursorLogCol >= currentPosInLogLine &&
559
+ cursorLogCol < currentPosInLogLine + numCodePointsInChunk // Cursor is within this chunk
560
+ ) {
561
+ currentVisualCursor = [
562
+ visualLines.length - 1,
563
+ cursorLogCol - currentPosInLogLine, // Visual col is also code point index within visual line
564
+ ];
565
+ }
566
+ else if (cursorLogCol === currentPosInLogLine + numCodePointsInChunk &&
567
+ numCodePointsInChunk > 0) {
568
+ // Cursor is exactly at the end of this non-empty chunk
569
+ currentVisualCursor = [
570
+ visualLines.length - 1,
571
+ numCodePointsInChunk,
572
+ ];
573
+ }
574
+ }
575
+ const logicalStartOfThisChunk = currentPosInLogLine;
576
+ currentPosInLogLine += numCodePointsInChunk;
577
+ // If the chunk processed did not consume the entire logical line,
578
+ // and the character immediately following the chunk is a space,
579
+ // advance past this space as it acted as a delimiter for word wrapping.
580
+ if (logicalStartOfThisChunk + numCodePointsInChunk <
581
+ codePointsInLogLine.length &&
582
+ currentPosInLogLine < codePointsInLogLine.length && // Redundant if previous is true, but safe
583
+ codePointsInLogLine[currentPosInLogLine] === ' ') {
584
+ currentPosInLogLine++;
585
+ }
586
+ }
587
+ // After all chunks of a non-empty logical line are processed,
588
+ // if the cursor is at the very end of this logical line, update visual cursor.
589
+ if (logIndex === logicalCursor[0] &&
590
+ logicalCursor[1] === codePointsInLogLine.length // Cursor at end of logical line
591
+ ) {
592
+ const lastVisualLineIdx = visualLines.length - 1;
593
+ if (lastVisualLineIdx >= 0 &&
594
+ visualLines[lastVisualLineIdx] !== undefined) {
595
+ currentVisualCursor = [
596
+ lastVisualLineIdx,
597
+ cpLen(visualLines[lastVisualLineIdx]), // Cursor at end of last visual line for this logical line
598
+ ];
599
+ }
600
+ }
601
+ }
602
+ });
603
+ // If the entire logical text was empty, ensure there's one empty visual line.
604
+ if (logicalLines.length === 0 ||
605
+ (logicalLines.length === 1 && logicalLines[0] === '')) {
606
+ if (visualLines.length === 0) {
607
+ visualLines.push('');
608
+ if (!logicalToVisualMap[0])
609
+ logicalToVisualMap[0] = [];
610
+ logicalToVisualMap[0].push([0, 0]);
611
+ visualToLogicalMap.push([0, 0]);
612
+ }
613
+ currentVisualCursor = [0, 0];
614
+ }
615
+ // Handle cursor at the very end of the text (after all processing)
616
+ // This case might be covered by the loop end condition now, but kept for safety.
617
+ else if (logicalCursor[0] === logicalLines.length - 1 &&
618
+ logicalCursor[1] === cpLen(logicalLines[logicalLines.length - 1]) &&
619
+ visualLines.length > 0) {
620
+ const lastVisLineIdx = visualLines.length - 1;
621
+ currentVisualCursor = [lastVisLineIdx, cpLen(visualLines[lastVisLineIdx])];
622
+ }
623
+ return {
624
+ visualLines,
625
+ visualCursor: currentVisualCursor,
626
+ logicalToVisualMap,
627
+ visualToLogicalMap,
628
+ };
629
+ }
630
+ const historyLimit = 100;
631
+ export const pushUndo = (currentState) => {
632
+ const snapshot = {
633
+ lines: [...currentState.lines],
634
+ cursorRow: currentState.cursorRow,
635
+ cursorCol: currentState.cursorCol,
636
+ };
637
+ const newStack = [...currentState.undoStack, snapshot];
638
+ if (newStack.length > historyLimit) {
639
+ newStack.shift();
640
+ }
641
+ return { ...currentState, undoStack: newStack, redoStack: [] };
642
+ };
643
+ export function textBufferReducer(state, action) {
644
+ const pushUndoLocal = pushUndo;
645
+ const currentLine = (r) => state.lines[r] ?? '';
646
+ const currentLineLen = (r) => cpLen(currentLine(r));
647
+ switch (action.type) {
648
+ case 'set_text': {
649
+ let nextState = state;
650
+ if (action.pushToUndo !== false) {
651
+ nextState = pushUndoLocal(state);
652
+ }
653
+ const newContentLines = action.payload
654
+ .replace(/\r\n?/g, '\n')
655
+ .split('\n');
656
+ const lines = newContentLines.length === 0 ? [''] : newContentLines;
657
+ const lastNewLineIndex = lines.length - 1;
658
+ return {
659
+ ...nextState,
660
+ lines,
661
+ cursorRow: lastNewLineIndex,
662
+ cursorCol: cpLen(lines[lastNewLineIndex] ?? ''),
663
+ preferredCol: null,
664
+ };
665
+ }
666
+ case 'insert': {
667
+ const nextState = pushUndoLocal(state);
668
+ const newLines = [...nextState.lines];
669
+ let newCursorRow = nextState.cursorRow;
670
+ let newCursorCol = nextState.cursorCol;
671
+ const currentLine = (r) => newLines[r] ?? '';
672
+ const str = stripUnsafeCharacters(action.payload.replace(/\r\n/g, '\n').replace(/\r/g, '\n'));
673
+ const parts = str.split('\n');
674
+ const lineContent = currentLine(newCursorRow);
675
+ const before = cpSlice(lineContent, 0, newCursorCol);
676
+ const after = cpSlice(lineContent, newCursorCol);
677
+ if (parts.length > 1) {
678
+ newLines[newCursorRow] = before + parts[0];
679
+ const remainingParts = parts.slice(1);
680
+ const lastPartOriginal = remainingParts.pop() ?? '';
681
+ newLines.splice(newCursorRow + 1, 0, ...remainingParts);
682
+ newLines.splice(newCursorRow + parts.length - 1, 0, lastPartOriginal + after);
683
+ newCursorRow = newCursorRow + parts.length - 1;
684
+ newCursorCol = cpLen(lastPartOriginal);
685
+ }
686
+ else {
687
+ newLines[newCursorRow] = before + parts[0] + after;
688
+ newCursorCol = cpLen(before) + cpLen(parts[0]);
689
+ }
690
+ return {
691
+ ...nextState,
692
+ lines: newLines,
693
+ cursorRow: newCursorRow,
694
+ cursorCol: newCursorCol,
695
+ preferredCol: null,
696
+ };
697
+ }
698
+ case 'backspace': {
699
+ const nextState = pushUndoLocal(state);
700
+ const newLines = [...nextState.lines];
701
+ let newCursorRow = nextState.cursorRow;
702
+ let newCursorCol = nextState.cursorCol;
703
+ const currentLine = (r) => newLines[r] ?? '';
704
+ if (newCursorCol === 0 && newCursorRow === 0)
705
+ return state;
706
+ if (newCursorCol > 0) {
707
+ const lineContent = currentLine(newCursorRow);
708
+ newLines[newCursorRow] =
709
+ cpSlice(lineContent, 0, newCursorCol - 1) +
710
+ cpSlice(lineContent, newCursorCol);
711
+ newCursorCol--;
712
+ }
713
+ else if (newCursorRow > 0) {
714
+ const prevLineContent = currentLine(newCursorRow - 1);
715
+ const currentLineContentVal = currentLine(newCursorRow);
716
+ const newCol = cpLen(prevLineContent);
717
+ newLines[newCursorRow - 1] = prevLineContent + currentLineContentVal;
718
+ newLines.splice(newCursorRow, 1);
719
+ newCursorRow--;
720
+ newCursorCol = newCol;
721
+ }
722
+ return {
723
+ ...nextState,
724
+ lines: newLines,
725
+ cursorRow: newCursorRow,
726
+ cursorCol: newCursorCol,
727
+ preferredCol: null,
728
+ };
729
+ }
730
+ case 'set_viewport_width': {
731
+ if (action.payload === state.viewportWidth) {
732
+ return state;
733
+ }
734
+ return { ...state, viewportWidth: action.payload };
735
+ }
736
+ case 'move': {
737
+ const { dir } = action.payload;
738
+ const { lines, cursorRow, cursorCol, viewportWidth } = state;
739
+ const visualLayout = calculateVisualLayout(lines, [cursorRow, cursorCol], viewportWidth);
740
+ const { visualLines, visualCursor, visualToLogicalMap } = visualLayout;
741
+ let newVisualRow = visualCursor[0];
742
+ let newVisualCol = visualCursor[1];
743
+ let newPreferredCol = state.preferredCol;
744
+ const currentVisLineLen = cpLen(visualLines[newVisualRow] ?? '');
745
+ switch (dir) {
746
+ case 'left':
747
+ newPreferredCol = null;
748
+ if (newVisualCol > 0) {
749
+ newVisualCol--;
750
+ }
751
+ else if (newVisualRow > 0) {
752
+ newVisualRow--;
753
+ newVisualCol = cpLen(visualLines[newVisualRow] ?? '');
754
+ }
755
+ break;
756
+ case 'right':
757
+ newPreferredCol = null;
758
+ if (newVisualCol < currentVisLineLen) {
759
+ newVisualCol++;
760
+ }
761
+ else if (newVisualRow < visualLines.length - 1) {
762
+ newVisualRow++;
763
+ newVisualCol = 0;
764
+ }
765
+ break;
766
+ case 'up':
767
+ if (newVisualRow > 0) {
768
+ if (newPreferredCol === null)
769
+ newPreferredCol = newVisualCol;
770
+ newVisualRow--;
771
+ newVisualCol = clamp(newPreferredCol, 0, cpLen(visualLines[newVisualRow] ?? ''));
772
+ }
773
+ break;
774
+ case 'down':
775
+ if (newVisualRow < visualLines.length - 1) {
776
+ if (newPreferredCol === null)
777
+ newPreferredCol = newVisualCol;
778
+ newVisualRow++;
779
+ newVisualCol = clamp(newPreferredCol, 0, cpLen(visualLines[newVisualRow] ?? ''));
780
+ }
781
+ break;
782
+ case 'home':
783
+ newPreferredCol = null;
784
+ newVisualCol = 0;
785
+ break;
786
+ case 'end':
787
+ newPreferredCol = null;
788
+ newVisualCol = currentVisLineLen;
789
+ break;
790
+ case 'wordLeft': {
791
+ const { cursorRow, cursorCol, lines } = state;
792
+ if (cursorCol === 0 && cursorRow === 0)
793
+ return state;
794
+ let newCursorRow = cursorRow;
795
+ let newCursorCol = cursorCol;
796
+ if (cursorCol === 0) {
797
+ newCursorRow--;
798
+ newCursorCol = cpLen(lines[newCursorRow] ?? '');
799
+ }
800
+ else {
801
+ const lineContent = lines[cursorRow];
802
+ const arr = toCodePoints(lineContent);
803
+ let start = cursorCol;
804
+ let onlySpaces = true;
805
+ for (let i = 0; i < start; i++) {
806
+ if (isWordChar(arr[i])) {
807
+ onlySpaces = false;
808
+ break;
809
+ }
810
+ }
811
+ if (onlySpaces && start > 0) {
812
+ start--;
813
+ }
814
+ else {
815
+ while (start > 0 && !isWordChar(arr[start - 1]))
816
+ start--;
817
+ while (start > 0 && isWordChar(arr[start - 1]))
818
+ start--;
819
+ }
820
+ newCursorCol = start;
821
+ }
822
+ return {
823
+ ...state,
824
+ cursorRow: newCursorRow,
825
+ cursorCol: newCursorCol,
826
+ preferredCol: null,
827
+ };
828
+ }
829
+ case 'wordRight': {
830
+ const { cursorRow, cursorCol, lines } = state;
831
+ if (cursorRow === lines.length - 1 &&
832
+ cursorCol === cpLen(lines[cursorRow] ?? '')) {
833
+ return state;
834
+ }
835
+ let newCursorRow = cursorRow;
836
+ let newCursorCol = cursorCol;
837
+ const lineContent = lines[cursorRow] ?? '';
838
+ const arr = toCodePoints(lineContent);
839
+ if (cursorCol >= arr.length) {
840
+ newCursorRow++;
841
+ newCursorCol = 0;
842
+ }
843
+ else {
844
+ let end = cursorCol;
845
+ while (end < arr.length && !isWordChar(arr[end]))
846
+ end++;
847
+ while (end < arr.length && isWordChar(arr[end]))
848
+ end++;
849
+ newCursorCol = end;
850
+ }
851
+ return {
852
+ ...state,
853
+ cursorRow: newCursorRow,
854
+ cursorCol: newCursorCol,
855
+ preferredCol: null,
856
+ };
857
+ }
858
+ default:
859
+ break;
860
+ }
861
+ if (visualToLogicalMap[newVisualRow]) {
862
+ const [logRow, logStartCol] = visualToLogicalMap[newVisualRow];
863
+ return {
864
+ ...state,
865
+ cursorRow: logRow,
866
+ cursorCol: clamp(logStartCol + newVisualCol, 0, cpLen(state.lines[logRow] ?? '')),
867
+ preferredCol: newPreferredCol,
868
+ };
869
+ }
870
+ return state;
871
+ }
872
+ case 'delete': {
873
+ const { cursorRow, cursorCol, lines } = state;
874
+ const lineContent = currentLine(cursorRow);
875
+ if (cursorCol < currentLineLen(cursorRow)) {
876
+ const nextState = pushUndoLocal(state);
877
+ const newLines = [...nextState.lines];
878
+ newLines[cursorRow] =
879
+ cpSlice(lineContent, 0, cursorCol) +
880
+ cpSlice(lineContent, cursorCol + 1);
881
+ return { ...nextState, lines: newLines, preferredCol: null };
882
+ }
883
+ else if (cursorRow < lines.length - 1) {
884
+ const nextState = pushUndoLocal(state);
885
+ const nextLineContent = currentLine(cursorRow + 1);
886
+ const newLines = [...nextState.lines];
887
+ newLines[cursorRow] = lineContent + nextLineContent;
888
+ newLines.splice(cursorRow + 1, 1);
889
+ return { ...nextState, lines: newLines, preferredCol: null };
890
+ }
891
+ return state;
892
+ }
893
+ case 'delete_word_left': {
894
+ const { cursorRow, cursorCol } = state;
895
+ if (cursorCol === 0 && cursorRow === 0)
896
+ return state;
897
+ if (cursorCol === 0) {
898
+ // Act as a backspace
899
+ const nextState = pushUndoLocal(state);
900
+ const prevLineContent = currentLine(cursorRow - 1);
901
+ const currentLineContentVal = currentLine(cursorRow);
902
+ const newCol = cpLen(prevLineContent);
903
+ const newLines = [...nextState.lines];
904
+ newLines[cursorRow - 1] = prevLineContent + currentLineContentVal;
905
+ newLines.splice(cursorRow, 1);
906
+ return {
907
+ ...nextState,
908
+ lines: newLines,
909
+ cursorRow: cursorRow - 1,
910
+ cursorCol: newCol,
911
+ preferredCol: null,
912
+ };
913
+ }
914
+ const nextState = pushUndoLocal(state);
915
+ const lineContent = currentLine(cursorRow);
916
+ const arr = toCodePoints(lineContent);
917
+ let start = cursorCol;
918
+ let onlySpaces = true;
919
+ for (let i = 0; i < start; i++) {
920
+ if (isWordChar(arr[i])) {
921
+ onlySpaces = false;
922
+ break;
923
+ }
924
+ }
925
+ if (onlySpaces && start > 0) {
926
+ start--;
927
+ }
928
+ else {
929
+ while (start > 0 && !isWordChar(arr[start - 1]))
930
+ start--;
931
+ while (start > 0 && isWordChar(arr[start - 1]))
932
+ start--;
933
+ }
934
+ const newLines = [...nextState.lines];
935
+ newLines[cursorRow] =
936
+ cpSlice(lineContent, 0, start) + cpSlice(lineContent, cursorCol);
937
+ return {
938
+ ...nextState,
939
+ lines: newLines,
940
+ cursorCol: start,
941
+ preferredCol: null,
942
+ };
943
+ }
944
+ case 'delete_word_right': {
945
+ const { cursorRow, cursorCol, lines } = state;
946
+ const lineContent = currentLine(cursorRow);
947
+ const arr = toCodePoints(lineContent);
948
+ if (cursorCol >= arr.length && cursorRow === lines.length - 1)
949
+ return state;
950
+ if (cursorCol >= arr.length) {
951
+ // Act as a delete
952
+ const nextState = pushUndoLocal(state);
953
+ const nextLineContent = currentLine(cursorRow + 1);
954
+ const newLines = [...nextState.lines];
955
+ newLines[cursorRow] = lineContent + nextLineContent;
956
+ newLines.splice(cursorRow + 1, 1);
957
+ return { ...nextState, lines: newLines, preferredCol: null };
958
+ }
959
+ const nextState = pushUndoLocal(state);
960
+ let end = cursorCol;
961
+ while (end < arr.length && !isWordChar(arr[end]))
962
+ end++;
963
+ while (end < arr.length && isWordChar(arr[end]))
964
+ end++;
965
+ const newLines = [...nextState.lines];
966
+ newLines[cursorRow] =
967
+ cpSlice(lineContent, 0, cursorCol) + cpSlice(lineContent, end);
968
+ return { ...nextState, lines: newLines, preferredCol: null };
969
+ }
970
+ case 'kill_line_right': {
971
+ const { cursorRow, cursorCol, lines } = state;
972
+ const lineContent = currentLine(cursorRow);
973
+ if (cursorCol < currentLineLen(cursorRow)) {
974
+ const nextState = pushUndoLocal(state);
975
+ const newLines = [...nextState.lines];
976
+ newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol);
977
+ return { ...nextState, lines: newLines };
978
+ }
979
+ else if (cursorRow < lines.length - 1) {
980
+ // Act as a delete
981
+ const nextState = pushUndoLocal(state);
982
+ const nextLineContent = currentLine(cursorRow + 1);
983
+ const newLines = [...nextState.lines];
984
+ newLines[cursorRow] = lineContent + nextLineContent;
985
+ newLines.splice(cursorRow + 1, 1);
986
+ return { ...nextState, lines: newLines, preferredCol: null };
987
+ }
988
+ return state;
989
+ }
990
+ case 'kill_line_left': {
991
+ const { cursorRow, cursorCol } = state;
992
+ if (cursorCol > 0) {
993
+ const nextState = pushUndoLocal(state);
994
+ const lineContent = currentLine(cursorRow);
995
+ const newLines = [...nextState.lines];
996
+ newLines[cursorRow] = cpSlice(lineContent, cursorCol);
997
+ return {
998
+ ...nextState,
999
+ lines: newLines,
1000
+ cursorCol: 0,
1001
+ preferredCol: null,
1002
+ };
1003
+ }
1004
+ return state;
1005
+ }
1006
+ case 'undo': {
1007
+ const stateToRestore = state.undoStack[state.undoStack.length - 1];
1008
+ if (!stateToRestore)
1009
+ return state;
1010
+ const currentSnapshot = {
1011
+ lines: [...state.lines],
1012
+ cursorRow: state.cursorRow,
1013
+ cursorCol: state.cursorCol,
1014
+ };
1015
+ return {
1016
+ ...state,
1017
+ ...stateToRestore,
1018
+ undoStack: state.undoStack.slice(0, -1),
1019
+ redoStack: [...state.redoStack, currentSnapshot],
1020
+ };
1021
+ }
1022
+ case 'redo': {
1023
+ const stateToRestore = state.redoStack[state.redoStack.length - 1];
1024
+ if (!stateToRestore)
1025
+ return state;
1026
+ const currentSnapshot = {
1027
+ lines: [...state.lines],
1028
+ cursorRow: state.cursorRow,
1029
+ cursorCol: state.cursorCol,
1030
+ };
1031
+ return {
1032
+ ...state,
1033
+ ...stateToRestore,
1034
+ redoStack: state.redoStack.slice(0, -1),
1035
+ undoStack: [...state.undoStack, currentSnapshot],
1036
+ };
1037
+ }
1038
+ case 'replace_range': {
1039
+ const { startRow, startCol, endRow, endCol, text } = action.payload;
1040
+ const nextState = pushUndoLocal(state);
1041
+ return replaceRangeInternal(nextState, startRow, startCol, endRow, endCol, text);
1042
+ }
1043
+ case 'move_to_offset': {
1044
+ const { offset } = action.payload;
1045
+ const [newRow, newCol] = offsetToLogicalPos(state.lines.join('\n'), offset);
1046
+ return {
1047
+ ...state,
1048
+ cursorRow: newRow,
1049
+ cursorCol: newCol,
1050
+ preferredCol: null,
1051
+ };
1052
+ }
1053
+ case 'create_undo_snapshot': {
1054
+ return pushUndoLocal(state);
1055
+ }
1056
+ // Vim-specific operations
1057
+ case 'vim_delete_word_forward':
1058
+ case 'vim_delete_word_backward':
1059
+ case 'vim_delete_word_end':
1060
+ case 'vim_change_word_forward':
1061
+ case 'vim_change_word_backward':
1062
+ case 'vim_change_word_end':
1063
+ case 'vim_delete_line':
1064
+ case 'vim_change_line':
1065
+ case 'vim_delete_to_end_of_line':
1066
+ case 'vim_change_to_end_of_line':
1067
+ case 'vim_change_movement':
1068
+ case 'vim_move_left':
1069
+ case 'vim_move_right':
1070
+ case 'vim_move_up':
1071
+ case 'vim_move_down':
1072
+ case 'vim_move_word_forward':
1073
+ case 'vim_move_word_backward':
1074
+ case 'vim_move_word_end':
1075
+ case 'vim_delete_char':
1076
+ case 'vim_insert_at_cursor':
1077
+ case 'vim_append_at_cursor':
1078
+ case 'vim_open_line_below':
1079
+ case 'vim_open_line_above':
1080
+ case 'vim_append_at_line_end':
1081
+ case 'vim_insert_at_line_start':
1082
+ case 'vim_move_to_line_start':
1083
+ case 'vim_move_to_line_end':
1084
+ case 'vim_move_to_first_nonwhitespace':
1085
+ case 'vim_move_to_first_line':
1086
+ case 'vim_move_to_last_line':
1087
+ case 'vim_move_to_line':
1088
+ case 'vim_escape_insert_mode':
1089
+ return handleVimAction(state, action);
1090
+ default: {
1091
+ const exhaustiveCheck = action;
1092
+ console.error(`Unknown action encountered: ${exhaustiveCheck}`);
1093
+ return state;
1094
+ }
1095
+ }
1096
+ }
1097
+ // --- End of reducer logic ---
1098
+ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewport, stdin, setRawMode, onChange, isValidPath, shellModeActive = false, }) {
1099
+ const initialState = useMemo(() => {
1100
+ const lines = initialText.split('\n');
1101
+ const [initialCursorRow, initialCursorCol] = calculateInitialCursorPosition(lines.length === 0 ? [''] : lines, initialCursorOffset);
1102
+ return {
1103
+ lines: lines.length === 0 ? [''] : lines,
1104
+ cursorRow: initialCursorRow,
1105
+ cursorCol: initialCursorCol,
1106
+ preferredCol: null,
1107
+ undoStack: [],
1108
+ redoStack: [],
1109
+ clipboard: null,
1110
+ selectionAnchor: null,
1111
+ viewportWidth: viewport.width,
1112
+ };
1113
+ }, [initialText, initialCursorOffset, viewport.width]);
1114
+ const [state, dispatch] = useReducer(textBufferReducer, initialState);
1115
+ const { lines, cursorRow, cursorCol, preferredCol, selectionAnchor } = state;
1116
+ const text = useMemo(() => lines.join('\n'), [lines]);
1117
+ const visualLayout = useMemo(() => calculateVisualLayout(lines, [cursorRow, cursorCol], state.viewportWidth), [lines, cursorRow, cursorCol, state.viewportWidth]);
1118
+ const { visualLines, visualCursor } = visualLayout;
1119
+ const [visualScrollRow, setVisualScrollRow] = useState(0);
1120
+ useEffect(() => {
1121
+ if (onChange) {
1122
+ onChange(text);
1123
+ }
1124
+ }, [text, onChange]);
1125
+ useEffect(() => {
1126
+ dispatch({ type: 'set_viewport_width', payload: viewport.width });
1127
+ }, [viewport.width]);
1128
+ // Update visual scroll (vertical)
1129
+ useEffect(() => {
1130
+ const { height } = viewport;
1131
+ let newVisualScrollRow = visualScrollRow;
1132
+ if (visualCursor[0] < visualScrollRow) {
1133
+ newVisualScrollRow = visualCursor[0];
1134
+ }
1135
+ else if (visualCursor[0] >= visualScrollRow + height) {
1136
+ newVisualScrollRow = visualCursor[0] - height + 1;
1137
+ }
1138
+ if (newVisualScrollRow !== visualScrollRow) {
1139
+ setVisualScrollRow(newVisualScrollRow);
1140
+ }
1141
+ }, [visualCursor, visualScrollRow, viewport]);
1142
+ const insert = useCallback((ch, { paste = false } = {}) => {
1143
+ if (/[\n\r]/.test(ch)) {
1144
+ dispatch({ type: 'insert', payload: ch });
1145
+ return;
1146
+ }
1147
+ const minLengthToInferAsDragDrop = 3;
1148
+ if (ch.length >= minLengthToInferAsDragDrop &&
1149
+ !shellModeActive &&
1150
+ paste) {
1151
+ let potentialPath = ch.trim();
1152
+ const quoteMatch = potentialPath.match(/^'(.*)'$/);
1153
+ if (quoteMatch) {
1154
+ potentialPath = quoteMatch[1];
1155
+ }
1156
+ potentialPath = potentialPath.trim();
1157
+ if (isValidPath(unescapePath(potentialPath))) {
1158
+ ch = `@${potentialPath} `;
1159
+ }
1160
+ }
1161
+ let currentText = '';
1162
+ for (const char of toCodePoints(ch)) {
1163
+ if (char.codePointAt(0) === 127) {
1164
+ if (currentText.length > 0) {
1165
+ dispatch({ type: 'insert', payload: currentText });
1166
+ currentText = '';
1167
+ }
1168
+ dispatch({ type: 'backspace' });
1169
+ }
1170
+ else {
1171
+ currentText += char;
1172
+ }
1173
+ }
1174
+ if (currentText.length > 0) {
1175
+ dispatch({ type: 'insert', payload: currentText });
1176
+ }
1177
+ }, [isValidPath, shellModeActive]);
1178
+ const newline = useCallback(() => {
1179
+ dispatch({ type: 'insert', payload: '\n' });
1180
+ }, []);
1181
+ const backspace = useCallback(() => {
1182
+ dispatch({ type: 'backspace' });
1183
+ }, []);
1184
+ const del = useCallback(() => {
1185
+ dispatch({ type: 'delete' });
1186
+ }, []);
1187
+ const move = useCallback((dir) => {
1188
+ dispatch({ type: 'move', payload: { dir } });
1189
+ }, []);
1190
+ const undo = useCallback(() => {
1191
+ dispatch({ type: 'undo' });
1192
+ }, []);
1193
+ const redo = useCallback(() => {
1194
+ dispatch({ type: 'redo' });
1195
+ }, []);
1196
+ const setText = useCallback((newText) => {
1197
+ dispatch({ type: 'set_text', payload: newText });
1198
+ }, []);
1199
+ const deleteWordLeft = useCallback(() => {
1200
+ dispatch({ type: 'delete_word_left' });
1201
+ }, []);
1202
+ const deleteWordRight = useCallback(() => {
1203
+ dispatch({ type: 'delete_word_right' });
1204
+ }, []);
1205
+ const killLineRight = useCallback(() => {
1206
+ dispatch({ type: 'kill_line_right' });
1207
+ }, []);
1208
+ const killLineLeft = useCallback(() => {
1209
+ dispatch({ type: 'kill_line_left' });
1210
+ }, []);
1211
+ // Vim-specific operations
1212
+ const vimDeleteWordForward = useCallback((count) => {
1213
+ dispatch({ type: 'vim_delete_word_forward', payload: { count } });
1214
+ }, []);
1215
+ const vimDeleteWordBackward = useCallback((count) => {
1216
+ dispatch({ type: 'vim_delete_word_backward', payload: { count } });
1217
+ }, []);
1218
+ const vimDeleteWordEnd = useCallback((count) => {
1219
+ dispatch({ type: 'vim_delete_word_end', payload: { count } });
1220
+ }, []);
1221
+ const vimChangeWordForward = useCallback((count) => {
1222
+ dispatch({ type: 'vim_change_word_forward', payload: { count } });
1223
+ }, []);
1224
+ const vimChangeWordBackward = useCallback((count) => {
1225
+ dispatch({ type: 'vim_change_word_backward', payload: { count } });
1226
+ }, []);
1227
+ const vimChangeWordEnd = useCallback((count) => {
1228
+ dispatch({ type: 'vim_change_word_end', payload: { count } });
1229
+ }, []);
1230
+ const vimDeleteLine = useCallback((count) => {
1231
+ dispatch({ type: 'vim_delete_line', payload: { count } });
1232
+ }, []);
1233
+ const vimChangeLine = useCallback((count) => {
1234
+ dispatch({ type: 'vim_change_line', payload: { count } });
1235
+ }, []);
1236
+ const vimDeleteToEndOfLine = useCallback(() => {
1237
+ dispatch({ type: 'vim_delete_to_end_of_line' });
1238
+ }, []);
1239
+ const vimChangeToEndOfLine = useCallback(() => {
1240
+ dispatch({ type: 'vim_change_to_end_of_line' });
1241
+ }, []);
1242
+ const vimChangeMovement = useCallback((movement, count) => {
1243
+ dispatch({ type: 'vim_change_movement', payload: { movement, count } });
1244
+ }, []);
1245
+ // New vim navigation and operation methods
1246
+ const vimMoveLeft = useCallback((count) => {
1247
+ dispatch({ type: 'vim_move_left', payload: { count } });
1248
+ }, []);
1249
+ const vimMoveRight = useCallback((count) => {
1250
+ dispatch({ type: 'vim_move_right', payload: { count } });
1251
+ }, []);
1252
+ const vimMoveUp = useCallback((count) => {
1253
+ dispatch({ type: 'vim_move_up', payload: { count } });
1254
+ }, []);
1255
+ const vimMoveDown = useCallback((count) => {
1256
+ dispatch({ type: 'vim_move_down', payload: { count } });
1257
+ }, []);
1258
+ const vimMoveWordForward = useCallback((count) => {
1259
+ dispatch({ type: 'vim_move_word_forward', payload: { count } });
1260
+ }, []);
1261
+ const vimMoveWordBackward = useCallback((count) => {
1262
+ dispatch({ type: 'vim_move_word_backward', payload: { count } });
1263
+ }, []);
1264
+ const vimMoveWordEnd = useCallback((count) => {
1265
+ dispatch({ type: 'vim_move_word_end', payload: { count } });
1266
+ }, []);
1267
+ const vimDeleteChar = useCallback((count) => {
1268
+ dispatch({ type: 'vim_delete_char', payload: { count } });
1269
+ }, []);
1270
+ const vimInsertAtCursor = useCallback(() => {
1271
+ dispatch({ type: 'vim_insert_at_cursor' });
1272
+ }, []);
1273
+ const vimAppendAtCursor = useCallback(() => {
1274
+ dispatch({ type: 'vim_append_at_cursor' });
1275
+ }, []);
1276
+ const vimOpenLineBelow = useCallback(() => {
1277
+ dispatch({ type: 'vim_open_line_below' });
1278
+ }, []);
1279
+ const vimOpenLineAbove = useCallback(() => {
1280
+ dispatch({ type: 'vim_open_line_above' });
1281
+ }, []);
1282
+ const vimAppendAtLineEnd = useCallback(() => {
1283
+ dispatch({ type: 'vim_append_at_line_end' });
1284
+ }, []);
1285
+ const vimInsertAtLineStart = useCallback(() => {
1286
+ dispatch({ type: 'vim_insert_at_line_start' });
1287
+ }, []);
1288
+ const vimMoveToLineStart = useCallback(() => {
1289
+ dispatch({ type: 'vim_move_to_line_start' });
1290
+ }, []);
1291
+ const vimMoveToLineEnd = useCallback(() => {
1292
+ dispatch({ type: 'vim_move_to_line_end' });
1293
+ }, []);
1294
+ const vimMoveToFirstNonWhitespace = useCallback(() => {
1295
+ dispatch({ type: 'vim_move_to_first_nonwhitespace' });
1296
+ }, []);
1297
+ const vimMoveToFirstLine = useCallback(() => {
1298
+ dispatch({ type: 'vim_move_to_first_line' });
1299
+ }, []);
1300
+ const vimMoveToLastLine = useCallback(() => {
1301
+ dispatch({ type: 'vim_move_to_last_line' });
1302
+ }, []);
1303
+ const vimMoveToLine = useCallback((lineNumber) => {
1304
+ dispatch({ type: 'vim_move_to_line', payload: { lineNumber } });
1305
+ }, []);
1306
+ const vimEscapeInsertMode = useCallback(() => {
1307
+ dispatch({ type: 'vim_escape_insert_mode' });
1308
+ }, []);
1309
+ const openInExternalEditor = useCallback(async (opts = {}) => {
1310
+ const editor = opts.editor ??
1311
+ process.env['VISUAL'] ??
1312
+ process.env['EDITOR'] ??
1313
+ (process.platform === 'win32' ? 'notepad' : 'vi');
1314
+ const tmpDir = fs.mkdtempSync(pathMod.join(os.tmpdir(), 'gemini-edit-'));
1315
+ const filePath = pathMod.join(tmpDir, 'buffer.txt');
1316
+ fs.writeFileSync(filePath, text, 'utf8');
1317
+ dispatch({ type: 'create_undo_snapshot' });
1318
+ const wasRaw = stdin?.isRaw ?? false;
1319
+ try {
1320
+ setRawMode?.(false);
1321
+ const { status, error } = spawnSync(editor, [filePath], {
1322
+ stdio: 'inherit',
1323
+ });
1324
+ if (error)
1325
+ throw error;
1326
+ if (typeof status === 'number' && status !== 0)
1327
+ throw new Error(`External editor exited with status ${status}`);
1328
+ let newText = fs.readFileSync(filePath, 'utf8');
1329
+ newText = newText.replace(/\r\n?/g, '\n');
1330
+ dispatch({ type: 'set_text', payload: newText, pushToUndo: false });
1331
+ }
1332
+ catch (err) {
1333
+ console.error('[useTextBuffer] external editor error', err);
1334
+ }
1335
+ finally {
1336
+ if (wasRaw)
1337
+ setRawMode?.(true);
1338
+ try {
1339
+ fs.unlinkSync(filePath);
1340
+ }
1341
+ catch {
1342
+ /* ignore */
1343
+ }
1344
+ try {
1345
+ fs.rmdirSync(tmpDir);
1346
+ }
1347
+ catch {
1348
+ /* ignore */
1349
+ }
1350
+ }
1351
+ }, [text, stdin, setRawMode]);
1352
+ const handleInput = useCallback((key) => {
1353
+ const { sequence: input } = key;
1354
+ if (key.paste) {
1355
+ // Do not do any other processing on pastes so ensure we handle them
1356
+ // before all other cases.
1357
+ insert(input, { paste: key.paste });
1358
+ return;
1359
+ }
1360
+ if (key.name === 'return' ||
1361
+ input === '\r' ||
1362
+ input === '\n' ||
1363
+ input === '\\\r' // VSCode terminal represents shift + enter this way
1364
+ )
1365
+ newline();
1366
+ else if (key.name === 'left' && !key.meta && !key.ctrl)
1367
+ move('left');
1368
+ else if (key.ctrl && key.name === 'b')
1369
+ move('left');
1370
+ else if (key.name === 'right' && !key.meta && !key.ctrl)
1371
+ move('right');
1372
+ else if (key.ctrl && key.name === 'f')
1373
+ move('right');
1374
+ else if (key.name === 'up')
1375
+ move('up');
1376
+ else if (key.name === 'down')
1377
+ move('down');
1378
+ else if ((key.ctrl || key.meta) && key.name === 'left')
1379
+ move('wordLeft');
1380
+ else if (key.meta && key.name === 'b')
1381
+ move('wordLeft');
1382
+ else if ((key.ctrl || key.meta) && key.name === 'right')
1383
+ move('wordRight');
1384
+ else if (key.meta && key.name === 'f')
1385
+ move('wordRight');
1386
+ else if (key.name === 'home')
1387
+ move('home');
1388
+ else if (key.ctrl && key.name === 'a')
1389
+ move('home');
1390
+ else if (key.name === 'end')
1391
+ move('end');
1392
+ else if (key.ctrl && key.name === 'e')
1393
+ move('end');
1394
+ else if (key.ctrl && key.name === 'w')
1395
+ deleteWordLeft();
1396
+ else if ((key.meta || key.ctrl) &&
1397
+ (key.name === 'backspace' || input === '\x7f'))
1398
+ deleteWordLeft();
1399
+ else if ((key.meta || key.ctrl) && key.name === 'delete')
1400
+ deleteWordRight();
1401
+ else if (key.name === 'backspace' ||
1402
+ input === '\x7f' ||
1403
+ (key.ctrl && key.name === 'h'))
1404
+ backspace();
1405
+ else if (key.name === 'delete' || (key.ctrl && key.name === 'd'))
1406
+ del();
1407
+ else if (input && !key.ctrl && !key.meta) {
1408
+ insert(input, { paste: key.paste });
1409
+ }
1410
+ }, [newline, move, deleteWordLeft, deleteWordRight, backspace, del, insert]);
1411
+ const renderedVisualLines = useMemo(() => visualLines.slice(visualScrollRow, visualScrollRow + viewport.height), [visualLines, visualScrollRow, viewport.height]);
1412
+ const replaceRange = useCallback((startRow, startCol, endRow, endCol, text) => {
1413
+ dispatch({
1414
+ type: 'replace_range',
1415
+ payload: { startRow, startCol, endRow, endCol, text },
1416
+ });
1417
+ }, []);
1418
+ const replaceRangeByOffset = useCallback((startOffset, endOffset, replacementText) => {
1419
+ const [startRow, startCol] = offsetToLogicalPos(text, startOffset);
1420
+ const [endRow, endCol] = offsetToLogicalPos(text, endOffset);
1421
+ replaceRange(startRow, startCol, endRow, endCol, replacementText);
1422
+ }, [text, replaceRange]);
1423
+ const moveToOffset = useCallback((offset) => {
1424
+ dispatch({ type: 'move_to_offset', payload: { offset } });
1425
+ }, []);
1426
+ const returnValue = {
1427
+ lines,
1428
+ text,
1429
+ cursor: [cursorRow, cursorCol],
1430
+ preferredCol,
1431
+ selectionAnchor,
1432
+ allVisualLines: visualLines,
1433
+ viewportVisualLines: renderedVisualLines,
1434
+ visualCursor,
1435
+ visualScrollRow,
1436
+ setText,
1437
+ insert,
1438
+ newline,
1439
+ backspace,
1440
+ del,
1441
+ move,
1442
+ undo,
1443
+ redo,
1444
+ replaceRange,
1445
+ replaceRangeByOffset,
1446
+ moveToOffset,
1447
+ deleteWordLeft,
1448
+ deleteWordRight,
1449
+ killLineRight,
1450
+ killLineLeft,
1451
+ handleInput,
1452
+ openInExternalEditor,
1453
+ // Vim-specific operations
1454
+ vimDeleteWordForward,
1455
+ vimDeleteWordBackward,
1456
+ vimDeleteWordEnd,
1457
+ vimChangeWordForward,
1458
+ vimChangeWordBackward,
1459
+ vimChangeWordEnd,
1460
+ vimDeleteLine,
1461
+ vimChangeLine,
1462
+ vimDeleteToEndOfLine,
1463
+ vimChangeToEndOfLine,
1464
+ vimChangeMovement,
1465
+ vimMoveLeft,
1466
+ vimMoveRight,
1467
+ vimMoveUp,
1468
+ vimMoveDown,
1469
+ vimMoveWordForward,
1470
+ vimMoveWordBackward,
1471
+ vimMoveWordEnd,
1472
+ vimDeleteChar,
1473
+ vimInsertAtCursor,
1474
+ vimAppendAtCursor,
1475
+ vimOpenLineBelow,
1476
+ vimOpenLineAbove,
1477
+ vimAppendAtLineEnd,
1478
+ vimInsertAtLineStart,
1479
+ vimMoveToLineStart,
1480
+ vimMoveToLineEnd,
1481
+ vimMoveToFirstNonWhitespace,
1482
+ vimMoveToFirstLine,
1483
+ vimMoveToLastLine,
1484
+ vimMoveToLine,
1485
+ vimEscapeInsertMode,
1486
+ };
1487
+ return returnValue;
1488
+ }
1489
+ //# sourceMappingURL=text-buffer.js.map