fss-link 1.0.49 → 1.0.51

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 (419) hide show
  1. package/dist/index.js +0 -0
  2. package/dist/package.json +2 -2
  3. package/dist/src/config/auth.js +8 -5
  4. package/dist/src/config/auth.js.map +1 -1
  5. package/dist/src/config/database.d.ts +103 -11
  6. package/dist/src/config/database.js +301 -59
  7. package/dist/src/config/database.js.map +1 -1
  8. package/dist/src/config/databaseBackup.d.ts +114 -0
  9. package/dist/src/config/databaseBackup.js +334 -0
  10. package/dist/src/config/databaseBackup.js.map +1 -0
  11. package/dist/src/config/databaseMigrations.d.ts +63 -0
  12. package/dist/src/config/databaseMigrations.js +379 -0
  13. package/dist/src/config/databaseMigrations.js.map +1 -0
  14. package/dist/src/config/databasePool.d.ts +70 -0
  15. package/dist/src/config/databasePool.js +193 -0
  16. package/dist/src/config/databasePool.js.map +1 -0
  17. package/dist/src/config/queryOptimizer.d.ts +127 -0
  18. package/dist/src/config/queryOptimizer.js +309 -0
  19. package/dist/src/config/queryOptimizer.js.map +1 -0
  20. package/dist/src/utils/sandbox.js +2 -8
  21. package/dist/src/utils/sandbox.js.map +1 -1
  22. package/dist/src/validateNonInterActiveAuth.js +3 -7
  23. package/dist/src/validateNonInterActiveAuth.js.map +1 -1
  24. package/dist/tsconfig.tsbuildinfo +1 -1
  25. package/package.json +2 -2
  26. package/dist/commands/mcp/add.test.ts +0 -122
  27. package/dist/commands/mcp/add.ts +0 -222
  28. package/dist/commands/mcp/list.test.ts +0 -154
  29. package/dist/commands/mcp/list.ts +0 -139
  30. package/dist/commands/mcp/remove.test.ts +0 -69
  31. package/dist/commands/mcp/remove.ts +0 -60
  32. package/dist/commands/mcp.test.ts +0 -55
  33. package/dist/commands/mcp.ts +0 -27
  34. package/dist/config/apiValidation.test.ts +0 -118
  35. package/dist/config/auth.test.ts +0 -79
  36. package/dist/config/auth.ts +0 -100
  37. package/dist/config/config.integration.test.ts +0 -407
  38. package/dist/config/config.test.ts +0 -1952
  39. package/dist/config/config.ts +0 -690
  40. package/dist/config/database.test.ts +0 -96
  41. package/dist/config/database.ts +0 -824
  42. package/dist/config/extension.test.ts +0 -236
  43. package/dist/config/extension.ts +0 -180
  44. package/dist/config/keyBindings.test.ts +0 -62
  45. package/dist/config/keyBindings.ts +0 -184
  46. package/dist/config/modelManager.ts +0 -326
  47. package/dist/config/providerManager.ts +0 -244
  48. package/dist/config/providerPersistence.test.ts +0 -377
  49. package/dist/config/providerPersistence.ts +0 -105
  50. package/dist/config/sandboxConfig.ts +0 -107
  51. package/dist/config/settings.test.ts +0 -1424
  52. package/dist/config/settings.ts +0 -517
  53. package/dist/config/settingsSchema.test.ts +0 -252
  54. package/dist/config/settingsSchema.ts +0 -728
  55. package/dist/config/trustedFolders.test.ts +0 -208
  56. package/dist/config/trustedFolders.ts +0 -167
  57. package/dist/gemini.test.tsx +0 -252
  58. package/dist/gemini.tsx +0 -357
  59. package/dist/generated/git-commit.ts +0 -10
  60. package/dist/index.ts +0 -21
  61. package/dist/nonInteractiveCli.test.ts +0 -276
  62. package/dist/nonInteractiveCli.ts +0 -143
  63. package/dist/patches/is-in-ci.ts +0 -17
  64. package/dist/services/BuiltinCommandLoader.test.ts +0 -127
  65. package/dist/services/BuiltinCommandLoader.ts +0 -95
  66. package/dist/services/CommandService.test.ts +0 -352
  67. package/dist/services/CommandService.ts +0 -103
  68. package/dist/services/FileCommandLoader.test.ts +0 -1002
  69. package/dist/services/FileCommandLoader.ts +0 -289
  70. package/dist/services/McpPromptLoader.ts +0 -231
  71. package/dist/services/SearchEngineConfigProvider.ts +0 -100
  72. package/dist/services/prompt-processors/argumentProcessor.test.ts +0 -41
  73. package/dist/services/prompt-processors/argumentProcessor.ts +0 -23
  74. package/dist/services/prompt-processors/shellProcessor.test.ts +0 -709
  75. package/dist/services/prompt-processors/shellProcessor.ts +0 -248
  76. package/dist/services/prompt-processors/types.ts +0 -44
  77. package/dist/services/types.ts +0 -24
  78. package/dist/src/config/apiValidation.test.d.ts +0 -6
  79. package/dist/src/config/apiValidation.test.js +0 -99
  80. package/dist/src/config/apiValidation.test.js.map +0 -1
  81. package/dist/src/config/database.test.d.ts +0 -6
  82. package/dist/src/config/database.test.js +0 -80
  83. package/dist/src/config/database.test.js.map +0 -1
  84. package/dist/src/config/providerManager.d.ts +0 -74
  85. package/dist/src/config/providerManager.js +0 -203
  86. package/dist/src/config/providerManager.js.map +0 -1
  87. package/dist/src/config/providerPersistence.test.d.ts +0 -6
  88. package/dist/src/config/providerPersistence.test.js +0 -283
  89. package/dist/src/config/providerPersistence.test.js.map +0 -1
  90. package/dist/src/ui/components/GeminiKeyDialog.d.ts +0 -11
  91. package/dist/src/ui/components/GeminiKeyDialog.js +0 -156
  92. package/dist/src/ui/components/GeminiKeyDialog.js.map +0 -1
  93. package/dist/src/ui/components/OpenAIEndpointDialog.d.ts +0 -19
  94. package/dist/src/ui/components/OpenAIEndpointDialog.js +0 -163
  95. package/dist/src/ui/components/OpenAIEndpointDialog.js.map +0 -1
  96. package/dist/test-setup.ts +0 -12
  97. package/dist/test-utils/customMatchers.ts +0 -65
  98. package/dist/test-utils/mockCommandContext.test.ts +0 -62
  99. package/dist/test-utils/mockCommandContext.ts +0 -105
  100. package/dist/test-utils/render.tsx +0 -18
  101. package/dist/ui/App.test.tsx +0 -2181
  102. package/dist/ui/App.tsx +0 -1344
  103. package/dist/ui/IdeIntegrationNudge.tsx +0 -98
  104. package/dist/ui/__snapshots__/App.test.tsx.snap +0 -124
  105. package/dist/ui/colors.ts +0 -56
  106. package/dist/ui/commands/aboutCommand.test.ts +0 -153
  107. package/dist/ui/commands/aboutCommand.ts +0 -49
  108. package/dist/ui/commands/authCommand.test.ts +0 -36
  109. package/dist/ui/commands/authCommand.ts +0 -17
  110. package/dist/ui/commands/bugCommand.test.ts +0 -114
  111. package/dist/ui/commands/bugCommand.ts +0 -92
  112. package/dist/ui/commands/chatCommand.test.ts +0 -414
  113. package/dist/ui/commands/chatCommand.ts +0 -280
  114. package/dist/ui/commands/clearCommand.test.ts +0 -100
  115. package/dist/ui/commands/clearCommand.ts +0 -29
  116. package/dist/ui/commands/compressCommand.test.ts +0 -129
  117. package/dist/ui/commands/compressCommand.ts +0 -78
  118. package/dist/ui/commands/contextCommand.ts +0 -132
  119. package/dist/ui/commands/copyCommand.test.ts +0 -296
  120. package/dist/ui/commands/copyCommand.ts +0 -67
  121. package/dist/ui/commands/corgiCommand.test.ts +0 -34
  122. package/dist/ui/commands/corgiCommand.ts +0 -16
  123. package/dist/ui/commands/directoryCommand.test.tsx +0 -185
  124. package/dist/ui/commands/directoryCommand.tsx +0 -179
  125. package/dist/ui/commands/docsCommand.test.ts +0 -99
  126. package/dist/ui/commands/docsCommand.ts +0 -42
  127. package/dist/ui/commands/editorCommand.test.ts +0 -30
  128. package/dist/ui/commands/editorCommand.ts +0 -21
  129. package/dist/ui/commands/extensionsCommand.test.ts +0 -67
  130. package/dist/ui/commands/extensionsCommand.ts +0 -46
  131. package/dist/ui/commands/helpCommand.test.ts +0 -52
  132. package/dist/ui/commands/helpCommand.ts +0 -23
  133. package/dist/ui/commands/ideCommand.test.ts +0 -255
  134. package/dist/ui/commands/ideCommand.ts +0 -283
  135. package/dist/ui/commands/initCommand.test.ts +0 -127
  136. package/dist/ui/commands/initCommand.ts +0 -117
  137. package/dist/ui/commands/mcpCommand.test.ts +0 -1057
  138. package/dist/ui/commands/mcpCommand.ts +0 -531
  139. package/dist/ui/commands/memoryCommand.test.ts +0 -344
  140. package/dist/ui/commands/memoryCommand.ts +0 -305
  141. package/dist/ui/commands/privacyCommand.test.ts +0 -38
  142. package/dist/ui/commands/privacyCommand.ts +0 -17
  143. package/dist/ui/commands/quitCommand.test.ts +0 -55
  144. package/dist/ui/commands/quitCommand.ts +0 -36
  145. package/dist/ui/commands/restoreCommand.test.ts +0 -250
  146. package/dist/ui/commands/restoreCommand.ts +0 -157
  147. package/dist/ui/commands/searchEngineSetupCommand.ts +0 -18
  148. package/dist/ui/commands/settingsCommand.test.ts +0 -36
  149. package/dist/ui/commands/settingsCommand.ts +0 -17
  150. package/dist/ui/commands/setupGithubCommand.test.ts +0 -238
  151. package/dist/ui/commands/setupGithubCommand.ts +0 -212
  152. package/dist/ui/commands/speakCommand.ts +0 -175
  153. package/dist/ui/commands/statsCommand.test.ts +0 -78
  154. package/dist/ui/commands/statsCommand.ts +0 -70
  155. package/dist/ui/commands/terminalSetupCommand.test.ts +0 -85
  156. package/dist/ui/commands/terminalSetupCommand.ts +0 -45
  157. package/dist/ui/commands/themeCommand.test.ts +0 -38
  158. package/dist/ui/commands/themeCommand.ts +0 -17
  159. package/dist/ui/commands/toolsCommand.test.ts +0 -105
  160. package/dist/ui/commands/toolsCommand.ts +0 -71
  161. package/dist/ui/commands/ttsCommand.ts +0 -143
  162. package/dist/ui/commands/types.ts +0 -204
  163. package/dist/ui/commands/vimCommand.ts +0 -25
  164. package/dist/ui/commands/voiceCommand.ts +0 -125
  165. package/dist/ui/components/AboutBox.tsx +0 -133
  166. package/dist/ui/components/AsciiArt.ts +0 -54
  167. package/dist/ui/components/AuthDialog.test.tsx +0 -334
  168. package/dist/ui/components/AuthDialog.tsx +0 -289
  169. package/dist/ui/components/AuthInProgress.tsx +0 -62
  170. package/dist/ui/components/AutoAcceptIndicator.tsx +0 -47
  171. package/dist/ui/components/ConsoleSummaryDisplay.tsx +0 -35
  172. package/dist/ui/components/ContextSummaryDisplay.test.tsx +0 -85
  173. package/dist/ui/components/ContextSummaryDisplay.tsx +0 -120
  174. package/dist/ui/components/ContextUsageDisplay.tsx +0 -77
  175. package/dist/ui/components/DebugProfiler.tsx +0 -36
  176. package/dist/ui/components/DetailedMessagesDisplay.tsx +0 -82
  177. package/dist/ui/components/EditorSettingsDialog.tsx +0 -172
  178. package/dist/ui/components/FolderTrustDialog.test.tsx +0 -36
  179. package/dist/ui/components/FolderTrustDialog.tsx +0 -74
  180. package/dist/ui/components/Footer.test.tsx +0 -159
  181. package/dist/ui/components/Footer.tsx +0 -158
  182. package/dist/ui/components/GeminiKeyDialog.tsx +0 -252
  183. package/dist/ui/components/GeminiRespondingSpinner.tsx +0 -34
  184. package/dist/ui/components/Header.test.tsx +0 -44
  185. package/dist/ui/components/Header.tsx +0 -70
  186. package/dist/ui/components/Help.tsx +0 -174
  187. package/dist/ui/components/HistoryItemDisplay.test.tsx +0 -125
  188. package/dist/ui/components/HistoryItemDisplay.tsx +0 -98
  189. package/dist/ui/components/InputPrompt.test.tsx +0 -1467
  190. package/dist/ui/components/InputPrompt.tsx +0 -641
  191. package/dist/ui/components/LMStudioModelPrompt.tsx +0 -215
  192. package/dist/ui/components/LoadingIndicator.test.tsx +0 -296
  193. package/dist/ui/components/LoadingIndicator.tsx +0 -82
  194. package/dist/ui/components/MemoryUsageDisplay.tsx +0 -36
  195. package/dist/ui/components/ModelStatsDisplay.test.tsx +0 -252
  196. package/dist/ui/components/ModelStatsDisplay.tsx +0 -197
  197. package/dist/ui/components/OllamaModelPrompt.tsx +0 -206
  198. package/dist/ui/components/OpenAIEndpointDialog.tsx +0 -261
  199. package/dist/ui/components/OpenAIKeyPrompt.test.tsx +0 -64
  200. package/dist/ui/components/OpenAIKeyPrompt.tsx +0 -197
  201. package/dist/ui/components/PrepareLabel.tsx +0 -48
  202. package/dist/ui/components/SearchEngineConfigDialog.tsx +0 -280
  203. package/dist/ui/components/SessionSummaryDisplay.test.tsx +0 -75
  204. package/dist/ui/components/SessionSummaryDisplay.tsx +0 -18
  205. package/dist/ui/components/SettingsDialog.test.tsx +0 -865
  206. package/dist/ui/components/SettingsDialog.tsx +0 -753
  207. package/dist/ui/components/ShellConfirmationDialog.test.tsx +0 -53
  208. package/dist/ui/components/ShellConfirmationDialog.tsx +0 -103
  209. package/dist/ui/components/ShellModeIndicator.tsx +0 -18
  210. package/dist/ui/components/ShowMoreLines.tsx +0 -40
  211. package/dist/ui/components/StatsDisplay.test.tsx +0 -401
  212. package/dist/ui/components/StatsDisplay.tsx +0 -273
  213. package/dist/ui/components/SuggestionsDisplay.tsx +0 -102
  214. package/dist/ui/components/ThemeDialog.tsx +0 -310
  215. package/dist/ui/components/Tips.tsx +0 -45
  216. package/dist/ui/components/TodoDisplay.test.tsx +0 -97
  217. package/dist/ui/components/TodoDisplay.tsx +0 -72
  218. package/dist/ui/components/ToolStatsDisplay.test.tsx +0 -180
  219. package/dist/ui/components/ToolStatsDisplay.tsx +0 -208
  220. package/dist/ui/components/UpdateNotification.tsx +0 -23
  221. package/dist/ui/components/WelcomeBackDialog.tsx +0 -290
  222. package/dist/ui/components/__snapshots__/IDEContextDetailDisplay.test.tsx.snap +0 -24
  223. package/dist/ui/components/__snapshots__/ModelStatsDisplay.test.tsx.snap +0 -121
  224. package/dist/ui/components/__snapshots__/SessionSummaryDisplay.test.tsx.snap +0 -30
  225. package/dist/ui/components/__snapshots__/ShellConfirmationDialog.test.tsx.snap +0 -21
  226. package/dist/ui/components/__snapshots__/StatsDisplay.test.tsx.snap +0 -264
  227. package/dist/ui/components/__snapshots__/ToolStatsDisplay.test.tsx.snap +0 -91
  228. package/dist/ui/components/messages/CompressionMessage.tsx +0 -49
  229. package/dist/ui/components/messages/DiffRenderer.test.tsx +0 -365
  230. package/dist/ui/components/messages/DiffRenderer.tsx +0 -358
  231. package/dist/ui/components/messages/ErrorMessage.tsx +0 -31
  232. package/dist/ui/components/messages/GeminiMessage.tsx +0 -43
  233. package/dist/ui/components/messages/GeminiMessageContent.tsx +0 -43
  234. package/dist/ui/components/messages/InfoMessage.tsx +0 -32
  235. package/dist/ui/components/messages/ToolConfirmationMessage.test.tsx +0 -58
  236. package/dist/ui/components/messages/ToolConfirmationMessage.tsx +0 -297
  237. package/dist/ui/components/messages/ToolGroupMessage.tsx +0 -126
  238. package/dist/ui/components/messages/ToolMessage.test.tsx +0 -183
  239. package/dist/ui/components/messages/ToolMessage.tsx +0 -296
  240. package/dist/ui/components/messages/UserMessage.tsx +0 -43
  241. package/dist/ui/components/messages/UserShellMessage.tsx +0 -25
  242. package/dist/ui/components/shared/MaxSizedBox.test.tsx +0 -425
  243. package/dist/ui/components/shared/MaxSizedBox.tsx +0 -624
  244. package/dist/ui/components/shared/RadioButtonSelect.test.tsx +0 -181
  245. package/dist/ui/components/shared/RadioButtonSelect.tsx +0 -234
  246. package/dist/ui/components/shared/__snapshots__/RadioButtonSelect.test.tsx.snap +0 -47
  247. package/dist/ui/components/shared/text-buffer.test.ts +0 -1728
  248. package/dist/ui/components/shared/text-buffer.ts +0 -2227
  249. package/dist/ui/components/shared/vim-buffer-actions.test.ts +0 -1119
  250. package/dist/ui/components/shared/vim-buffer-actions.ts +0 -814
  251. package/dist/ui/constants.ts +0 -17
  252. package/dist/ui/contexts/KeypressContext.test.tsx +0 -391
  253. package/dist/ui/contexts/KeypressContext.tsx +0 -440
  254. package/dist/ui/contexts/OverflowContext.tsx +0 -87
  255. package/dist/ui/contexts/SessionContext.test.tsx +0 -132
  256. package/dist/ui/contexts/SessionContext.tsx +0 -143
  257. package/dist/ui/contexts/SettingsContext.tsx +0 -20
  258. package/dist/ui/contexts/StreamingContext.tsx +0 -22
  259. package/dist/ui/contexts/VimModeContext.tsx +0 -79
  260. package/dist/ui/editors/editorSettingsManager.ts +0 -66
  261. package/dist/ui/hooks/atCommandProcessor.test.ts +0 -1102
  262. package/dist/ui/hooks/atCommandProcessor.ts +0 -485
  263. package/dist/ui/hooks/shellCommandProcessor.test.ts +0 -481
  264. package/dist/ui/hooks/shellCommandProcessor.ts +0 -314
  265. package/dist/ui/hooks/slashCommandProcessor.test.ts +0 -1044
  266. package/dist/ui/hooks/slashCommandProcessor.ts +0 -595
  267. package/dist/ui/hooks/useAtCompletion.test.ts +0 -497
  268. package/dist/ui/hooks/useAtCompletion.ts +0 -244
  269. package/dist/ui/hooks/useAuthCommand.ts +0 -129
  270. package/dist/ui/hooks/useAutoAcceptIndicator.test.ts +0 -300
  271. package/dist/ui/hooks/useAutoAcceptIndicator.ts +0 -52
  272. package/dist/ui/hooks/useBracketedPaste.ts +0 -37
  273. package/dist/ui/hooks/useCommandCompletion.test.ts +0 -518
  274. package/dist/ui/hooks/useCommandCompletion.tsx +0 -238
  275. package/dist/ui/hooks/useCompletion.ts +0 -128
  276. package/dist/ui/hooks/useConsoleMessages.test.ts +0 -147
  277. package/dist/ui/hooks/useConsoleMessages.ts +0 -110
  278. package/dist/ui/hooks/useEditorSettings.test.ts +0 -283
  279. package/dist/ui/hooks/useEditorSettings.ts +0 -75
  280. package/dist/ui/hooks/useFocus.test.ts +0 -119
  281. package/dist/ui/hooks/useFocus.ts +0 -48
  282. package/dist/ui/hooks/useFolderTrust.test.ts +0 -159
  283. package/dist/ui/hooks/useFolderTrust.ts +0 -72
  284. package/dist/ui/hooks/useGeminiStream.test.tsx +0 -1998
  285. package/dist/ui/hooks/useGeminiStream.ts +0 -1017
  286. package/dist/ui/hooks/useGitBranchName.test.ts +0 -280
  287. package/dist/ui/hooks/useGitBranchName.ts +0 -79
  288. package/dist/ui/hooks/useHistoryManager.test.ts +0 -202
  289. package/dist/ui/hooks/useHistoryManager.ts +0 -111
  290. package/dist/ui/hooks/useInputHistory.test.ts +0 -261
  291. package/dist/ui/hooks/useInputHistory.ts +0 -111
  292. package/dist/ui/hooks/useKeypress.test.ts +0 -280
  293. package/dist/ui/hooks/useKeypress.ts +0 -39
  294. package/dist/ui/hooks/useKittyKeyboardProtocol.ts +0 -31
  295. package/dist/ui/hooks/useLoadingIndicator.test.ts +0 -139
  296. package/dist/ui/hooks/useLoadingIndicator.ts +0 -57
  297. package/dist/ui/hooks/useLogger.ts +0 -32
  298. package/dist/ui/hooks/useMessageQueue.test.ts +0 -226
  299. package/dist/ui/hooks/useMessageQueue.ts +0 -69
  300. package/dist/ui/hooks/usePhraseCycler.test.ts +0 -145
  301. package/dist/ui/hooks/usePhraseCycler.ts +0 -198
  302. package/dist/ui/hooks/usePrivacySettings.test.ts +0 -242
  303. package/dist/ui/hooks/usePrivacySettings.ts +0 -150
  304. package/dist/ui/hooks/useReactToolScheduler.ts +0 -309
  305. package/dist/ui/hooks/useRefreshMemoryCommand.ts +0 -7
  306. package/dist/ui/hooks/useReverseSearchCompletion.test.tsx +0 -260
  307. package/dist/ui/hooks/useReverseSearchCompletion.tsx +0 -95
  308. package/dist/ui/hooks/useSettingsCommand.ts +0 -25
  309. package/dist/ui/hooks/useShellHistory.test.ts +0 -219
  310. package/dist/ui/hooks/useShellHistory.ts +0 -133
  311. package/dist/ui/hooks/useShowMemoryCommand.ts +0 -75
  312. package/dist/ui/hooks/useSlashCompletion.test.ts +0 -434
  313. package/dist/ui/hooks/useSlashCompletion.ts +0 -187
  314. package/dist/ui/hooks/useStateAndRef.ts +0 -36
  315. package/dist/ui/hooks/useTerminalSize.ts +0 -32
  316. package/dist/ui/hooks/useThemeCommand.ts +0 -110
  317. package/dist/ui/hooks/useTimer.test.ts +0 -120
  318. package/dist/ui/hooks/useTimer.ts +0 -65
  319. package/dist/ui/hooks/useToolScheduler.test.ts +0 -1123
  320. package/dist/ui/hooks/useWelcomeBack.ts +0 -253
  321. package/dist/ui/hooks/vim.test.ts +0 -1691
  322. package/dist/ui/hooks/vim.ts +0 -784
  323. package/dist/ui/keyMatchers.test.ts +0 -337
  324. package/dist/ui/keyMatchers.ts +0 -105
  325. package/dist/ui/privacy/CloudFreePrivacyNotice.tsx +0 -117
  326. package/dist/ui/privacy/CloudPaidPrivacyNotice.tsx +0 -59
  327. package/dist/ui/privacy/GeminiPrivacyNotice.tsx +0 -62
  328. package/dist/ui/privacy/PrivacyNotice.tsx +0 -42
  329. package/dist/ui/semantic-colors.ts +0 -26
  330. package/dist/ui/themes/ansi-light.ts +0 -150
  331. package/dist/ui/themes/ansi.ts +0 -159
  332. package/dist/ui/themes/atom-one-dark.ts +0 -147
  333. package/dist/ui/themes/ayu-light.ts +0 -139
  334. package/dist/ui/themes/ayu.ts +0 -113
  335. package/dist/ui/themes/color-utils.test.ts +0 -221
  336. package/dist/ui/themes/color-utils.ts +0 -231
  337. package/dist/ui/themes/default-light.ts +0 -108
  338. package/dist/ui/themes/default.ts +0 -151
  339. package/dist/ui/themes/dracula.ts +0 -124
  340. package/dist/ui/themes/fss-code-dark.ts +0 -156
  341. package/dist/ui/themes/fss-dark.ts +0 -113
  342. package/dist/ui/themes/fss-light.ts +0 -139
  343. package/dist/ui/themes/github-dark.ts +0 -147
  344. package/dist/ui/themes/github-light.ts +0 -149
  345. package/dist/ui/themes/googlecode.ts +0 -146
  346. package/dist/ui/themes/no-color.ts +0 -125
  347. package/dist/ui/themes/qwen-dark.ts +0 -118
  348. package/dist/ui/themes/qwen-light.ts +0 -144
  349. package/dist/ui/themes/semantic-tokens.ts +0 -127
  350. package/dist/ui/themes/shades-of-purple.ts +0 -352
  351. package/dist/ui/themes/theme-manager.test.ts +0 -99
  352. package/dist/ui/themes/theme-manager.ts +0 -257
  353. package/dist/ui/themes/theme.test.ts +0 -97
  354. package/dist/ui/themes/theme.ts +0 -451
  355. package/dist/ui/themes/xcode.ts +0 -154
  356. package/dist/ui/types.ts +0 -255
  357. package/dist/ui/utils/CodeColorizer.tsx +0 -217
  358. package/dist/ui/utils/ConsolePatcher.ts +0 -71
  359. package/dist/ui/utils/InlineMarkdownRenderer.tsx +0 -173
  360. package/dist/ui/utils/MarkdownDisplay.test.tsx +0 -244
  361. package/dist/ui/utils/MarkdownDisplay.tsx +0 -415
  362. package/dist/ui/utils/TableRenderer.tsx +0 -159
  363. package/dist/ui/utils/__snapshots__/MarkdownDisplay.test.tsx.snap +0 -93
  364. package/dist/ui/utils/clipboardUtils.test.ts +0 -76
  365. package/dist/ui/utils/clipboardUtils.ts +0 -149
  366. package/dist/ui/utils/commandUtils.test.ts +0 -384
  367. package/dist/ui/utils/commandUtils.ts +0 -106
  368. package/dist/ui/utils/computeStats.test.ts +0 -292
  369. package/dist/ui/utils/computeStats.ts +0 -86
  370. package/dist/ui/utils/displayUtils.test.ts +0 -58
  371. package/dist/ui/utils/displayUtils.ts +0 -32
  372. package/dist/ui/utils/formatters.test.ts +0 -72
  373. package/dist/ui/utils/formatters.ts +0 -63
  374. package/dist/ui/utils/isNarrowWidth.ts +0 -9
  375. package/dist/ui/utils/kittyProtocolDetector.ts +0 -105
  376. package/dist/ui/utils/markdownUtilities.test.ts +0 -50
  377. package/dist/ui/utils/markdownUtilities.ts +0 -125
  378. package/dist/ui/utils/platformConstants.ts +0 -52
  379. package/dist/ui/utils/terminalSetup.ts +0 -342
  380. package/dist/ui/utils/textUtils.ts +0 -40
  381. package/dist/ui/utils/updateCheck.test.ts +0 -163
  382. package/dist/ui/utils/updateCheck.ts +0 -100
  383. package/dist/utils/checks.ts +0 -28
  384. package/dist/utils/cleanup.test.ts +0 -68
  385. package/dist/utils/cleanup.ts +0 -36
  386. package/dist/utils/dialogScopeUtils.ts +0 -64
  387. package/dist/utils/events.ts +0 -14
  388. package/dist/utils/gitUtils.test.ts +0 -149
  389. package/dist/utils/gitUtils.ts +0 -116
  390. package/dist/utils/handleAutoUpdate.test.ts +0 -272
  391. package/dist/utils/handleAutoUpdate.ts +0 -145
  392. package/dist/utils/installationInfo.test.ts +0 -315
  393. package/dist/utils/installationInfo.ts +0 -176
  394. package/dist/utils/package.ts +0 -38
  395. package/dist/utils/readStdin.ts +0 -51
  396. package/dist/utils/resolvePath.ts +0 -21
  397. package/dist/utils/sandbox-macos-permissive-closed.sb +0 -32
  398. package/dist/utils/sandbox-macos-permissive-open.sb +0 -25
  399. package/dist/utils/sandbox-macos-permissive-proxied.sb +0 -37
  400. package/dist/utils/sandbox-macos-restrictive-closed.sb +0 -93
  401. package/dist/utils/sandbox-macos-restrictive-open.sb +0 -96
  402. package/dist/utils/sandbox-macos-restrictive-proxied.sb +0 -98
  403. package/dist/utils/sandbox.ts +0 -962
  404. package/dist/utils/settingsUtils.test.ts +0 -797
  405. package/dist/utils/settingsUtils.ts +0 -489
  406. package/dist/utils/spawnWrapper.ts +0 -9
  407. package/dist/utils/startupWarnings.test.ts +0 -83
  408. package/dist/utils/startupWarnings.ts +0 -40
  409. package/dist/utils/updateEventEmitter.ts +0 -13
  410. package/dist/utils/userStartupWarnings.test.ts +0 -87
  411. package/dist/utils/userStartupWarnings.ts +0 -69
  412. package/dist/utils/version.ts +0 -12
  413. package/dist/validateNonInterActiveAuth.test.ts +0 -260
  414. package/dist/validateNonInterActiveAuth.ts +0 -51
  415. package/dist/vitest.config.ts +0 -37
  416. package/dist/zed-integration/acp.ts +0 -366
  417. package/dist/zed-integration/fileSystemService.ts +0 -47
  418. package/dist/zed-integration/schema.ts +0 -466
  419. package/dist/zed-integration/zedIntegration.ts +0 -944
@@ -1,1728 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import { describe, it, expect, beforeEach } from 'vitest';
8
- import stripAnsi from 'strip-ansi';
9
- import { renderHook, act } from '@testing-library/react';
10
- import {
11
- useTextBuffer,
12
- Viewport,
13
- TextBuffer,
14
- offsetToLogicalPos,
15
- logicalPosToOffset,
16
- textBufferReducer,
17
- TextBufferState,
18
- TextBufferAction,
19
- findWordEndInLine,
20
- findNextWordStartInLine,
21
- isWordCharStrict,
22
- } from './text-buffer.js';
23
- import { cpLen } from '../../utils/textUtils.js';
24
-
25
- const initialState: TextBufferState = {
26
- lines: [''],
27
- cursorRow: 0,
28
- cursorCol: 0,
29
- preferredCol: null,
30
- undoStack: [],
31
- redoStack: [],
32
- clipboard: null,
33
- selectionAnchor: null,
34
- };
35
-
36
- describe('textBufferReducer', () => {
37
- it('should return the initial state if state is undefined', () => {
38
- const action = { type: 'unknown_action' } as unknown as TextBufferAction;
39
- const state = textBufferReducer(initialState, action);
40
- expect(state).toHaveOnlyValidCharacters();
41
- expect(state).toEqual(initialState);
42
- });
43
-
44
- describe('set_text action', () => {
45
- it('should set new text and move cursor to the end', () => {
46
- const action: TextBufferAction = {
47
- type: 'set_text',
48
- payload: 'hello\nworld',
49
- };
50
- const state = textBufferReducer(initialState, action);
51
- expect(state).toHaveOnlyValidCharacters();
52
- expect(state.lines).toEqual(['hello', 'world']);
53
- expect(state.cursorRow).toBe(1);
54
- expect(state.cursorCol).toBe(5);
55
- expect(state.undoStack.length).toBe(1);
56
- });
57
-
58
- it('should not create an undo snapshot if pushToUndo is false', () => {
59
- const action: TextBufferAction = {
60
- type: 'set_text',
61
- payload: 'no undo',
62
- pushToUndo: false,
63
- };
64
- const state = textBufferReducer(initialState, action);
65
- expect(state).toHaveOnlyValidCharacters();
66
- expect(state.lines).toEqual(['no undo']);
67
- expect(state.undoStack.length).toBe(0);
68
- });
69
- });
70
-
71
- describe('insert action', () => {
72
- it('should insert a character', () => {
73
- const action: TextBufferAction = { type: 'insert', payload: 'a' };
74
- const state = textBufferReducer(initialState, action);
75
- expect(state).toHaveOnlyValidCharacters();
76
- expect(state.lines).toEqual(['a']);
77
- expect(state.cursorCol).toBe(1);
78
- });
79
-
80
- it('should insert a newline', () => {
81
- const stateWithText = { ...initialState, lines: ['hello'] };
82
- const action: TextBufferAction = { type: 'insert', payload: '\n' };
83
- const state = textBufferReducer(stateWithText, action);
84
- expect(state).toHaveOnlyValidCharacters();
85
- expect(state.lines).toEqual(['', 'hello']);
86
- expect(state.cursorRow).toBe(1);
87
- expect(state.cursorCol).toBe(0);
88
- });
89
- });
90
-
91
- describe('backspace action', () => {
92
- it('should remove a character', () => {
93
- const stateWithText: TextBufferState = {
94
- ...initialState,
95
- lines: ['a'],
96
- cursorRow: 0,
97
- cursorCol: 1,
98
- };
99
- const action: TextBufferAction = { type: 'backspace' };
100
- const state = textBufferReducer(stateWithText, action);
101
- expect(state).toHaveOnlyValidCharacters();
102
- expect(state.lines).toEqual(['']);
103
- expect(state.cursorCol).toBe(0);
104
- });
105
-
106
- it('should join lines if at the beginning of a line', () => {
107
- const stateWithText: TextBufferState = {
108
- ...initialState,
109
- lines: ['hello', 'world'],
110
- cursorRow: 1,
111
- cursorCol: 0,
112
- };
113
- const action: TextBufferAction = { type: 'backspace' };
114
- const state = textBufferReducer(stateWithText, action);
115
- expect(state).toHaveOnlyValidCharacters();
116
- expect(state.lines).toEqual(['helloworld']);
117
- expect(state.cursorRow).toBe(0);
118
- expect(state.cursorCol).toBe(5);
119
- });
120
- });
121
-
122
- describe('undo/redo actions', () => {
123
- it('should undo and redo a change', () => {
124
- // 1. Insert text
125
- const insertAction: TextBufferAction = {
126
- type: 'insert',
127
- payload: 'test',
128
- };
129
- const stateAfterInsert = textBufferReducer(initialState, insertAction);
130
- expect(stateAfterInsert).toHaveOnlyValidCharacters();
131
- expect(stateAfterInsert.lines).toEqual(['test']);
132
- expect(stateAfterInsert.undoStack.length).toBe(1);
133
-
134
- // 2. Undo
135
- const undoAction: TextBufferAction = { type: 'undo' };
136
- const stateAfterUndo = textBufferReducer(stateAfterInsert, undoAction);
137
- expect(stateAfterUndo).toHaveOnlyValidCharacters();
138
- expect(stateAfterUndo.lines).toEqual(['']);
139
- expect(stateAfterUndo.undoStack.length).toBe(0);
140
- expect(stateAfterUndo.redoStack.length).toBe(1);
141
-
142
- // 3. Redo
143
- const redoAction: TextBufferAction = { type: 'redo' };
144
- const stateAfterRedo = textBufferReducer(stateAfterUndo, redoAction);
145
- expect(stateAfterRedo).toHaveOnlyValidCharacters();
146
- expect(stateAfterRedo.lines).toEqual(['test']);
147
- expect(stateAfterRedo.undoStack.length).toBe(1);
148
- expect(stateAfterRedo.redoStack.length).toBe(0);
149
- });
150
- });
151
-
152
- describe('create_undo_snapshot action', () => {
153
- it('should create a snapshot without changing state', () => {
154
- const stateWithText: TextBufferState = {
155
- ...initialState,
156
- lines: ['hello'],
157
- cursorRow: 0,
158
- cursorCol: 5,
159
- };
160
- const action: TextBufferAction = { type: 'create_undo_snapshot' };
161
- const state = textBufferReducer(stateWithText, action);
162
- expect(state).toHaveOnlyValidCharacters();
163
-
164
- expect(state.lines).toEqual(['hello']);
165
- expect(state.cursorRow).toBe(0);
166
- expect(state.cursorCol).toBe(5);
167
- expect(state.undoStack.length).toBe(1);
168
- expect(state.undoStack[0].lines).toEqual(['hello']);
169
- expect(state.undoStack[0].cursorRow).toBe(0);
170
- expect(state.undoStack[0].cursorCol).toBe(5);
171
- });
172
- });
173
- });
174
-
175
- // Helper to get the state from the hook
176
- const getBufferState = (result: { current: TextBuffer }) => {
177
- expect(result.current).toHaveOnlyValidCharacters();
178
- return {
179
- text: result.current.text,
180
- lines: [...result.current.lines], // Clone for safety
181
- cursor: [...result.current.cursor] as [number, number],
182
- allVisualLines: [...result.current.allVisualLines],
183
- viewportVisualLines: [...result.current.viewportVisualLines],
184
- visualCursor: [...result.current.visualCursor] as [number, number],
185
- visualScrollRow: result.current.visualScrollRow,
186
- preferredCol: result.current.preferredCol,
187
- };
188
- };
189
-
190
- describe('useTextBuffer', () => {
191
- let viewport: Viewport;
192
-
193
- beforeEach(() => {
194
- viewport = { width: 10, height: 3 }; // Default viewport for tests
195
- });
196
-
197
- describe('Initialization', () => {
198
- it('should initialize with empty text and cursor at (0,0) by default', () => {
199
- const { result } = renderHook(() =>
200
- useTextBuffer({ viewport, isValidPath: () => false }),
201
- );
202
- const state = getBufferState(result);
203
- expect(state.text).toBe('');
204
- expect(state.lines).toEqual(['']);
205
- expect(state.cursor).toEqual([0, 0]);
206
- expect(state.allVisualLines).toEqual(['']);
207
- expect(state.viewportVisualLines).toEqual(['']);
208
- expect(state.visualCursor).toEqual([0, 0]);
209
- expect(state.visualScrollRow).toBe(0);
210
- });
211
-
212
- it('should initialize with provided initialText', () => {
213
- const { result } = renderHook(() =>
214
- useTextBuffer({
215
- initialText: 'hello',
216
- viewport,
217
- isValidPath: () => false,
218
- }),
219
- );
220
- const state = getBufferState(result);
221
- expect(state.text).toBe('hello');
222
- expect(state.lines).toEqual(['hello']);
223
- expect(state.cursor).toEqual([0, 0]); // Default cursor if offset not given
224
- expect(state.allVisualLines).toEqual(['hello']);
225
- expect(state.viewportVisualLines).toEqual(['hello']);
226
- expect(state.visualCursor).toEqual([0, 0]);
227
- });
228
-
229
- it('should initialize with initialText and initialCursorOffset', () => {
230
- const { result } = renderHook(() =>
231
- useTextBuffer({
232
- initialText: 'hello\nworld',
233
- initialCursorOffset: 7, // Should be at 'o' in 'world'
234
- viewport,
235
- isValidPath: () => false,
236
- }),
237
- );
238
- const state = getBufferState(result);
239
- expect(state.text).toBe('hello\nworld');
240
- expect(state.lines).toEqual(['hello', 'world']);
241
- expect(state.cursor).toEqual([1, 1]); // Logical cursor at 'o' in "world"
242
- expect(state.allVisualLines).toEqual(['hello', 'world']);
243
- expect(state.viewportVisualLines).toEqual(['hello', 'world']);
244
- expect(state.visualCursor[0]).toBe(1); // On the second visual line
245
- expect(state.visualCursor[1]).toBe(1); // At 'o' in "world"
246
- });
247
-
248
- it('should wrap visual lines', () => {
249
- const { result } = renderHook(() =>
250
- useTextBuffer({
251
- initialText: 'The quick brown fox jumps over the lazy dog.',
252
- initialCursorOffset: 2, // After '好'
253
- viewport: { width: 15, height: 4 },
254
- isValidPath: () => false,
255
- }),
256
- );
257
- const state = getBufferState(result);
258
- expect(state.allVisualLines).toEqual([
259
- 'The quick',
260
- 'brown fox',
261
- 'jumps over the',
262
- 'lazy dog.',
263
- ]);
264
- });
265
-
266
- it('should wrap visual lines with multiple spaces', () => {
267
- const { result } = renderHook(() =>
268
- useTextBuffer({
269
- initialText: 'The quick brown fox jumps over the lazy dog.',
270
- viewport: { width: 15, height: 4 },
271
- isValidPath: () => false,
272
- }),
273
- );
274
- const state = getBufferState(result);
275
- // Including multiple spaces at the end of the lines like this is
276
- // consistent with Google docs behavior and makes it intuitive to edit
277
- // the spaces as needed.
278
- expect(state.allVisualLines).toEqual([
279
- 'The quick ',
280
- 'brown fox ',
281
- 'jumps over the',
282
- 'lazy dog.',
283
- ]);
284
- });
285
-
286
- it('should wrap visual lines even without spaces', () => {
287
- const { result } = renderHook(() =>
288
- useTextBuffer({
289
- initialText: '123456789012345ABCDEFG', // 4 chars, 12 bytes
290
- viewport: { width: 15, height: 2 },
291
- isValidPath: () => false,
292
- }),
293
- );
294
- const state = getBufferState(result);
295
- // Including multiple spaces at the end of the lines like this is
296
- // consistent with Google docs behavior and makes it intuitive to edit
297
- // the spaces as needed.
298
- expect(state.allVisualLines).toEqual(['123456789012345', 'ABCDEFG']);
299
- });
300
-
301
- it('should initialize with multi-byte unicode characters and correct cursor offset', () => {
302
- const { result } = renderHook(() =>
303
- useTextBuffer({
304
- initialText: '你好世界', // 4 chars, 12 bytes
305
- initialCursorOffset: 2, // After '好'
306
- viewport: { width: 5, height: 2 },
307
- isValidPath: () => false,
308
- }),
309
- );
310
- const state = getBufferState(result);
311
- expect(state.text).toBe('你好世界');
312
- expect(state.lines).toEqual(['你好世界']);
313
- expect(state.cursor).toEqual([0, 2]);
314
- // Visual: "你好" (width 4), "世"界" (width 4) with viewport width 5
315
- expect(state.allVisualLines).toEqual(['你好', '世界']);
316
- expect(state.visualCursor).toEqual([1, 0]);
317
- });
318
- });
319
-
320
- describe('Basic Editing', () => {
321
- it('insert: should insert a character and update cursor', () => {
322
- const { result } = renderHook(() =>
323
- useTextBuffer({ viewport, isValidPath: () => false }),
324
- );
325
- act(() => result.current.insert('a'));
326
- let state = getBufferState(result);
327
- expect(state.text).toBe('a');
328
- expect(state.cursor).toEqual([0, 1]);
329
- expect(state.visualCursor).toEqual([0, 1]);
330
-
331
- act(() => result.current.insert('b'));
332
- state = getBufferState(result);
333
- expect(state.text).toBe('ab');
334
- expect(state.cursor).toEqual([0, 2]);
335
- expect(state.visualCursor).toEqual([0, 2]);
336
- });
337
-
338
- it('insert: should insert text in the middle of a line', () => {
339
- const { result } = renderHook(() =>
340
- useTextBuffer({
341
- initialText: 'abc',
342
- viewport,
343
- isValidPath: () => false,
344
- }),
345
- );
346
- act(() => result.current.move('right'));
347
- act(() => result.current.insert('-NEW-'));
348
- const state = getBufferState(result);
349
- expect(state.text).toBe('a-NEW-bc');
350
- expect(state.cursor).toEqual([0, 6]);
351
- });
352
-
353
- it('newline: should create a new line and move cursor', () => {
354
- const { result } = renderHook(() =>
355
- useTextBuffer({
356
- initialText: 'ab',
357
- viewport,
358
- isValidPath: () => false,
359
- }),
360
- );
361
- act(() => result.current.move('end')); // cursor at [0,2]
362
- act(() => result.current.newline());
363
- const state = getBufferState(result);
364
- expect(state.text).toBe('ab\n');
365
- expect(state.lines).toEqual(['ab', '']);
366
- expect(state.cursor).toEqual([1, 0]);
367
- expect(state.allVisualLines).toEqual(['ab', '']);
368
- expect(state.viewportVisualLines).toEqual(['ab', '']); // viewport height 3
369
- expect(state.visualCursor).toEqual([1, 0]); // On the new visual line
370
- });
371
-
372
- it('backspace: should delete char to the left or merge lines', () => {
373
- const { result } = renderHook(() =>
374
- useTextBuffer({
375
- initialText: 'a\nb',
376
- viewport,
377
- isValidPath: () => false,
378
- }),
379
- );
380
- act(() => {
381
- result.current.move('down');
382
- });
383
- act(() => {
384
- result.current.move('end'); // cursor to [1,1] (end of 'b')
385
- });
386
- act(() => result.current.backspace()); // delete 'b'
387
- let state = getBufferState(result);
388
- expect(state.text).toBe('a\n');
389
- expect(state.cursor).toEqual([1, 0]);
390
-
391
- act(() => result.current.backspace()); // merge lines
392
- state = getBufferState(result);
393
- expect(state.text).toBe('a');
394
- expect(state.cursor).toEqual([0, 1]); // cursor after 'a'
395
- expect(state.allVisualLines).toEqual(['a']);
396
- expect(state.viewportVisualLines).toEqual(['a']);
397
- expect(state.visualCursor).toEqual([0, 1]);
398
- });
399
-
400
- it('del: should delete char to the right or merge lines', () => {
401
- const { result } = renderHook(() =>
402
- useTextBuffer({
403
- initialText: 'a\nb',
404
- viewport,
405
- isValidPath: () => false,
406
- }),
407
- );
408
- // cursor at [0,0]
409
- act(() => result.current.del()); // delete 'a'
410
- let state = getBufferState(result);
411
- expect(state.text).toBe('\nb');
412
- expect(state.cursor).toEqual([0, 0]);
413
-
414
- act(() => result.current.del()); // merge lines (deletes newline)
415
- state = getBufferState(result);
416
- expect(state.text).toBe('b');
417
- expect(state.cursor).toEqual([0, 0]);
418
- expect(state.allVisualLines).toEqual(['b']);
419
- expect(state.viewportVisualLines).toEqual(['b']);
420
- expect(state.visualCursor).toEqual([0, 0]);
421
- });
422
- });
423
-
424
- describe('Drag and Drop File Paths', () => {
425
- it('should prepend @ to a valid file path on insert', () => {
426
- const { result } = renderHook(() =>
427
- useTextBuffer({ viewport, isValidPath: () => true }),
428
- );
429
- const filePath = '/path/to/a/valid/file.txt';
430
- act(() => result.current.insert(filePath, { paste: true }));
431
- expect(getBufferState(result).text).toBe(`@${filePath} `);
432
- });
433
-
434
- it('should not prepend @ to an invalid file path on insert', () => {
435
- const { result } = renderHook(() =>
436
- useTextBuffer({ viewport, isValidPath: () => false }),
437
- );
438
- const notAPath = 'this is just some long text';
439
- act(() => result.current.insert(notAPath, { paste: true }));
440
- expect(getBufferState(result).text).toBe(notAPath);
441
- });
442
-
443
- it('should handle quoted paths', () => {
444
- const { result } = renderHook(() =>
445
- useTextBuffer({ viewport, isValidPath: () => true }),
446
- );
447
- const filePath = "'/path/to/a/valid/file.txt'";
448
- act(() => result.current.insert(filePath, { paste: true }));
449
- expect(getBufferState(result).text).toBe(`@/path/to/a/valid/file.txt `);
450
- });
451
-
452
- it('should not prepend @ to short text that is not a path', () => {
453
- const { result } = renderHook(() =>
454
- useTextBuffer({ viewport, isValidPath: () => true }),
455
- );
456
- const shortText = 'ab';
457
- act(() => result.current.insert(shortText, { paste: true }));
458
- expect(getBufferState(result).text).toBe(shortText);
459
- });
460
- });
461
-
462
- describe('Shell Mode Behavior', () => {
463
- it('should not prepend @ to valid file paths when shellModeActive is true', () => {
464
- const { result } = renderHook(() =>
465
- useTextBuffer({
466
- viewport,
467
- isValidPath: () => true,
468
- shellModeActive: true,
469
- }),
470
- );
471
- const filePath = '/path/to/a/valid/file.txt';
472
- act(() => result.current.insert(filePath, { paste: true }));
473
- expect(getBufferState(result).text).toBe(filePath); // No @ prefix
474
- });
475
-
476
- it('should not prepend @ to quoted paths when shellModeActive is true', () => {
477
- const { result } = renderHook(() =>
478
- useTextBuffer({
479
- viewport,
480
- isValidPath: () => true,
481
- shellModeActive: true,
482
- }),
483
- );
484
- const quotedFilePath = "'/path/to/a/valid/file.txt'";
485
- act(() => result.current.insert(quotedFilePath, { paste: true }));
486
- expect(getBufferState(result).text).toBe(quotedFilePath); // No @ prefix, keeps quotes
487
- });
488
-
489
- it('should behave normally with invalid paths when shellModeActive is true', () => {
490
- const { result } = renderHook(() =>
491
- useTextBuffer({
492
- viewport,
493
- isValidPath: () => false,
494
- shellModeActive: true,
495
- }),
496
- );
497
- const notAPath = 'this is just some text';
498
- act(() => result.current.insert(notAPath, { paste: true }));
499
- expect(getBufferState(result).text).toBe(notAPath);
500
- });
501
-
502
- it('should behave normally with short text when shellModeActive is true', () => {
503
- const { result } = renderHook(() =>
504
- useTextBuffer({
505
- viewport,
506
- isValidPath: () => true,
507
- shellModeActive: true,
508
- }),
509
- );
510
- const shortText = 'ls';
511
- act(() => result.current.insert(shortText, { paste: true }));
512
- expect(getBufferState(result).text).toBe(shortText); // No @ prefix for short text
513
- });
514
- });
515
-
516
- describe('Cursor Movement', () => {
517
- it('move: left/right should work within and across visual lines (due to wrapping)', () => {
518
- // Text: "long line1next line2" (20 chars)
519
- // Viewport width 5. Word wrapping should produce:
520
- // "long " (5)
521
- // "line1" (5)
522
- // "next " (5)
523
- // "line2" (5)
524
- const { result } = renderHook(() =>
525
- useTextBuffer({
526
- initialText: 'long line1next line2', // Corrected: was 'long line1next line2'
527
- viewport: { width: 5, height: 4 },
528
- isValidPath: () => false,
529
- }),
530
- );
531
- // Initial cursor [0,0] logical, visual [0,0] ("l" of "long ")
532
-
533
- act(() => result.current.move('right')); // visual [0,1] ("o")
534
- expect(getBufferState(result).visualCursor).toEqual([0, 1]);
535
- act(() => result.current.move('right')); // visual [0,2] ("n")
536
- act(() => result.current.move('right')); // visual [0,3] ("g")
537
- act(() => result.current.move('right')); // visual [0,4] (" ")
538
- expect(getBufferState(result).visualCursor).toEqual([0, 4]);
539
-
540
- act(() => result.current.move('right')); // visual [1,0] ("l" of "line1")
541
- expect(getBufferState(result).visualCursor).toEqual([1, 0]);
542
- expect(getBufferState(result).cursor).toEqual([0, 5]); // logical cursor
543
-
544
- act(() => result.current.move('left')); // visual [0,4] (" " of "long ")
545
- expect(getBufferState(result).visualCursor).toEqual([0, 4]);
546
- expect(getBufferState(result).cursor).toEqual([0, 4]); // logical cursor
547
- });
548
-
549
- it('move: up/down should preserve preferred visual column', () => {
550
- const text = 'abcde\nxy\n12345';
551
- const { result } = renderHook(() =>
552
- useTextBuffer({
553
- initialText: text,
554
- viewport,
555
- isValidPath: () => false,
556
- }),
557
- );
558
- expect(result.current.allVisualLines).toEqual(['abcde', 'xy', '12345']);
559
- // Place cursor at the end of "abcde" -> logical [0,5]
560
- act(() => {
561
- result.current.move('home'); // to [0,0]
562
- });
563
- for (let i = 0; i < 5; i++) {
564
- act(() => {
565
- result.current.move('right'); // to [0,5]
566
- });
567
- }
568
- expect(getBufferState(result).cursor).toEqual([0, 5]);
569
- expect(getBufferState(result).visualCursor).toEqual([0, 5]);
570
-
571
- // Set preferredCol by moving up then down to the same spot, then test.
572
- act(() => {
573
- result.current.move('down'); // to xy, logical [1,2], visual [1,2], preferredCol should be 5
574
- });
575
- let state = getBufferState(result);
576
- expect(state.cursor).toEqual([1, 2]); // Logical cursor at end of 'xy'
577
- expect(state.visualCursor).toEqual([1, 2]); // Visual cursor at end of 'xy'
578
- expect(state.preferredCol).toBe(5);
579
-
580
- act(() => result.current.move('down')); // to '12345', preferredCol=5.
581
- state = getBufferState(result);
582
- expect(state.cursor).toEqual([2, 5]); // Logical cursor at end of '12345'
583
- expect(state.visualCursor).toEqual([2, 5]); // Visual cursor at end of '12345'
584
- expect(state.preferredCol).toBe(5); // Preferred col is maintained
585
-
586
- act(() => result.current.move('left')); // preferredCol should reset
587
- state = getBufferState(result);
588
- expect(state.preferredCol).toBe(null);
589
- });
590
-
591
- it('move: home/end should go to visual line start/end', () => {
592
- const initialText = 'line one\nsecond line';
593
- const { result } = renderHook(() =>
594
- useTextBuffer({
595
- initialText,
596
- viewport: { width: 5, height: 5 },
597
- isValidPath: () => false,
598
- }),
599
- );
600
- expect(result.current.allVisualLines).toEqual([
601
- 'line',
602
- 'one',
603
- 'secon',
604
- 'd',
605
- 'line',
606
- ]);
607
- // Initial cursor [0,0] (start of "line")
608
- act(() => result.current.move('down')); // visual cursor from [0,0] to [1,0] ("o" of "one")
609
- act(() => result.current.move('right')); // visual cursor to [1,1] ("n" of "one")
610
- expect(getBufferState(result).visualCursor).toEqual([1, 1]);
611
-
612
- act(() => result.current.move('home')); // visual cursor to [1,0] (start of "one")
613
- expect(getBufferState(result).visualCursor).toEqual([1, 0]);
614
-
615
- act(() => result.current.move('end')); // visual cursor to [1,3] (end of "one")
616
- expect(getBufferState(result).visualCursor).toEqual([1, 3]); // "one" is 3 chars
617
- });
618
- });
619
-
620
- describe('Visual Layout & Viewport', () => {
621
- it('should wrap long lines correctly into visualLines', () => {
622
- const { result } = renderHook(() =>
623
- useTextBuffer({
624
- initialText: 'This is a very long line of text.', // 33 chars
625
- viewport: { width: 10, height: 5 },
626
- isValidPath: () => false,
627
- }),
628
- );
629
- const state = getBufferState(result);
630
- // Expected visual lines with word wrapping (viewport width 10):
631
- // "This is a"
632
- // "very long"
633
- // "line of"
634
- // "text."
635
- expect(state.allVisualLines.length).toBe(4);
636
- expect(state.allVisualLines[0]).toBe('This is a');
637
- expect(state.allVisualLines[1]).toBe('very long');
638
- expect(state.allVisualLines[2]).toBe('line of');
639
- expect(state.allVisualLines[3]).toBe('text.');
640
- });
641
-
642
- it('should update visualScrollRow when visualCursor moves out of viewport', () => {
643
- const { result } = renderHook(() =>
644
- useTextBuffer({
645
- initialText: 'l1\nl2\nl3\nl4\nl5',
646
- viewport: { width: 5, height: 3 }, // Can show 3 visual lines
647
- isValidPath: () => false,
648
- }),
649
- );
650
- // Initial: l1, l2, l3 visible. visualScrollRow = 0. visualCursor = [0,0]
651
- expect(getBufferState(result).visualScrollRow).toBe(0);
652
- expect(getBufferState(result).allVisualLines).toEqual([
653
- 'l1',
654
- 'l2',
655
- 'l3',
656
- 'l4',
657
- 'l5',
658
- ]);
659
- expect(getBufferState(result).viewportVisualLines).toEqual([
660
- 'l1',
661
- 'l2',
662
- 'l3',
663
- ]);
664
-
665
- act(() => result.current.move('down')); // vc=[1,0]
666
- act(() => result.current.move('down')); // vc=[2,0] (l3)
667
- expect(getBufferState(result).visualScrollRow).toBe(0);
668
-
669
- act(() => result.current.move('down')); // vc=[3,0] (l4) - scroll should happen
670
- // Now: l2, l3, l4 visible. visualScrollRow = 1.
671
- let state = getBufferState(result);
672
- expect(state.visualScrollRow).toBe(1);
673
- expect(state.allVisualLines).toEqual(['l1', 'l2', 'l3', 'l4', 'l5']);
674
- expect(state.viewportVisualLines).toEqual(['l2', 'l3', 'l4']);
675
- expect(state.visualCursor).toEqual([3, 0]);
676
-
677
- act(() => result.current.move('up')); // vc=[2,0] (l3)
678
- act(() => result.current.move('up')); // vc=[1,0] (l2)
679
- expect(getBufferState(result).visualScrollRow).toBe(1);
680
-
681
- act(() => result.current.move('up')); // vc=[0,0] (l1) - scroll up
682
- // Now: l1, l2, l3 visible. visualScrollRow = 0
683
- state = getBufferState(result); // Assign to the existing `state` variable
684
- expect(state.visualScrollRow).toBe(0);
685
- expect(state.allVisualLines).toEqual(['l1', 'l2', 'l3', 'l4', 'l5']);
686
- expect(state.viewportVisualLines).toEqual(['l1', 'l2', 'l3']);
687
- expect(state.visualCursor).toEqual([0, 0]);
688
- });
689
- });
690
-
691
- describe('Undo/Redo', () => {
692
- it('should undo and redo an insert operation', () => {
693
- const { result } = renderHook(() =>
694
- useTextBuffer({ viewport, isValidPath: () => false }),
695
- );
696
- act(() => result.current.insert('a'));
697
- expect(getBufferState(result).text).toBe('a');
698
-
699
- act(() => result.current.undo());
700
- expect(getBufferState(result).text).toBe('');
701
- expect(getBufferState(result).cursor).toEqual([0, 0]);
702
-
703
- act(() => result.current.redo());
704
- expect(getBufferState(result).text).toBe('a');
705
- expect(getBufferState(result).cursor).toEqual([0, 1]);
706
- });
707
-
708
- it('should undo and redo a newline operation', () => {
709
- const { result } = renderHook(() =>
710
- useTextBuffer({
711
- initialText: 'test',
712
- viewport,
713
- isValidPath: () => false,
714
- }),
715
- );
716
- act(() => result.current.move('end'));
717
- act(() => result.current.newline());
718
- expect(getBufferState(result).text).toBe('test\n');
719
-
720
- act(() => result.current.undo());
721
- expect(getBufferState(result).text).toBe('test');
722
- expect(getBufferState(result).cursor).toEqual([0, 4]);
723
-
724
- act(() => result.current.redo());
725
- expect(getBufferState(result).text).toBe('test\n');
726
- expect(getBufferState(result).cursor).toEqual([1, 0]);
727
- });
728
- });
729
-
730
- describe('Unicode Handling', () => {
731
- it('insert: should correctly handle multi-byte unicode characters', () => {
732
- const { result } = renderHook(() =>
733
- useTextBuffer({ viewport, isValidPath: () => false }),
734
- );
735
- act(() => result.current.insert('你好'));
736
- const state = getBufferState(result);
737
- expect(state.text).toBe('你好');
738
- expect(state.cursor).toEqual([0, 2]); // Cursor is 2 (char count)
739
- expect(state.visualCursor).toEqual([0, 2]);
740
- });
741
-
742
- it('backspace: should correctly delete multi-byte unicode characters', () => {
743
- const { result } = renderHook(() =>
744
- useTextBuffer({
745
- initialText: '你好',
746
- viewport,
747
- isValidPath: () => false,
748
- }),
749
- );
750
- act(() => result.current.move('end')); // cursor at [0,2]
751
- act(() => result.current.backspace()); // delete '好'
752
- let state = getBufferState(result);
753
- expect(state.text).toBe('你');
754
- expect(state.cursor).toEqual([0, 1]);
755
-
756
- act(() => result.current.backspace()); // delete '你'
757
- state = getBufferState(result);
758
- expect(state.text).toBe('');
759
- expect(state.cursor).toEqual([0, 0]);
760
- });
761
-
762
- it('move: left/right should treat multi-byte chars as single units for visual cursor', () => {
763
- const { result } = renderHook(() =>
764
- useTextBuffer({
765
- initialText: '🐶🐱',
766
- viewport: { width: 5, height: 1 },
767
- isValidPath: () => false,
768
- }),
769
- );
770
- // Initial: visualCursor [0,0]
771
- act(() => result.current.move('right')); // visualCursor [0,1] (after 🐶)
772
- let state = getBufferState(result);
773
- expect(state.cursor).toEqual([0, 1]);
774
- expect(state.visualCursor).toEqual([0, 1]);
775
-
776
- act(() => result.current.move('right')); // visualCursor [0,2] (after 🐱)
777
- state = getBufferState(result);
778
- expect(state.cursor).toEqual([0, 2]);
779
- expect(state.visualCursor).toEqual([0, 2]);
780
-
781
- act(() => result.current.move('left')); // visualCursor [0,1] (before 🐱 / after 🐶)
782
- state = getBufferState(result);
783
- expect(state.cursor).toEqual([0, 1]);
784
- expect(state.visualCursor).toEqual([0, 1]);
785
- });
786
- });
787
-
788
- describe('handleInput', () => {
789
- it('should insert printable characters', () => {
790
- const { result } = renderHook(() =>
791
- useTextBuffer({ viewport, isValidPath: () => false }),
792
- );
793
- act(() =>
794
- result.current.handleInput({
795
- name: 'h',
796
- ctrl: false,
797
- meta: false,
798
- shift: false,
799
- paste: false,
800
- sequence: 'h',
801
- }),
802
- );
803
- act(() =>
804
- result.current.handleInput({
805
- name: 'i',
806
- ctrl: false,
807
- meta: false,
808
- shift: false,
809
- paste: false,
810
- sequence: 'i',
811
- }),
812
- );
813
- expect(getBufferState(result).text).toBe('hi');
814
- });
815
-
816
- it('should handle "Enter" key as newline', () => {
817
- const { result } = renderHook(() =>
818
- useTextBuffer({ viewport, isValidPath: () => false }),
819
- );
820
- act(() =>
821
- result.current.handleInput({
822
- name: 'return',
823
- ctrl: false,
824
- meta: false,
825
- shift: false,
826
- paste: false,
827
- sequence: '\r',
828
- }),
829
- );
830
- expect(getBufferState(result).lines).toEqual(['', '']);
831
- });
832
-
833
- it('should handle "Backspace" key', () => {
834
- const { result } = renderHook(() =>
835
- useTextBuffer({
836
- initialText: 'a',
837
- viewport,
838
- isValidPath: () => false,
839
- }),
840
- );
841
- act(() => result.current.move('end'));
842
- act(() =>
843
- result.current.handleInput({
844
- name: 'backspace',
845
- ctrl: false,
846
- meta: false,
847
- shift: false,
848
- paste: false,
849
- sequence: '\x7f',
850
- }),
851
- );
852
- expect(getBufferState(result).text).toBe('');
853
- });
854
-
855
- it('should handle multiple delete characters in one input', () => {
856
- const { result } = renderHook(() =>
857
- useTextBuffer({
858
- initialText: 'abcde',
859
- viewport,
860
- isValidPath: () => false,
861
- }),
862
- );
863
- act(() => result.current.move('end')); // cursor at the end
864
- expect(getBufferState(result).cursor).toEqual([0, 5]);
865
-
866
- act(() => {
867
- result.current.handleInput({
868
- name: 'backspace',
869
- ctrl: false,
870
- meta: false,
871
- shift: false,
872
- paste: false,
873
- sequence: '\x7f',
874
- });
875
- result.current.handleInput({
876
- name: 'backspace',
877
- ctrl: false,
878
- meta: false,
879
- shift: false,
880
- paste: false,
881
- sequence: '\x7f',
882
- });
883
- result.current.handleInput({
884
- name: 'backspace',
885
- ctrl: false,
886
- meta: false,
887
- shift: false,
888
- paste: false,
889
- sequence: '\x7f',
890
- });
891
- });
892
- expect(getBufferState(result).text).toBe('ab');
893
- expect(getBufferState(result).cursor).toEqual([0, 2]);
894
- });
895
-
896
- it('should handle inserts that contain delete characters ', () => {
897
- const { result } = renderHook(() =>
898
- useTextBuffer({
899
- initialText: 'abcde',
900
- viewport,
901
- isValidPath: () => false,
902
- }),
903
- );
904
- act(() => result.current.move('end')); // cursor at the end
905
- expect(getBufferState(result).cursor).toEqual([0, 5]);
906
-
907
- act(() => {
908
- result.current.insert('\x7f\x7f\x7f');
909
- });
910
- expect(getBufferState(result).text).toBe('ab');
911
- expect(getBufferState(result).cursor).toEqual([0, 2]);
912
- });
913
-
914
- it('should handle inserts with a mix of regular and delete characters ', () => {
915
- const { result } = renderHook(() =>
916
- useTextBuffer({
917
- initialText: 'abcde',
918
- viewport,
919
- isValidPath: () => false,
920
- }),
921
- );
922
- act(() => result.current.move('end')); // cursor at the end
923
- expect(getBufferState(result).cursor).toEqual([0, 5]);
924
-
925
- act(() => {
926
- result.current.insert('\x7fI\x7f\x7fNEW');
927
- });
928
- expect(getBufferState(result).text).toBe('abcNEW');
929
- expect(getBufferState(result).cursor).toEqual([0, 6]);
930
- });
931
-
932
- it('should handle arrow keys for movement', () => {
933
- const { result } = renderHook(() =>
934
- useTextBuffer({
935
- initialText: 'ab',
936
- viewport,
937
- isValidPath: () => false,
938
- }),
939
- );
940
- act(() => result.current.move('end')); // cursor [0,2]
941
- act(() =>
942
- result.current.handleInput({
943
- name: 'left',
944
- ctrl: false,
945
- meta: false,
946
- shift: false,
947
- paste: false,
948
- sequence: '\x1b[D',
949
- }),
950
- ); // cursor [0,1]
951
- expect(getBufferState(result).cursor).toEqual([0, 1]);
952
- act(() =>
953
- result.current.handleInput({
954
- name: 'right',
955
- ctrl: false,
956
- meta: false,
957
- shift: false,
958
- paste: false,
959
- sequence: '\x1b[C',
960
- }),
961
- ); // cursor [0,2]
962
- expect(getBufferState(result).cursor).toEqual([0, 2]);
963
- });
964
-
965
- it('should strip ANSI escape codes when pasting text', () => {
966
- const { result } = renderHook(() =>
967
- useTextBuffer({ viewport, isValidPath: () => false }),
968
- );
969
- const textWithAnsi = '\x1B[31mHello\x1B[0m \x1B[32mWorld\x1B[0m';
970
- // Simulate pasting by calling handleInput with a string longer than 1 char
971
- act(() =>
972
- result.current.handleInput({
973
- name: '',
974
- ctrl: false,
975
- meta: false,
976
- shift: false,
977
- paste: false,
978
- sequence: textWithAnsi,
979
- }),
980
- );
981
- expect(getBufferState(result).text).toBe('Hello World');
982
- });
983
-
984
- it('should handle VSCode terminal Shift+Enter as newline', () => {
985
- const { result } = renderHook(() =>
986
- useTextBuffer({ viewport, isValidPath: () => false }),
987
- );
988
- act(() =>
989
- result.current.handleInput({
990
- name: 'return',
991
- ctrl: false,
992
- meta: false,
993
- shift: true,
994
- paste: false,
995
- sequence: '\r',
996
- }),
997
- ); // Simulates Shift+Enter in VSCode terminal
998
- expect(getBufferState(result).lines).toEqual(['', '']);
999
- });
1000
-
1001
- it('should correctly handle repeated pasting of long text', () => {
1002
- const longText = `not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
1003
-
1004
- Why do we use it?
1005
- It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
1006
-
1007
- Where does it come from?
1008
- Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lore
1009
- `;
1010
- const { result } = renderHook(() =>
1011
- useTextBuffer({ viewport, isValidPath: () => false }),
1012
- );
1013
-
1014
- // Simulate pasting the long text multiple times
1015
- act(() => {
1016
- result.current.insert(longText, { paste: true });
1017
- result.current.insert(longText, { paste: true });
1018
- result.current.insert(longText, { paste: true });
1019
- });
1020
-
1021
- const state = getBufferState(result);
1022
- // Check that the text is the result of three concatenations.
1023
- expect(state.lines).toStrictEqual(
1024
- (longText + longText + longText).split('\n'),
1025
- );
1026
- const expectedCursorPos = offsetToLogicalPos(
1027
- state.text,
1028
- state.text.length,
1029
- );
1030
- expect(state.cursor).toEqual(expectedCursorPos);
1031
- });
1032
- });
1033
-
1034
- // More tests would be needed for:
1035
- // - setText, replaceRange
1036
- // - deleteWordLeft, deleteWordRight
1037
- // - More complex undo/redo scenarios
1038
- // - Selection and clipboard (copy/paste) - might need clipboard API mocks or internal state check
1039
- // - openInExternalEditor (heavy mocking of fs, child_process, os)
1040
- // - All edge cases for visual scrolling and wrapping with different viewport sizes and text content.
1041
-
1042
- describe('replaceRange', () => {
1043
- it('should replace a single-line range with single-line text', () => {
1044
- const { result } = renderHook(() =>
1045
- useTextBuffer({
1046
- initialText: '@pac',
1047
- viewport,
1048
- isValidPath: () => false,
1049
- }),
1050
- );
1051
- act(() => result.current.replaceRange(0, 1, 0, 4, 'packages'));
1052
- const state = getBufferState(result);
1053
- expect(state.text).toBe('@packages');
1054
- expect(state.cursor).toEqual([0, 9]); // cursor after 'typescript'
1055
- });
1056
-
1057
- it('should replace a multi-line range with single-line text', () => {
1058
- const { result } = renderHook(() =>
1059
- useTextBuffer({
1060
- initialText: 'hello\nworld\nagain',
1061
- viewport,
1062
- isValidPath: () => false,
1063
- }),
1064
- );
1065
- act(() => result.current.replaceRange(0, 2, 1, 3, ' new ')); // replace 'llo\nwor' with ' new '
1066
- const state = getBufferState(result);
1067
- expect(state.text).toBe('he new ld\nagain');
1068
- expect(state.cursor).toEqual([0, 7]); // cursor after ' new '
1069
- });
1070
-
1071
- it('should delete a range when replacing with an empty string', () => {
1072
- const { result } = renderHook(() =>
1073
- useTextBuffer({
1074
- initialText: 'hello world',
1075
- viewport,
1076
- isValidPath: () => false,
1077
- }),
1078
- );
1079
- act(() => result.current.replaceRange(0, 5, 0, 11, '')); // delete ' world'
1080
- const state = getBufferState(result);
1081
- expect(state.text).toBe('hello');
1082
- expect(state.cursor).toEqual([0, 5]);
1083
- });
1084
-
1085
- it('should handle replacing at the beginning of the text', () => {
1086
- const { result } = renderHook(() =>
1087
- useTextBuffer({
1088
- initialText: 'world',
1089
- viewport,
1090
- isValidPath: () => false,
1091
- }),
1092
- );
1093
- act(() => result.current.replaceRange(0, 0, 0, 0, 'hello '));
1094
- const state = getBufferState(result);
1095
- expect(state.text).toBe('hello world');
1096
- expect(state.cursor).toEqual([0, 6]);
1097
- });
1098
-
1099
- it('should handle replacing at the end of the text', () => {
1100
- const { result } = renderHook(() =>
1101
- useTextBuffer({
1102
- initialText: 'hello',
1103
- viewport,
1104
- isValidPath: () => false,
1105
- }),
1106
- );
1107
- act(() => result.current.replaceRange(0, 5, 0, 5, ' world'));
1108
- const state = getBufferState(result);
1109
- expect(state.text).toBe('hello world');
1110
- expect(state.cursor).toEqual([0, 11]);
1111
- });
1112
-
1113
- it('should handle replacing the entire buffer content', () => {
1114
- const { result } = renderHook(() =>
1115
- useTextBuffer({
1116
- initialText: 'old text',
1117
- viewport,
1118
- isValidPath: () => false,
1119
- }),
1120
- );
1121
- act(() => result.current.replaceRange(0, 0, 0, 8, 'new text'));
1122
- const state = getBufferState(result);
1123
- expect(state.text).toBe('new text');
1124
- expect(state.cursor).toEqual([0, 8]);
1125
- });
1126
-
1127
- it('should correctly replace with unicode characters', () => {
1128
- const { result } = renderHook(() =>
1129
- useTextBuffer({
1130
- initialText: 'hello *** world',
1131
- viewport,
1132
- isValidPath: () => false,
1133
- }),
1134
- );
1135
- act(() => result.current.replaceRange(0, 6, 0, 9, '你好'));
1136
- const state = getBufferState(result);
1137
- expect(state.text).toBe('hello 你好 world');
1138
- expect(state.cursor).toEqual([0, 8]); // after '你好'
1139
- });
1140
-
1141
- it('should handle invalid range by returning false and not changing text', () => {
1142
- const { result } = renderHook(() =>
1143
- useTextBuffer({
1144
- initialText: 'test',
1145
- viewport,
1146
- isValidPath: () => false,
1147
- }),
1148
- );
1149
- act(() => {
1150
- result.current.replaceRange(0, 5, 0, 3, 'fail'); // startCol > endCol in same line
1151
- });
1152
-
1153
- expect(getBufferState(result).text).toBe('test');
1154
-
1155
- act(() => {
1156
- result.current.replaceRange(1, 0, 0, 0, 'fail'); // startRow > endRow
1157
- });
1158
- expect(getBufferState(result).text).toBe('test');
1159
- });
1160
-
1161
- it('replaceRange: multiple lines with a single character', () => {
1162
- const { result } = renderHook(() =>
1163
- useTextBuffer({
1164
- initialText: 'first\nsecond\nthird',
1165
- viewport,
1166
- isValidPath: () => false,
1167
- }),
1168
- );
1169
- act(() => result.current.replaceRange(0, 2, 2, 3, 'X')); // Replace 'rst\nsecond\nthi'
1170
- const state = getBufferState(result);
1171
- expect(state.text).toBe('fiXrd');
1172
- expect(state.cursor).toEqual([0, 3]); // After 'X'
1173
- });
1174
-
1175
- it('should replace a single-line range with multi-line text', () => {
1176
- const { result } = renderHook(() =>
1177
- useTextBuffer({
1178
- initialText: 'one two three',
1179
- viewport,
1180
- isValidPath: () => false,
1181
- }),
1182
- );
1183
- // Replace "two" with "new\nline"
1184
- act(() => result.current.replaceRange(0, 4, 0, 7, 'new\nline'));
1185
- const state = getBufferState(result);
1186
- expect(state.lines).toEqual(['one new', 'line three']);
1187
- expect(state.text).toBe('one new\nline three');
1188
- expect(state.cursor).toEqual([1, 4]); // cursor after 'line'
1189
- });
1190
- });
1191
-
1192
- describe('Input Sanitization', () => {
1193
- it('should strip ANSI escape codes from input', () => {
1194
- const { result } = renderHook(() =>
1195
- useTextBuffer({ viewport, isValidPath: () => false }),
1196
- );
1197
- const textWithAnsi = '\x1B[31mHello\x1B[0m \x1B[32mWorld\x1B[0m';
1198
- act(() =>
1199
- result.current.handleInput({
1200
- name: '',
1201
- ctrl: false,
1202
- meta: false,
1203
- shift: false,
1204
- paste: false,
1205
- sequence: textWithAnsi,
1206
- }),
1207
- );
1208
- expect(getBufferState(result).text).toBe('Hello World');
1209
- });
1210
-
1211
- it('should strip control characters from input', () => {
1212
- const { result } = renderHook(() =>
1213
- useTextBuffer({ viewport, isValidPath: () => false }),
1214
- );
1215
- const textWithControlChars = 'H\x07e\x08l\x0Bl\x0Co'; // BELL, BACKSPACE, VT, FF
1216
- act(() =>
1217
- result.current.handleInput({
1218
- name: '',
1219
- ctrl: false,
1220
- meta: false,
1221
- shift: false,
1222
- paste: false,
1223
- sequence: textWithControlChars,
1224
- }),
1225
- );
1226
- expect(getBufferState(result).text).toBe('Hello');
1227
- });
1228
-
1229
- it('should strip mixed ANSI and control characters from input', () => {
1230
- const { result } = renderHook(() =>
1231
- useTextBuffer({ viewport, isValidPath: () => false }),
1232
- );
1233
- const textWithMixed = '\u001B[4mH\u001B[0mello';
1234
- act(() =>
1235
- result.current.handleInput({
1236
- name: '',
1237
- ctrl: false,
1238
- meta: false,
1239
- shift: false,
1240
- paste: false,
1241
- sequence: textWithMixed,
1242
- }),
1243
- );
1244
- expect(getBufferState(result).text).toBe('Hello');
1245
- });
1246
-
1247
- it('should not strip standard characters or newlines', () => {
1248
- const { result } = renderHook(() =>
1249
- useTextBuffer({ viewport, isValidPath: () => false }),
1250
- );
1251
- const validText = 'Hello World\nThis is a test.';
1252
- act(() =>
1253
- result.current.handleInput({
1254
- name: '',
1255
- ctrl: false,
1256
- meta: false,
1257
- shift: false,
1258
- paste: false,
1259
- sequence: validText,
1260
- }),
1261
- );
1262
- expect(getBufferState(result).text).toBe(validText);
1263
- });
1264
-
1265
- it('should sanitize pasted text via handleInput', () => {
1266
- const { result } = renderHook(() =>
1267
- useTextBuffer({ viewport, isValidPath: () => false }),
1268
- );
1269
- const pastedText = '\u001B[4mPasted\u001B[4m Text';
1270
- act(() =>
1271
- result.current.handleInput({
1272
- name: '',
1273
- ctrl: false,
1274
- meta: false,
1275
- shift: false,
1276
- paste: false,
1277
- sequence: pastedText,
1278
- }),
1279
- );
1280
- expect(getBufferState(result).text).toBe('Pasted Text');
1281
- });
1282
-
1283
- it('should not strip popular emojis', () => {
1284
- const { result } = renderHook(() =>
1285
- useTextBuffer({ viewport, isValidPath: () => false }),
1286
- );
1287
- const emojis = '🐍🐳🦀🦄';
1288
- act(() =>
1289
- result.current.handleInput({
1290
- name: '',
1291
- ctrl: false,
1292
- meta: false,
1293
- shift: false,
1294
- paste: false,
1295
- sequence: emojis,
1296
- }),
1297
- );
1298
- expect(getBufferState(result).text).toBe(emojis);
1299
- });
1300
- });
1301
-
1302
- describe('stripAnsi', () => {
1303
- it('should correctly strip ANSI escape codes', () => {
1304
- const textWithAnsi = '\x1B[31mHello\x1B[0m World';
1305
- expect(stripAnsi(textWithAnsi)).toBe('Hello World');
1306
- });
1307
-
1308
- it('should handle multiple ANSI codes', () => {
1309
- const textWithMultipleAnsi = '\x1B[1m\x1B[34mBold Blue\x1B[0m Text';
1310
- expect(stripAnsi(textWithMultipleAnsi)).toBe('Bold Blue Text');
1311
- });
1312
-
1313
- it('should not modify text without ANSI codes', () => {
1314
- const plainText = 'Plain text';
1315
- expect(stripAnsi(plainText)).toBe('Plain text');
1316
- });
1317
-
1318
- it('should handle empty string', () => {
1319
- expect(stripAnsi('')).toBe('');
1320
- });
1321
- });
1322
- });
1323
-
1324
- describe('offsetToLogicalPos', () => {
1325
- it('should return [0,0] for offset 0', () => {
1326
- expect(offsetToLogicalPos('any text', 0)).toEqual([0, 0]);
1327
- });
1328
-
1329
- it('should handle single line text', () => {
1330
- const text = 'hello';
1331
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]); // Start
1332
- expect(offsetToLogicalPos(text, 2)).toEqual([0, 2]); // Middle 'l'
1333
- expect(offsetToLogicalPos(text, 5)).toEqual([0, 5]); // End
1334
- expect(offsetToLogicalPos(text, 10)).toEqual([0, 5]); // Beyond end
1335
- });
1336
-
1337
- it('should handle multi-line text', () => {
1338
- const text = 'hello\nworld\n123';
1339
- // "hello" (5) + \n (1) + "world" (5) + \n (1) + "123" (3)
1340
- // h e l l o \n w o r l d \n 1 2 3
1341
- // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
1342
- // Line 0: "hello" (length 5)
1343
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]); // Start of 'hello'
1344
- expect(offsetToLogicalPos(text, 3)).toEqual([0, 3]); // 'l' in 'hello'
1345
- expect(offsetToLogicalPos(text, 5)).toEqual([0, 5]); // End of 'hello' (before \n)
1346
-
1347
- // Line 1: "world" (length 5)
1348
- expect(offsetToLogicalPos(text, 6)).toEqual([1, 0]); // Start of 'world' (after \n)
1349
- expect(offsetToLogicalPos(text, 8)).toEqual([1, 2]); // 'r' in 'world'
1350
- expect(offsetToLogicalPos(text, 11)).toEqual([1, 5]); // End of 'world' (before \n)
1351
-
1352
- // Line 2: "123" (length 3)
1353
- expect(offsetToLogicalPos(text, 12)).toEqual([2, 0]); // Start of '123' (after \n)
1354
- expect(offsetToLogicalPos(text, 13)).toEqual([2, 1]); // '2' in '123'
1355
- expect(offsetToLogicalPos(text, 15)).toEqual([2, 3]); // End of '123'
1356
- expect(offsetToLogicalPos(text, 20)).toEqual([2, 3]); // Beyond end of text
1357
- });
1358
-
1359
- it('should handle empty lines', () => {
1360
- const text = 'a\n\nc'; // "a" (1) + \n (1) + "" (0) + \n (1) + "c" (1)
1361
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]); // 'a'
1362
- expect(offsetToLogicalPos(text, 1)).toEqual([0, 1]); // End of 'a'
1363
- expect(offsetToLogicalPos(text, 2)).toEqual([1, 0]); // Start of empty line
1364
- expect(offsetToLogicalPos(text, 3)).toEqual([2, 0]); // Start of 'c'
1365
- expect(offsetToLogicalPos(text, 4)).toEqual([2, 1]); // End of 'c'
1366
- });
1367
-
1368
- it('should handle text ending with a newline', () => {
1369
- const text = 'hello\n'; // "hello" (5) + \n (1)
1370
- expect(offsetToLogicalPos(text, 5)).toEqual([0, 5]); // End of 'hello'
1371
- expect(offsetToLogicalPos(text, 6)).toEqual([1, 0]); // Position on the new empty line after
1372
-
1373
- expect(offsetToLogicalPos(text, 7)).toEqual([1, 0]); // Still on the new empty line
1374
- });
1375
-
1376
- it('should handle text starting with a newline', () => {
1377
- const text = '\nhello'; // "" (0) + \n (1) + "hello" (5)
1378
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]); // Start of first empty line
1379
- expect(offsetToLogicalPos(text, 1)).toEqual([1, 0]); // Start of 'hello'
1380
- expect(offsetToLogicalPos(text, 3)).toEqual([1, 2]); // 'l' in 'hello'
1381
- });
1382
-
1383
- it('should handle empty string input', () => {
1384
- expect(offsetToLogicalPos('', 0)).toEqual([0, 0]);
1385
- expect(offsetToLogicalPos('', 5)).toEqual([0, 0]);
1386
- });
1387
-
1388
- it('should handle multi-byte unicode characters correctly', () => {
1389
- const text = '你好\n世界'; // "你好" (2 chars) + \n (1) + "世界" (2 chars)
1390
- // Total "code points" for offset calculation: 2 + 1 + 2 = 5
1391
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]); // Start of '你好'
1392
- expect(offsetToLogicalPos(text, 1)).toEqual([0, 1]); // After '你', before '好'
1393
- expect(offsetToLogicalPos(text, 2)).toEqual([0, 2]); // End of '你好'
1394
- expect(offsetToLogicalPos(text, 3)).toEqual([1, 0]); // Start of '世界'
1395
- expect(offsetToLogicalPos(text, 4)).toEqual([1, 1]); // After '世', before '界'
1396
- expect(offsetToLogicalPos(text, 5)).toEqual([1, 2]); // End of '世界'
1397
- expect(offsetToLogicalPos(text, 6)).toEqual([1, 2]); // Beyond end
1398
- });
1399
-
1400
- it('should handle offset exactly at newline character', () => {
1401
- const text = 'abc\ndef';
1402
- // a b c \n d e f
1403
- // 0 1 2 3 4 5 6
1404
- expect(offsetToLogicalPos(text, 3)).toEqual([0, 3]); // End of 'abc'
1405
- // The next character is the newline, so an offset of 4 means the start of the next line.
1406
- expect(offsetToLogicalPos(text, 4)).toEqual([1, 0]); // Start of 'def'
1407
- });
1408
-
1409
- it('should handle offset in the middle of a multi-byte character (should place at start of that char)', () => {
1410
- // This scenario is tricky as "offset" is usually character-based.
1411
- // Assuming cpLen and related logic handles this by treating multi-byte as one unit.
1412
- // The current implementation of offsetToLogicalPos uses cpLen, so it should be code-point aware.
1413
- const text = '🐶🐱'; // 2 code points
1414
- expect(offsetToLogicalPos(text, 0)).toEqual([0, 0]);
1415
- expect(offsetToLogicalPos(text, 1)).toEqual([0, 1]); // After 🐶
1416
- expect(offsetToLogicalPos(text, 2)).toEqual([0, 2]); // After 🐱
1417
- });
1418
- });
1419
-
1420
- describe('logicalPosToOffset', () => {
1421
- it('should convert row/col position to offset correctly', () => {
1422
- const lines = ['hello', 'world', '123'];
1423
-
1424
- // Line 0: "hello" (5 chars)
1425
- expect(logicalPosToOffset(lines, 0, 0)).toBe(0); // Start of 'hello'
1426
- expect(logicalPosToOffset(lines, 0, 3)).toBe(3); // 'l' in 'hello'
1427
- expect(logicalPosToOffset(lines, 0, 5)).toBe(5); // End of 'hello'
1428
-
1429
- // Line 1: "world" (5 chars), offset starts at 6 (5 + 1 for newline)
1430
- expect(logicalPosToOffset(lines, 1, 0)).toBe(6); // Start of 'world'
1431
- expect(logicalPosToOffset(lines, 1, 2)).toBe(8); // 'r' in 'world'
1432
- expect(logicalPosToOffset(lines, 1, 5)).toBe(11); // End of 'world'
1433
-
1434
- // Line 2: "123" (3 chars), offset starts at 12 (5 + 1 + 5 + 1)
1435
- expect(logicalPosToOffset(lines, 2, 0)).toBe(12); // Start of '123'
1436
- expect(logicalPosToOffset(lines, 2, 1)).toBe(13); // '2' in '123'
1437
- expect(logicalPosToOffset(lines, 2, 3)).toBe(15); // End of '123'
1438
- });
1439
-
1440
- it('should handle empty lines', () => {
1441
- const lines = ['a', '', 'c'];
1442
-
1443
- expect(logicalPosToOffset(lines, 0, 0)).toBe(0); // 'a'
1444
- expect(logicalPosToOffset(lines, 0, 1)).toBe(1); // End of 'a'
1445
- expect(logicalPosToOffset(lines, 1, 0)).toBe(2); // Empty line
1446
- expect(logicalPosToOffset(lines, 2, 0)).toBe(3); // 'c'
1447
- expect(logicalPosToOffset(lines, 2, 1)).toBe(4); // End of 'c'
1448
- });
1449
-
1450
- it('should handle single empty line', () => {
1451
- const lines = [''];
1452
-
1453
- expect(logicalPosToOffset(lines, 0, 0)).toBe(0);
1454
- });
1455
-
1456
- it('should be inverse of offsetToLogicalPos', () => {
1457
- const lines = ['hello', 'world', '123'];
1458
- const text = lines.join('\n');
1459
-
1460
- // Test round-trip conversion
1461
- for (let offset = 0; offset <= text.length; offset++) {
1462
- const [row, col] = offsetToLogicalPos(text, offset);
1463
- const convertedOffset = logicalPosToOffset(lines, row, col);
1464
- expect(convertedOffset).toBe(offset);
1465
- }
1466
- });
1467
-
1468
- it('should handle out-of-bounds positions', () => {
1469
- const lines = ['hello'];
1470
-
1471
- // Beyond end of line
1472
- expect(logicalPosToOffset(lines, 0, 10)).toBe(5); // Clamps to end of line
1473
-
1474
- // Beyond array bounds - should clamp to the last line
1475
- expect(logicalPosToOffset(lines, 5, 0)).toBe(0); // Clamps to start of last line (row 0)
1476
- expect(logicalPosToOffset(lines, 5, 10)).toBe(5); // Clamps to end of last line
1477
- });
1478
- });
1479
-
1480
- describe('textBufferReducer vim operations', () => {
1481
- describe('vim_delete_line', () => {
1482
- it('should delete a single line including newline in multi-line text', () => {
1483
- const initialState: TextBufferState = {
1484
- lines: ['line1', 'line2', 'line3'],
1485
- cursorRow: 1,
1486
- cursorCol: 2,
1487
- preferredCol: null,
1488
- visualLines: [['line1'], ['line2'], ['line3']],
1489
- visualScrollRow: 0,
1490
- visualCursor: { row: 1, col: 2 },
1491
- viewport: { width: 10, height: 5 },
1492
- undoStack: [],
1493
- redoStack: [],
1494
- };
1495
-
1496
- const action: TextBufferAction = {
1497
- type: 'vim_delete_line',
1498
- payload: { count: 1 },
1499
- };
1500
-
1501
- const result = textBufferReducer(initialState, action);
1502
- expect(result).toHaveOnlyValidCharacters();
1503
-
1504
- // After deleting line2, we should have line1 and line3, with cursor on line3 (now at index 1)
1505
- expect(result.lines).toEqual(['line1', 'line3']);
1506
- expect(result.cursorRow).toBe(1);
1507
- expect(result.cursorCol).toBe(0);
1508
- });
1509
-
1510
- it('should delete multiple lines when count > 1', () => {
1511
- const initialState: TextBufferState = {
1512
- lines: ['line1', 'line2', 'line3', 'line4'],
1513
- cursorRow: 1,
1514
- cursorCol: 0,
1515
- preferredCol: null,
1516
- visualLines: [['line1'], ['line2'], ['line3'], ['line4']],
1517
- visualScrollRow: 0,
1518
- visualCursor: { row: 1, col: 0 },
1519
- viewport: { width: 10, height: 5 },
1520
- undoStack: [],
1521
- redoStack: [],
1522
- };
1523
-
1524
- const action: TextBufferAction = {
1525
- type: 'vim_delete_line',
1526
- payload: { count: 2 },
1527
- };
1528
-
1529
- const result = textBufferReducer(initialState, action);
1530
- expect(result).toHaveOnlyValidCharacters();
1531
-
1532
- // Should delete line2 and line3, leaving line1 and line4
1533
- expect(result.lines).toEqual(['line1', 'line4']);
1534
- expect(result.cursorRow).toBe(1);
1535
- expect(result.cursorCol).toBe(0);
1536
- });
1537
-
1538
- it('should clear single line content when only one line exists', () => {
1539
- const initialState: TextBufferState = {
1540
- lines: ['only line'],
1541
- cursorRow: 0,
1542
- cursorCol: 5,
1543
- preferredCol: null,
1544
- visualLines: [['only line']],
1545
- visualScrollRow: 0,
1546
- visualCursor: { row: 0, col: 5 },
1547
- viewport: { width: 10, height: 5 },
1548
- undoStack: [],
1549
- redoStack: [],
1550
- };
1551
-
1552
- const action: TextBufferAction = {
1553
- type: 'vim_delete_line',
1554
- payload: { count: 1 },
1555
- };
1556
-
1557
- const result = textBufferReducer(initialState, action);
1558
- expect(result).toHaveOnlyValidCharacters();
1559
-
1560
- // Should clear the line content but keep the line
1561
- expect(result.lines).toEqual(['']);
1562
- expect(result.cursorRow).toBe(0);
1563
- expect(result.cursorCol).toBe(0);
1564
- });
1565
-
1566
- it('should handle deleting the last line properly', () => {
1567
- const initialState: TextBufferState = {
1568
- lines: ['line1', 'line2'],
1569
- cursorRow: 1,
1570
- cursorCol: 0,
1571
- preferredCol: null,
1572
- visualLines: [['line1'], ['line2']],
1573
- visualScrollRow: 0,
1574
- visualCursor: { row: 1, col: 0 },
1575
- viewport: { width: 10, height: 5 },
1576
- undoStack: [],
1577
- redoStack: [],
1578
- };
1579
-
1580
- const action: TextBufferAction = {
1581
- type: 'vim_delete_line',
1582
- payload: { count: 1 },
1583
- };
1584
-
1585
- const result = textBufferReducer(initialState, action);
1586
- expect(result).toHaveOnlyValidCharacters();
1587
-
1588
- // Should delete the last line completely, not leave empty line
1589
- expect(result.lines).toEqual(['line1']);
1590
- expect(result.cursorRow).toBe(0);
1591
- expect(result.cursorCol).toBe(0);
1592
- });
1593
-
1594
- it('should handle deleting all lines and maintain valid state for subsequent paste', () => {
1595
- const initialState: TextBufferState = {
1596
- lines: ['line1', 'line2', 'line3', 'line4'],
1597
- cursorRow: 0,
1598
- cursorCol: 0,
1599
- preferredCol: null,
1600
- visualLines: [['line1'], ['line2'], ['line3'], ['line4']],
1601
- visualScrollRow: 0,
1602
- visualCursor: { row: 0, col: 0 },
1603
- viewport: { width: 10, height: 5 },
1604
- undoStack: [],
1605
- redoStack: [],
1606
- };
1607
-
1608
- // Delete all 4 lines with 4dd
1609
- const deleteAction: TextBufferAction = {
1610
- type: 'vim_delete_line',
1611
- payload: { count: 4 },
1612
- };
1613
-
1614
- const afterDelete = textBufferReducer(initialState, deleteAction);
1615
- expect(afterDelete).toHaveOnlyValidCharacters();
1616
-
1617
- // After deleting all lines, should have one empty line
1618
- expect(afterDelete.lines).toEqual(['']);
1619
- expect(afterDelete.cursorRow).toBe(0);
1620
- expect(afterDelete.cursorCol).toBe(0);
1621
-
1622
- // Now paste multiline content - this should work correctly
1623
- const pasteAction: TextBufferAction = {
1624
- type: 'insert',
1625
- payload: 'new1\nnew2\nnew3\nnew4',
1626
- };
1627
-
1628
- const afterPaste = textBufferReducer(afterDelete, pasteAction);
1629
- expect(afterPaste).toHaveOnlyValidCharacters();
1630
-
1631
- // All lines including the first one should be present
1632
- expect(afterPaste.lines).toEqual(['new1', 'new2', 'new3', 'new4']);
1633
- expect(afterPaste.cursorRow).toBe(3);
1634
- expect(afterPaste.cursorCol).toBe(4);
1635
- });
1636
- });
1637
- });
1638
-
1639
- describe('Unicode helper functions', () => {
1640
- describe('findWordEndInLine with Unicode', () => {
1641
- it('should handle combining characters', () => {
1642
- // café with combining accent
1643
- const cafeWithCombining = 'cafe\u0301';
1644
- const result = findWordEndInLine(cafeWithCombining + ' test', 0);
1645
- expect(result).toBe(3); // End of 'café' at base character 'e', not combining accent
1646
- });
1647
-
1648
- it('should handle precomposed characters with diacritics', () => {
1649
- // café with precomposed é (U+00E9)
1650
- const cafePrecomposed = 'café';
1651
- const result = findWordEndInLine(cafePrecomposed + ' test', 0);
1652
- expect(result).toBe(3); // End of 'café' at precomposed character 'é'
1653
- });
1654
-
1655
- it('should return null when no word end found', () => {
1656
- const result = findWordEndInLine(' ', 0);
1657
- expect(result).toBeNull(); // No word end found in whitespace-only string string
1658
- });
1659
- });
1660
-
1661
- describe('findNextWordStartInLine with Unicode', () => {
1662
- it('should handle right-to-left text', () => {
1663
- const result = findNextWordStartInLine('hello مرحبا world', 0);
1664
- expect(result).toBe(6); // Start of Arabic word
1665
- });
1666
-
1667
- it('should handle Chinese characters', () => {
1668
- const result = findNextWordStartInLine('hello 你好 world', 0);
1669
- expect(result).toBe(6); // Start of Chinese word
1670
- });
1671
-
1672
- it('should return null at end of line', () => {
1673
- const result = findNextWordStartInLine('hello', 10);
1674
- expect(result).toBeNull();
1675
- });
1676
-
1677
- it('should handle combining characters', () => {
1678
- // café with combining accent + next word
1679
- const textWithCombining = 'cafe\u0301 test';
1680
- const result = findNextWordStartInLine(textWithCombining, 0);
1681
- expect(result).toBe(6); // Start of 'test' after 'café ' (combining char makes string longer)
1682
- });
1683
-
1684
- it('should handle precomposed characters with diacritics', () => {
1685
- // café with precomposed é + next word
1686
- const textPrecomposed = 'café test';
1687
- const result = findNextWordStartInLine(textPrecomposed, 0);
1688
- expect(result).toBe(5); // Start of 'test' after 'café '
1689
- });
1690
- });
1691
-
1692
- describe('isWordCharStrict with Unicode', () => {
1693
- it('should return true for ASCII word characters', () => {
1694
- expect(isWordCharStrict('a')).toBe(true);
1695
- expect(isWordCharStrict('Z')).toBe(true);
1696
- expect(isWordCharStrict('0')).toBe(true);
1697
- expect(isWordCharStrict('_')).toBe(true);
1698
- });
1699
-
1700
- it('should return false for punctuation', () => {
1701
- expect(isWordCharStrict('.')).toBe(false);
1702
- expect(isWordCharStrict(',')).toBe(false);
1703
- expect(isWordCharStrict('!')).toBe(false);
1704
- });
1705
-
1706
- it('should return true for non-Latin scripts', () => {
1707
- expect(isWordCharStrict('你')).toBe(true); // Chinese character
1708
- expect(isWordCharStrict('م')).toBe(true); // Arabic character
1709
- });
1710
-
1711
- it('should return false for whitespace', () => {
1712
- expect(isWordCharStrict(' ')).toBe(false);
1713
- expect(isWordCharStrict('\t')).toBe(false);
1714
- });
1715
- });
1716
-
1717
- describe('cpLen with Unicode', () => {
1718
- it('should handle combining characters', () => {
1719
- expect(cpLen('é')).toBe(1); // Precomposed
1720
- expect(cpLen('e\u0301')).toBe(2); // e + combining acute
1721
- });
1722
-
1723
- it('should handle Chinese and Arabic text', () => {
1724
- expect(cpLen('hello 你好 world')).toBe(14); // 5 + 1 + 2 + 1 + 5 = 14
1725
- expect(cpLen('hello مرحبا world')).toBe(17);
1726
- });
1727
- });
1728
- });