@dexto/tui 1.6.2
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.
- package/LICENSE +44 -0
- package/dist/InkCLIRefactored.cjs +319 -0
- package/dist/InkCLIRefactored.d.ts +55 -0
- package/dist/InkCLIRefactored.d.ts.map +1 -0
- package/dist/InkCLIRefactored.js +289 -0
- package/dist/assets/sounds/SOURCES.md +35 -0
- package/dist/assets/sounds/boot.wav +0 -0
- package/dist/assets/sounds/chime.wav +0 -0
- package/dist/assets/sounds/coin.wav +0 -0
- package/dist/assets/sounds/confirm.wav +0 -0
- package/dist/assets/sounds/levelup.wav +0 -0
- package/dist/assets/sounds/ping.wav +0 -0
- package/dist/assets/sounds/powerup.wav +0 -0
- package/dist/assets/sounds/startup.wav +0 -0
- package/dist/assets/sounds/success.wav +0 -0
- package/dist/assets/sounds/treasure.wav +0 -0
- package/dist/assets/sounds/win.wav +0 -0
- package/dist/components/ApprovalPrompt.cjs +353 -0
- package/dist/components/ApprovalPrompt.d.ts +44 -0
- package/dist/components/ApprovalPrompt.d.ts.map +1 -0
- package/dist/components/ApprovalPrompt.js +336 -0
- package/dist/components/BackgroundTasksPanel.cjs +117 -0
- package/dist/components/BackgroundTasksPanel.d.ts +18 -0
- package/dist/components/BackgroundTasksPanel.d.ts.map +1 -0
- package/dist/components/BackgroundTasksPanel.js +93 -0
- package/dist/components/CustomInput.cjs +77 -0
- package/dist/components/CustomInput.d.ts +17 -0
- package/dist/components/CustomInput.d.ts.map +1 -0
- package/dist/components/CustomInput.js +57 -0
- package/dist/components/CustomTextInput.cjs +76 -0
- package/dist/components/CustomTextInput.d.ts +16 -0
- package/dist/components/CustomTextInput.d.ts.map +1 -0
- package/dist/components/CustomTextInput.js +46 -0
- package/dist/components/EditableMultiLineInput.cjs +151 -0
- package/dist/components/EditableMultiLineInput.d.ts +19 -0
- package/dist/components/EditableMultiLineInput.d.ts.map +1 -0
- package/dist/components/EditableMultiLineInput.js +131 -0
- package/dist/components/ElicitationForm.cjs +622 -0
- package/dist/components/ElicitationForm.d.ts +24 -0
- package/dist/components/ElicitationForm.d.ts.map +1 -0
- package/dist/components/ElicitationForm.js +588 -0
- package/dist/components/ErrorBoundary.cjs +66 -0
- package/dist/components/ErrorBoundary.d.ts +20 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +32 -0
- package/dist/components/Footer.cjs +165 -0
- package/dist/components/Footer.d.ts +23 -0
- package/dist/components/Footer.d.ts.map +1 -0
- package/dist/components/Footer.js +131 -0
- package/dist/components/HistorySearchBar.cjs +40 -0
- package/dist/components/HistorySearchBar.d.ts +17 -0
- package/dist/components/HistorySearchBar.d.ts.map +1 -0
- package/dist/components/HistorySearchBar.js +16 -0
- package/dist/components/MultiLineInput.cjs +56 -0
- package/dist/components/MultiLineInput.d.ts +12 -0
- package/dist/components/MultiLineInput.d.ts.map +1 -0
- package/dist/components/MultiLineInput.js +36 -0
- package/dist/components/ResourceAutocomplete.cjs +344 -0
- package/dist/components/ResourceAutocomplete.d.ts +26 -0
- package/dist/components/ResourceAutocomplete.d.ts.map +1 -0
- package/dist/components/ResourceAutocomplete.js +322 -0
- package/dist/components/SlashCommandAutocomplete.cjs +389 -0
- package/dist/components/SlashCommandAutocomplete.d.ts +28 -0
- package/dist/components/SlashCommandAutocomplete.d.ts.map +1 -0
- package/dist/components/SlashCommandAutocomplete.js +363 -0
- package/dist/components/StatusBar.cjs +142 -0
- package/dist/components/StatusBar.d.ts +41 -0
- package/dist/components/StatusBar.d.ts.map +1 -0
- package/dist/components/StatusBar.js +118 -0
- package/dist/components/TextBufferInput.cjs +531 -0
- package/dist/components/TextBufferInput.d.ts +54 -0
- package/dist/components/TextBufferInput.d.ts.map +1 -0
- package/dist/components/TextBufferInput.js +507 -0
- package/dist/components/TodoPanel.cjs +129 -0
- package/dist/components/TodoPanel.d.ts +26 -0
- package/dist/components/TodoPanel.d.ts.map +1 -0
- package/dist/components/TodoPanel.js +105 -0
- package/dist/components/base/BaseAutocomplete.cjs +153 -0
- package/dist/components/base/BaseAutocomplete.d.ts +29 -0
- package/dist/components/base/BaseAutocomplete.d.ts.map +1 -0
- package/dist/components/base/BaseAutocomplete.js +129 -0
- package/dist/components/base/BaseSelector.cjs +167 -0
- package/dist/components/base/BaseSelector.d.ts +37 -0
- package/dist/components/base/BaseSelector.d.ts.map +1 -0
- package/dist/components/base/BaseSelector.js +151 -0
- package/dist/components/base/index.cjs +31 -0
- package/dist/components/base/index.d.ts +6 -0
- package/dist/components/base/index.d.ts.map +1 -0
- package/dist/components/base/index.js +6 -0
- package/dist/components/chat/ChatView.cjs +51 -0
- package/dist/components/chat/ChatView.d.ts +19 -0
- package/dist/components/chat/ChatView.d.ts.map +1 -0
- package/dist/components/chat/ChatView.js +27 -0
- package/dist/components/chat/Footer.cjs +32 -0
- package/dist/components/chat/Footer.d.ts +9 -0
- package/dist/components/chat/Footer.d.ts.map +1 -0
- package/dist/components/chat/Footer.js +8 -0
- package/dist/components/chat/Header.cjs +86 -0
- package/dist/components/chat/Header.d.ts +18 -0
- package/dist/components/chat/Header.d.ts.map +1 -0
- package/dist/components/chat/Header.js +62 -0
- package/dist/components/chat/MessageItem.cjs +269 -0
- package/dist/components/chat/MessageItem.d.ts +23 -0
- package/dist/components/chat/MessageItem.d.ts.map +1 -0
- package/dist/components/chat/MessageItem.js +247 -0
- package/dist/components/chat/MessageList.cjs +46 -0
- package/dist/components/chat/MessageList.d.ts +16 -0
- package/dist/components/chat/MessageList.d.ts.map +1 -0
- package/dist/components/chat/MessageList.js +22 -0
- package/dist/components/chat/QueuedMessagesDisplay.cjs +59 -0
- package/dist/components/chat/QueuedMessagesDisplay.d.ts +16 -0
- package/dist/components/chat/QueuedMessagesDisplay.d.ts.map +1 -0
- package/dist/components/chat/QueuedMessagesDisplay.js +35 -0
- package/dist/components/chat/ToolIcon.cjs +60 -0
- package/dist/components/chat/ToolIcon.d.ts +18 -0
- package/dist/components/chat/ToolIcon.d.ts.map +1 -0
- package/dist/components/chat/ToolIcon.js +36 -0
- package/dist/components/chat/index.cjs +43 -0
- package/dist/components/chat/index.d.ts +10 -0
- package/dist/components/chat/index.d.ts.map +1 -0
- package/dist/components/chat/index.js +14 -0
- package/dist/components/chat/styled-boxes/ConfigBox.cjs +56 -0
- package/dist/components/chat/styled-boxes/ConfigBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/ConfigBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/ConfigBox.js +32 -0
- package/dist/components/chat/styled-boxes/HelpBox.cjs +53 -0
- package/dist/components/chat/styled-boxes/HelpBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/HelpBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/HelpBox.js +29 -0
- package/dist/components/chat/styled-boxes/LogConfigBox.cjs +54 -0
- package/dist/components/chat/styled-boxes/LogConfigBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/LogConfigBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/LogConfigBox.js +30 -0
- package/dist/components/chat/styled-boxes/SessionHistoryBox.cjs +81 -0
- package/dist/components/chat/styled-boxes/SessionHistoryBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/SessionHistoryBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/SessionHistoryBox.js +57 -0
- package/dist/components/chat/styled-boxes/SessionListBox.cjs +58 -0
- package/dist/components/chat/styled-boxes/SessionListBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/SessionListBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/SessionListBox.js +34 -0
- package/dist/components/chat/styled-boxes/ShortcutsBox.cjs +39 -0
- package/dist/components/chat/styled-boxes/ShortcutsBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/ShortcutsBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/ShortcutsBox.js +15 -0
- package/dist/components/chat/styled-boxes/StatsBox.cjs +123 -0
- package/dist/components/chat/styled-boxes/StatsBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/StatsBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/StatsBox.js +99 -0
- package/dist/components/chat/styled-boxes/StyledBox.cjs +88 -0
- package/dist/components/chat/styled-boxes/StyledBox.d.ts +45 -0
- package/dist/components/chat/styled-boxes/StyledBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/StyledBox.js +61 -0
- package/dist/components/chat/styled-boxes/SyspromptBox.cjs +33 -0
- package/dist/components/chat/styled-boxes/SyspromptBox.d.ts +10 -0
- package/dist/components/chat/styled-boxes/SyspromptBox.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/SyspromptBox.js +9 -0
- package/dist/components/chat/styled-boxes/index.cjs +58 -0
- package/dist/components/chat/styled-boxes/index.d.ts +13 -0
- package/dist/components/chat/styled-boxes/index.d.ts.map +1 -0
- package/dist/components/chat/styled-boxes/index.js +23 -0
- package/dist/components/input/InputArea.cjs +74 -0
- package/dist/components/input/InputArea.d.ts +48 -0
- package/dist/components/input/InputArea.d.ts.map +1 -0
- package/dist/components/input/InputArea.js +50 -0
- package/dist/components/input/index.cjs +28 -0
- package/dist/components/input/index.d.ts +5 -0
- package/dist/components/input/index.d.ts.map +1 -0
- package/dist/components/input/index.js +4 -0
- package/dist/components/modes/AlternateBufferCLI.cjs +360 -0
- package/dist/components/modes/AlternateBufferCLI.d.ts +28 -0
- package/dist/components/modes/AlternateBufferCLI.d.ts.map +1 -0
- package/dist/components/modes/AlternateBufferCLI.js +339 -0
- package/dist/components/modes/StaticCLI.cjs +303 -0
- package/dist/components/modes/StaticCLI.d.ts +30 -0
- package/dist/components/modes/StaticCLI.d.ts.map +1 -0
- package/dist/components/modes/StaticCLI.js +279 -0
- package/dist/components/modes/index.cjs +31 -0
- package/dist/components/modes/index.d.ts +10 -0
- package/dist/components/modes/index.d.ts.map +1 -0
- package/dist/components/modes/index.js +6 -0
- package/dist/components/overlays/ApiKeyInput.cjs +131 -0
- package/dist/components/overlays/ApiKeyInput.d.ts +26 -0
- package/dist/components/overlays/ApiKeyInput.d.ts.map +1 -0
- package/dist/components/overlays/ApiKeyInput.js +115 -0
- package/dist/components/overlays/CommandOutputOverlay.cjs +103 -0
- package/dist/components/overlays/CommandOutputOverlay.d.ts +13 -0
- package/dist/components/overlays/CommandOutputOverlay.d.ts.map +1 -0
- package/dist/components/overlays/CommandOutputOverlay.js +69 -0
- package/dist/components/overlays/ContextStatsOverlay.cjs +354 -0
- package/dist/components/overlays/ContextStatsOverlay.d.ts +26 -0
- package/dist/components/overlays/ContextStatsOverlay.d.ts.map +1 -0
- package/dist/components/overlays/ContextStatsOverlay.js +334 -0
- package/dist/components/overlays/CustomModelWizard.cjs +362 -0
- package/dist/components/overlays/CustomModelWizard.d.ts +29 -0
- package/dist/components/overlays/CustomModelWizard.d.ts.map +1 -0
- package/dist/components/overlays/CustomModelWizard.js +356 -0
- package/dist/components/overlays/ExportWizard.cjs +382 -0
- package/dist/components/overlays/ExportWizard.d.ts +22 -0
- package/dist/components/overlays/ExportWizard.d.ts.map +1 -0
- package/dist/components/overlays/ExportWizard.js +352 -0
- package/dist/components/overlays/LogLevelSelector.cjs +120 -0
- package/dist/components/overlays/LogLevelSelector.d.ts +23 -0
- package/dist/components/overlays/LogLevelSelector.d.ts.map +1 -0
- package/dist/components/overlays/LogLevelSelector.js +100 -0
- package/dist/components/overlays/LoginOverlay.cjs +211 -0
- package/dist/components/overlays/LoginOverlay.d.ts +22 -0
- package/dist/components/overlays/LoginOverlay.d.ts.map +1 -0
- package/dist/components/overlays/LoginOverlay.js +194 -0
- package/dist/components/overlays/LogoutOverlay.cjs +138 -0
- package/dist/components/overlays/LogoutOverlay.d.ts +20 -0
- package/dist/components/overlays/LogoutOverlay.d.ts.map +1 -0
- package/dist/components/overlays/LogoutOverlay.js +130 -0
- package/dist/components/overlays/MarketplaceAddPrompt.cjs +119 -0
- package/dist/components/overlays/MarketplaceAddPrompt.d.ts +20 -0
- package/dist/components/overlays/MarketplaceAddPrompt.d.ts.map +1 -0
- package/dist/components/overlays/MarketplaceAddPrompt.js +99 -0
- package/dist/components/overlays/MarketplaceBrowser.cjs +364 -0
- package/dist/components/overlays/MarketplaceBrowser.d.ts +31 -0
- package/dist/components/overlays/MarketplaceBrowser.d.ts.map +1 -0
- package/dist/components/overlays/MarketplaceBrowser.js +358 -0
- package/dist/components/overlays/McpAddChoice.cjs +100 -0
- package/dist/components/overlays/McpAddChoice.d.ts +22 -0
- package/dist/components/overlays/McpAddChoice.d.ts.map +1 -0
- package/dist/components/overlays/McpAddChoice.js +80 -0
- package/dist/components/overlays/McpAddSelector.cjs +113 -0
- package/dist/components/overlays/McpAddSelector.d.ts +26 -0
- package/dist/components/overlays/McpAddSelector.d.ts.map +1 -0
- package/dist/components/overlays/McpAddSelector.js +93 -0
- package/dist/components/overlays/McpCustomTypeSelector.cjs +99 -0
- package/dist/components/overlays/McpCustomTypeSelector.d.ts +21 -0
- package/dist/components/overlays/McpCustomTypeSelector.d.ts.map +1 -0
- package/dist/components/overlays/McpCustomTypeSelector.js +79 -0
- package/dist/components/overlays/McpCustomWizard.cjs +258 -0
- package/dist/components/overlays/McpCustomWizard.d.ts +29 -0
- package/dist/components/overlays/McpCustomWizard.d.ts.map +1 -0
- package/dist/components/overlays/McpCustomWizard.js +238 -0
- package/dist/components/overlays/McpRemoveSelector.cjs +127 -0
- package/dist/components/overlays/McpRemoveSelector.d.ts +22 -0
- package/dist/components/overlays/McpRemoveSelector.d.ts.map +1 -0
- package/dist/components/overlays/McpRemoveSelector.js +107 -0
- package/dist/components/overlays/McpSelector.cjs +94 -0
- package/dist/components/overlays/McpSelector.d.ts +21 -0
- package/dist/components/overlays/McpSelector.d.ts.map +1 -0
- package/dist/components/overlays/McpSelector.js +74 -0
- package/dist/components/overlays/McpServerActions.cjs +124 -0
- package/dist/components/overlays/McpServerActions.d.ts +28 -0
- package/dist/components/overlays/McpServerActions.d.ts.map +1 -0
- package/dist/components/overlays/McpServerActions.js +111 -0
- package/dist/components/overlays/McpServerList.cjs +152 -0
- package/dist/components/overlays/McpServerList.d.ts +29 -0
- package/dist/components/overlays/McpServerList.d.ts.map +1 -0
- package/dist/components/overlays/McpServerList.js +139 -0
- package/dist/components/overlays/ModelSelectorRefactored.cjs +869 -0
- package/dist/components/overlays/ModelSelectorRefactored.d.ts +27 -0
- package/dist/components/overlays/ModelSelectorRefactored.d.ts.map +1 -0
- package/dist/components/overlays/ModelSelectorRefactored.js +870 -0
- package/dist/components/overlays/PluginActions.cjs +108 -0
- package/dist/components/overlays/PluginActions.d.ts +27 -0
- package/dist/components/overlays/PluginActions.d.ts.map +1 -0
- package/dist/components/overlays/PluginActions.js +95 -0
- package/dist/components/overlays/PluginList.cjs +115 -0
- package/dist/components/overlays/PluginList.d.ts +21 -0
- package/dist/components/overlays/PluginList.d.ts.map +1 -0
- package/dist/components/overlays/PluginList.js +102 -0
- package/dist/components/overlays/PluginManager.cjs +106 -0
- package/dist/components/overlays/PluginManager.d.ts +21 -0
- package/dist/components/overlays/PluginManager.d.ts.map +1 -0
- package/dist/components/overlays/PluginManager.js +86 -0
- package/dist/components/overlays/PromptAddChoice.cjs +92 -0
- package/dist/components/overlays/PromptAddChoice.d.ts +22 -0
- package/dist/components/overlays/PromptAddChoice.d.ts.map +1 -0
- package/dist/components/overlays/PromptAddChoice.js +72 -0
- package/dist/components/overlays/PromptAddWizard.cjs +215 -0
- package/dist/components/overlays/PromptAddWizard.d.ts +29 -0
- package/dist/components/overlays/PromptAddWizard.d.ts.map +1 -0
- package/dist/components/overlays/PromptAddWizard.js +195 -0
- package/dist/components/overlays/PromptDeleteSelector.cjs +148 -0
- package/dist/components/overlays/PromptDeleteSelector.d.ts +27 -0
- package/dist/components/overlays/PromptDeleteSelector.d.ts.map +1 -0
- package/dist/components/overlays/PromptDeleteSelector.js +135 -0
- package/dist/components/overlays/PromptList.cjs +169 -0
- package/dist/components/overlays/PromptList.d.ts +33 -0
- package/dist/components/overlays/PromptList.d.ts.map +1 -0
- package/dist/components/overlays/PromptList.js +157 -0
- package/dist/components/overlays/ReasoningOverlay.cjs +305 -0
- package/dist/components/overlays/ReasoningOverlay.d.ts +28 -0
- package/dist/components/overlays/ReasoningOverlay.d.ts.map +1 -0
- package/dist/components/overlays/ReasoningOverlay.js +278 -0
- package/dist/components/overlays/SearchOverlay.cjs +249 -0
- package/dist/components/overlays/SearchOverlay.d.ts +23 -0
- package/dist/components/overlays/SearchOverlay.d.ts.map +1 -0
- package/dist/components/overlays/SearchOverlay.js +236 -0
- package/dist/components/overlays/SessionRenameOverlay.cjs +101 -0
- package/dist/components/overlays/SessionRenameOverlay.d.ts +21 -0
- package/dist/components/overlays/SessionRenameOverlay.d.ts.map +1 -0
- package/dist/components/overlays/SessionRenameOverlay.js +81 -0
- package/dist/components/overlays/SessionSelectorRefactored.cjs +153 -0
- package/dist/components/overlays/SessionSelectorRefactored.d.ts +26 -0
- package/dist/components/overlays/SessionSelectorRefactored.d.ts.map +1 -0
- package/dist/components/overlays/SessionSelectorRefactored.js +133 -0
- package/dist/components/overlays/SessionSubcommandSelector.cjs +84 -0
- package/dist/components/overlays/SessionSubcommandSelector.d.ts +21 -0
- package/dist/components/overlays/SessionSubcommandSelector.d.ts.map +1 -0
- package/dist/components/overlays/SessionSubcommandSelector.js +64 -0
- package/dist/components/overlays/SoundsSelector.cjs +632 -0
- package/dist/components/overlays/SoundsSelector.d.ts +21 -0
- package/dist/components/overlays/SoundsSelector.d.ts.map +1 -0
- package/dist/components/overlays/SoundsSelector.js +619 -0
- package/dist/components/overlays/StreamSelector.cjs +104 -0
- package/dist/components/overlays/StreamSelector.d.ts +20 -0
- package/dist/components/overlays/StreamSelector.d.ts.map +1 -0
- package/dist/components/overlays/StreamSelector.js +84 -0
- package/dist/components/overlays/ToolBrowser.cjs +854 -0
- package/dist/components/overlays/ToolBrowser.d.ts +26 -0
- package/dist/components/overlays/ToolBrowser.d.ts.map +1 -0
- package/dist/components/overlays/ToolBrowser.js +831 -0
- package/dist/components/overlays/custom-model-wizard/LocalModelWizard.cjs +784 -0
- package/dist/components/overlays/custom-model-wizard/LocalModelWizard.d.ts +25 -0
- package/dist/components/overlays/custom-model-wizard/LocalModelWizard.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/LocalModelWizard.js +768 -0
- package/dist/components/overlays/custom-model-wizard/index.cjs +26 -0
- package/dist/components/overlays/custom-model-wizard/index.d.ts +15 -0
- package/dist/components/overlays/custom-model-wizard/index.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/index.js +3 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.cjs +549 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.d.ts +42 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.js +516 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.test.cjs +31 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.test.d.ts +2 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.test.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/provider-config.test.js +30 -0
- package/dist/components/overlays/custom-model-wizard/shared/ApiKeyStep.cjs +59 -0
- package/dist/components/overlays/custom-model-wizard/shared/ApiKeyStep.d.ts +25 -0
- package/dist/components/overlays/custom-model-wizard/shared/ApiKeyStep.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/shared/ApiKeyStep.js +33 -0
- package/dist/components/overlays/custom-model-wizard/shared/ProviderSelector.cjs +64 -0
- package/dist/components/overlays/custom-model-wizard/shared/ProviderSelector.d.ts +17 -0
- package/dist/components/overlays/custom-model-wizard/shared/ProviderSelector.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/shared/ProviderSelector.js +40 -0
- package/dist/components/overlays/custom-model-wizard/shared/SetupInfoBanner.cjs +48 -0
- package/dist/components/overlays/custom-model-wizard/shared/SetupInfoBanner.d.ts +20 -0
- package/dist/components/overlays/custom-model-wizard/shared/SetupInfoBanner.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/shared/SetupInfoBanner.js +24 -0
- package/dist/components/overlays/custom-model-wizard/shared/WizardStepInput.cjs +58 -0
- package/dist/components/overlays/custom-model-wizard/shared/WizardStepInput.d.ts +30 -0
- package/dist/components/overlays/custom-model-wizard/shared/WizardStepInput.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/shared/WizardStepInput.js +34 -0
- package/dist/components/overlays/custom-model-wizard/shared/index.cjs +41 -0
- package/dist/components/overlays/custom-model-wizard/shared/index.d.ts +8 -0
- package/dist/components/overlays/custom-model-wizard/shared/index.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/shared/index.js +12 -0
- package/dist/components/overlays/custom-model-wizard/types.cjs +53 -0
- package/dist/components/overlays/custom-model-wizard/types.d.ts +85 -0
- package/dist/components/overlays/custom-model-wizard/types.d.ts.map +1 -0
- package/dist/components/overlays/custom-model-wizard/types.js +29 -0
- package/dist/components/renderers/DiffRenderer.cjs +145 -0
- package/dist/components/renderers/DiffRenderer.d.ts +21 -0
- package/dist/components/renderers/DiffRenderer.d.ts.map +1 -0
- package/dist/components/renderers/DiffRenderer.js +118 -0
- package/dist/components/renderers/FilePreviewRenderer.cjs +146 -0
- package/dist/components/renderers/FilePreviewRenderer.d.ts +30 -0
- package/dist/components/renderers/FilePreviewRenderer.d.ts.map +1 -0
- package/dist/components/renderers/FilePreviewRenderer.js +119 -0
- package/dist/components/renderers/FileRenderer.cjs +95 -0
- package/dist/components/renderers/FileRenderer.d.ts +21 -0
- package/dist/components/renderers/FileRenderer.d.ts.map +1 -0
- package/dist/components/renderers/FileRenderer.js +71 -0
- package/dist/components/renderers/GenericRenderer.cjs +63 -0
- package/dist/components/renderers/GenericRenderer.d.ts +21 -0
- package/dist/components/renderers/GenericRenderer.d.ts.map +1 -0
- package/dist/components/renderers/GenericRenderer.js +39 -0
- package/dist/components/renderers/SearchRenderer.cjs +77 -0
- package/dist/components/renderers/SearchRenderer.d.ts +20 -0
- package/dist/components/renderers/SearchRenderer.d.ts.map +1 -0
- package/dist/components/renderers/SearchRenderer.js +43 -0
- package/dist/components/renderers/ShellRenderer.cjs +61 -0
- package/dist/components/renderers/ShellRenderer.d.ts +21 -0
- package/dist/components/renderers/ShellRenderer.d.ts.map +1 -0
- package/dist/components/renderers/ShellRenderer.js +37 -0
- package/dist/components/renderers/diff-shared.cjs +172 -0
- package/dist/components/renderers/diff-shared.d.ts +61 -0
- package/dist/components/renderers/diff-shared.d.ts.map +1 -0
- package/dist/components/renderers/diff-shared.js +142 -0
- package/dist/components/renderers/index.cjs +75 -0
- package/dist/components/renderers/index.d.ts +28 -0
- package/dist/components/renderers/index.d.ts.map +1 -0
- package/dist/components/renderers/index.js +44 -0
- package/dist/components/shared/FocusOverlayFrame.cjs +39 -0
- package/dist/components/shared/FocusOverlayFrame.d.ts +7 -0
- package/dist/components/shared/FocusOverlayFrame.d.ts.map +1 -0
- package/dist/components/shared/FocusOverlayFrame.js +15 -0
- package/dist/components/shared/HintBar.cjs +33 -0
- package/dist/components/shared/HintBar.d.ts +6 -0
- package/dist/components/shared/HintBar.d.ts.map +1 -0
- package/dist/components/shared/HintBar.js +9 -0
- package/dist/components/shared/MarkdownText.cjs +409 -0
- package/dist/components/shared/MarkdownText.d.ts +38 -0
- package/dist/components/shared/MarkdownText.d.ts.map +1 -0
- package/dist/components/shared/MarkdownText.js +373 -0
- package/dist/components/shared/VirtualizedList.cjs +365 -0
- package/dist/components/shared/VirtualizedList.d.ts +44 -0
- package/dist/components/shared/VirtualizedList.d.ts.map +1 -0
- package/dist/components/shared/VirtualizedList.js +349 -0
- package/dist/components/shared/text-buffer.cjs +1220 -0
- package/dist/components/shared/text-buffer.d.ts +185 -0
- package/dist/components/shared/text-buffer.d.ts.map +1 -0
- package/dist/components/shared/text-buffer.js +1194 -0
- package/dist/constants/processingPhrases.cjs +114 -0
- package/dist/constants/processingPhrases.d.ts +10 -0
- package/dist/constants/processingPhrases.d.ts.map +1 -0
- package/dist/constants/processingPhrases.js +89 -0
- package/dist/constants/spinnerFrames.cjs +28 -0
- package/dist/constants/spinnerFrames.d.ts +2 -0
- package/dist/constants/spinnerFrames.d.ts.map +1 -0
- package/dist/constants/spinnerFrames.js +4 -0
- package/dist/constants/tips.cjs +76 -0
- package/dist/constants/tips.d.ts +15 -0
- package/dist/constants/tips.d.ts.map +1 -0
- package/dist/constants/tips.js +51 -0
- package/dist/containers/InputContainer.cjs +706 -0
- package/dist/containers/InputContainer.d.ts +62 -0
- package/dist/containers/InputContainer.d.ts.map +1 -0
- package/dist/containers/InputContainer.js +672 -0
- package/dist/containers/OverlayContainer.cjs +2372 -0
- package/dist/containers/OverlayContainer.d.ts +42 -0
- package/dist/containers/OverlayContainer.d.ts.map +1 -0
- package/dist/containers/OverlayContainer.js +2356 -0
- package/dist/containers/index.cjs +31 -0
- package/dist/containers/index.d.ts +6 -0
- package/dist/containers/index.d.ts.map +1 -0
- package/dist/containers/index.js +6 -0
- package/dist/contexts/KeypressContext.cjs +436 -0
- package/dist/contexts/KeypressContext.d.ts +36 -0
- package/dist/contexts/KeypressContext.d.ts.map +1 -0
- package/dist/contexts/KeypressContext.js +408 -0
- package/dist/contexts/MouseContext.cjs +122 -0
- package/dist/contexts/MouseContext.d.ts +27 -0
- package/dist/contexts/MouseContext.d.ts.map +1 -0
- package/dist/contexts/MouseContext.js +101 -0
- package/dist/contexts/ScrollProvider.cjs +180 -0
- package/dist/contexts/ScrollProvider.d.ts +33 -0
- package/dist/contexts/ScrollProvider.d.ts.map +1 -0
- package/dist/contexts/ScrollProvider.js +163 -0
- package/dist/contexts/SoundContext.cjs +38 -0
- package/dist/contexts/SoundContext.d.ts +23 -0
- package/dist/contexts/SoundContext.d.ts.map +1 -0
- package/dist/contexts/SoundContext.js +13 -0
- package/dist/contexts/index.cjs +47 -0
- package/dist/contexts/index.d.ts +8 -0
- package/dist/contexts/index.d.ts.map +1 -0
- package/dist/contexts/index.js +25 -0
- package/dist/hooks/index.cjs +54 -0
- package/dist/hooks/index.d.ts +12 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +28 -0
- package/dist/hooks/useAgentEvents.cjs +382 -0
- package/dist/hooks/useAgentEvents.d.ts +49 -0
- package/dist/hooks/useAgentEvents.d.ts.map +1 -0
- package/dist/hooks/useAgentEvents.js +360 -0
- package/dist/hooks/useAnimationTick.cjs +71 -0
- package/dist/hooks/useAnimationTick.d.ts +11 -0
- package/dist/hooks/useAnimationTick.d.ts.map +1 -0
- package/dist/hooks/useAnimationTick.js +47 -0
- package/dist/hooks/useBatchedScroll.cjs +44 -0
- package/dist/hooks/useBatchedScroll.d.ts +14 -0
- package/dist/hooks/useBatchedScroll.d.ts.map +1 -0
- package/dist/hooks/useBatchedScroll.js +20 -0
- package/dist/hooks/useCLIState.cjs +222 -0
- package/dist/hooks/useCLIState.d.ts +53 -0
- package/dist/hooks/useCLIState.d.ts.map +1 -0
- package/dist/hooks/useCLIState.js +201 -0
- package/dist/hooks/useElapsedTime.cjs +79 -0
- package/dist/hooks/useElapsedTime.d.ts +24 -0
- package/dist/hooks/useElapsedTime.d.ts.map +1 -0
- package/dist/hooks/useElapsedTime.js +55 -0
- package/dist/hooks/useGitBranch.cjs +47 -0
- package/dist/hooks/useGitBranch.d.ts +13 -0
- package/dist/hooks/useGitBranch.d.ts.map +1 -0
- package/dist/hooks/useGitBranch.js +23 -0
- package/dist/hooks/useHistorySearch.cjs +219 -0
- package/dist/hooks/useHistorySearch.d.ts +61 -0
- package/dist/hooks/useHistorySearch.d.ts.map +1 -0
- package/dist/hooks/useHistorySearch.js +195 -0
- package/dist/hooks/useInputHistory.cjs +47 -0
- package/dist/hooks/useInputHistory.d.ts +18 -0
- package/dist/hooks/useInputHistory.d.ts.map +1 -0
- package/dist/hooks/useInputHistory.js +23 -0
- package/dist/hooks/useInputOrchestrator.cjs +663 -0
- package/dist/hooks/useInputOrchestrator.d.ts +136 -0
- package/dist/hooks/useInputOrchestrator.d.ts.map +1 -0
- package/dist/hooks/useInputOrchestrator.js +635 -0
- package/dist/hooks/useKeyboardShortcuts.cjs +87 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts +21 -0
- package/dist/hooks/useKeyboardShortcuts.d.ts.map +1 -0
- package/dist/hooks/useKeyboardShortcuts.js +63 -0
- package/dist/hooks/useKeypress.cjs +41 -0
- package/dist/hooks/useKeypress.d.ts +18 -0
- package/dist/hooks/useKeypress.d.ts.map +1 -0
- package/dist/hooks/useKeypress.js +17 -0
- package/dist/hooks/usePhraseCycler.cjs +74 -0
- package/dist/hooks/usePhraseCycler.d.ts +30 -0
- package/dist/hooks/usePhraseCycler.d.ts.map +1 -0
- package/dist/hooks/usePhraseCycler.js +50 -0
- package/dist/hooks/useStreaming.cjs +43 -0
- package/dist/hooks/useStreaming.d.ts +19 -0
- package/dist/hooks/useStreaming.d.ts.map +1 -0
- package/dist/hooks/useStreaming.js +24 -0
- package/dist/hooks/useTerminalSize.cjs +48 -0
- package/dist/hooks/useTerminalSize.d.ts +14 -0
- package/dist/hooks/useTerminalSize.d.ts.map +1 -0
- package/dist/hooks/useTerminalSize.js +24 -0
- package/dist/hooks/useTokenCounter.cjs +105 -0
- package/dist/hooks/useTokenCounter.d.ts +46 -0
- package/dist/hooks/useTokenCounter.d.ts.map +1 -0
- package/dist/hooks/useTokenCounter.js +81 -0
- package/dist/host/index.cjs +144 -0
- package/dist/host/index.d.ts +108 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +104 -0
- package/dist/index.cjs +33 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/interactive-commands/auth/index.cjs +44 -0
- package/dist/interactive-commands/auth/index.d.ts +13 -0
- package/dist/interactive-commands/auth/index.d.ts.map +1 -0
- package/dist/interactive-commands/auth/index.js +19 -0
- package/dist/interactive-commands/command-parser.cjs +184 -0
- package/dist/interactive-commands/command-parser.d.ts +56 -0
- package/dist/interactive-commands/command-parser.d.ts.map +1 -0
- package/dist/interactive-commands/command-parser.js +146 -0
- package/dist/interactive-commands/commands.cjs +135 -0
- package/dist/interactive-commands/commands.d.ts +52 -0
- package/dist/interactive-commands/commands.d.ts.map +1 -0
- package/dist/interactive-commands/commands.js +99 -0
- package/dist/interactive-commands/documentation-commands.cjs +61 -0
- package/dist/interactive-commands/documentation-commands.d.ts +15 -0
- package/dist/interactive-commands/documentation-commands.d.ts.map +1 -0
- package/dist/interactive-commands/documentation-commands.js +27 -0
- package/dist/interactive-commands/exit-handler.cjs +40 -0
- package/dist/interactive-commands/exit-handler.d.ts +12 -0
- package/dist/interactive-commands/exit-handler.d.ts.map +1 -0
- package/dist/interactive-commands/exit-handler.js +15 -0
- package/dist/interactive-commands/exit-stats.cjs +41 -0
- package/dist/interactive-commands/exit-stats.d.ts +24 -0
- package/dist/interactive-commands/exit-stats.d.ts.map +1 -0
- package/dist/interactive-commands/exit-stats.js +15 -0
- package/dist/interactive-commands/export/index.cjs +36 -0
- package/dist/interactive-commands/export/index.d.ts +13 -0
- package/dist/interactive-commands/export/index.d.ts.map +1 -0
- package/dist/interactive-commands/export/index.js +12 -0
- package/dist/interactive-commands/general-commands.cjs +478 -0
- package/dist/interactive-commands/general-commands.d.ts +22 -0
- package/dist/interactive-commands/general-commands.d.ts.map +1 -0
- package/dist/interactive-commands/general-commands.js +443 -0
- package/dist/interactive-commands/mcp/index.cjs +35 -0
- package/dist/interactive-commands/mcp/index.d.ts +13 -0
- package/dist/interactive-commands/mcp/index.d.ts.map +1 -0
- package/dist/interactive-commands/mcp/index.js +11 -0
- package/dist/interactive-commands/model/index.cjs +36 -0
- package/dist/interactive-commands/model/index.d.ts +13 -0
- package/dist/interactive-commands/model/index.d.ts.map +1 -0
- package/dist/interactive-commands/model/index.js +12 -0
- package/dist/interactive-commands/plugin/index.cjs +35 -0
- package/dist/interactive-commands/plugin/index.d.ts +13 -0
- package/dist/interactive-commands/plugin/index.d.ts.map +1 -0
- package/dist/interactive-commands/plugin/index.js +11 -0
- package/dist/interactive-commands/prompt-commands.cjs +269 -0
- package/dist/interactive-commands/prompt-commands.d.ts +25 -0
- package/dist/interactive-commands/prompt-commands.d.ts.map +1 -0
- package/dist/interactive-commands/prompt-commands.js +244 -0
- package/dist/interactive-commands/session/index.cjs +32 -0
- package/dist/interactive-commands/session/index.d.ts +16 -0
- package/dist/interactive-commands/session/index.d.ts.map +1 -0
- package/dist/interactive-commands/session/index.js +6 -0
- package/dist/interactive-commands/session/session-commands.cjs +64 -0
- package/dist/interactive-commands/session/session-commands.d.ts +32 -0
- package/dist/interactive-commands/session/session-commands.d.ts.map +1 -0
- package/dist/interactive-commands/session/session-commands.js +38 -0
- package/dist/interactive-commands/system/index.cjs +28 -0
- package/dist/interactive-commands/system/index.d.ts +13 -0
- package/dist/interactive-commands/system/index.d.ts.map +1 -0
- package/dist/interactive-commands/system/index.js +4 -0
- package/dist/interactive-commands/system/system-commands.cjs +217 -0
- package/dist/interactive-commands/system/system-commands.d.ts +6 -0
- package/dist/interactive-commands/system/system-commands.d.ts.map +1 -0
- package/dist/interactive-commands/system/system-commands.js +195 -0
- package/dist/interactive-commands/tool-commands.cjs +38 -0
- package/dist/interactive-commands/tool-commands.d.ts +15 -0
- package/dist/interactive-commands/tool-commands.d.ts.map +1 -0
- package/dist/interactive-commands/tool-commands.js +14 -0
- package/dist/interactive-commands/utils/arg-parser.cjs +59 -0
- package/dist/interactive-commands/utils/arg-parser.d.ts +57 -0
- package/dist/interactive-commands/utils/arg-parser.d.ts.map +1 -0
- package/dist/interactive-commands/utils/arg-parser.js +34 -0
- package/dist/interactive-commands/utils/command-output.cjs +75 -0
- package/dist/interactive-commands/utils/command-output.d.ts +40 -0
- package/dist/interactive-commands/utils/command-output.d.ts.map +1 -0
- package/dist/interactive-commands/utils/command-output.js +51 -0
- package/dist/interactive-commands/utils/format-output.cjs +36 -0
- package/dist/interactive-commands/utils/format-output.d.ts +14 -0
- package/dist/interactive-commands/utils/format-output.d.ts.map +1 -0
- package/dist/interactive-commands/utils/format-output.js +11 -0
- package/dist/services/CommandService.cjs +68 -0
- package/dist/services/CommandService.d.ts +58 -0
- package/dist/services/CommandService.d.ts.map +1 -0
- package/dist/services/CommandService.js +41 -0
- package/dist/services/InputService.cjs +97 -0
- package/dist/services/InputService.d.ts +40 -0
- package/dist/services/InputService.d.ts.map +1 -0
- package/dist/services/InputService.js +78 -0
- package/dist/services/MessageService.cjs +69 -0
- package/dist/services/MessageService.d.ts +35 -0
- package/dist/services/MessageService.d.ts.map +1 -0
- package/dist/services/MessageService.js +51 -0
- package/dist/services/index.cjs +39 -0
- package/dist/services/index.d.ts +8 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +16 -0
- package/dist/services/processStream.cjs +877 -0
- package/dist/services/processStream.d.ts +79 -0
- package/dist/services/processStream.d.ts.map +1 -0
- package/dist/services/processStream.js +843 -0
- package/dist/services/processStream.test.cjs +255 -0
- package/dist/services/processStream.test.d.ts +2 -0
- package/dist/services/processStream.test.d.ts.map +1 -0
- package/dist/services/processStream.test.js +254 -0
- package/dist/state/actions.cjs +16 -0
- package/dist/state/actions.d.ts +124 -0
- package/dist/state/actions.d.ts.map +1 -0
- package/dist/state/actions.js +0 -0
- package/dist/state/index.cjs +28 -0
- package/dist/state/index.d.ts +10 -0
- package/dist/state/index.d.ts.map +1 -0
- package/dist/state/index.js +4 -0
- package/dist/state/initialState.cjs +78 -0
- package/dist/state/initialState.d.ts +12 -0
- package/dist/state/initialState.d.ts.map +1 -0
- package/dist/state/initialState.js +54 -0
- package/dist/state/reducer.cjs +340 -0
- package/dist/state/reducer.d.ts +15 -0
- package/dist/state/reducer.d.ts.map +1 -0
- package/dist/state/reducer.js +316 -0
- package/dist/state/streaming-state.cjs +52 -0
- package/dist/state/streaming-state.d.ts +27 -0
- package/dist/state/streaming-state.d.ts.map +1 -0
- package/dist/state/streaming-state.js +25 -0
- package/dist/state/types.cjs +16 -0
- package/dist/state/types.d.ts +388 -0
- package/dist/state/types.d.ts.map +1 -0
- package/dist/state/types.js +0 -0
- package/dist/utils/bracketedPaste.cjs +37 -0
- package/dist/utils/bracketedPaste.d.ts +22 -0
- package/dist/utils/bracketedPaste.d.ts.map +1 -0
- package/dist/utils/bracketedPaste.js +12 -0
- package/dist/utils/clipboardUtils.cjs +297 -0
- package/dist/utils/clipboardUtils.d.ts +49 -0
- package/dist/utils/clipboardUtils.d.ts.map +1 -0
- package/dist/utils/clipboardUtils.js +261 -0
- package/dist/utils/commandOverlays.cjs +69 -0
- package/dist/utils/commandOverlays.d.ts +22 -0
- package/dist/utils/commandOverlays.d.ts.map +1 -0
- package/dist/utils/commandOverlays.js +44 -0
- package/dist/utils/debugLog.cjs +63 -0
- package/dist/utils/debugLog.d.ts +38 -0
- package/dist/utils/debugLog.d.ts.map +1 -0
- package/dist/utils/debugLog.js +39 -0
- package/dist/utils/elicitationSchema.cjs +85 -0
- package/dist/utils/elicitationSchema.d.ts +11 -0
- package/dist/utils/elicitationSchema.d.ts.map +1 -0
- package/dist/utils/elicitationSchema.js +61 -0
- package/dist/utils/elicitationSchema.test.cjs +78 -0
- package/dist/utils/elicitationSchema.test.d.ts +2 -0
- package/dist/utils/elicitationSchema.test.d.ts.map +1 -0
- package/dist/utils/elicitationSchema.test.js +77 -0
- package/dist/utils/idGenerator.cjs +31 -0
- package/dist/utils/idGenerator.d.ts +10 -0
- package/dist/utils/idGenerator.d.ts.map +1 -0
- package/dist/utils/idGenerator.js +7 -0
- package/dist/utils/index.cjs +62 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +39 -0
- package/dist/utils/input.cjs +72 -0
- package/dist/utils/input.d.ts +25 -0
- package/dist/utils/input.d.ts.map +1 -0
- package/dist/utils/input.js +39 -0
- package/dist/utils/inputParsing.cjs +76 -0
- package/dist/utils/inputParsing.d.ts +31 -0
- package/dist/utils/inputParsing.d.ts.map +1 -0
- package/dist/utils/inputParsing.js +48 -0
- package/dist/utils/llm-provider-display.cjs +49 -0
- package/dist/utils/llm-provider-display.d.ts +3 -0
- package/dist/utils/llm-provider-display.d.ts.map +1 -0
- package/dist/utils/llm-provider-display.js +25 -0
- package/dist/utils/messageFormatting.cjs +447 -0
- package/dist/utils/messageFormatting.d.ts +131 -0
- package/dist/utils/messageFormatting.d.ts.map +1 -0
- package/dist/utils/messageFormatting.js +393 -0
- package/dist/utils/messageFormatting.test.cjs +16 -0
- package/dist/utils/messageFormatting.test.d.ts +2 -0
- package/dist/utils/messageFormatting.test.d.ts.map +1 -0
- package/dist/utils/messageFormatting.test.js +15 -0
- package/dist/utils/mouse.cjs +196 -0
- package/dist/utils/mouse.d.ts +61 -0
- package/dist/utils/mouse.d.ts.map +1 -0
- package/dist/utils/mouse.js +172 -0
- package/dist/utils/overlayPresentation.cjs +48 -0
- package/dist/utils/overlayPresentation.d.ts +19 -0
- package/dist/utils/overlayPresentation.d.ts.map +1 -0
- package/dist/utils/overlayPresentation.js +22 -0
- package/dist/utils/overlaySizing.cjs +39 -0
- package/dist/utils/overlaySizing.d.ts +19 -0
- package/dist/utils/overlaySizing.d.ts.map +1 -0
- package/dist/utils/overlaySizing.js +15 -0
- package/dist/utils/soundNotification.cjs +217 -0
- package/dist/utils/soundNotification.d.ts +77 -0
- package/dist/utils/soundNotification.d.ts.map +1 -0
- package/dist/utils/soundNotification.js +188 -0
- package/dist/utils/soundNotification.test.cjs +126 -0
- package/dist/utils/soundNotification.test.d.ts +2 -0
- package/dist/utils/soundNotification.test.d.ts.map +1 -0
- package/dist/utils/soundNotification.test.js +125 -0
- package/dist/utils/streamSplitter.cjs +126 -0
- package/dist/utils/streamSplitter.d.ts +44 -0
- package/dist/utils/streamSplitter.d.ts.map +1 -0
- package/dist/utils/streamSplitter.js +100 -0
- package/dist/utils/textUtils.cjs +223 -0
- package/dist/utils/textUtils.d.ts +63 -0
- package/dist/utils/textUtils.d.ts.map +1 -0
- package/dist/utils/textUtils.js +174 -0
- package/dist/utils/toolUtils.cjs +40 -0
- package/dist/utils/toolUtils.d.ts +20 -0
- package/dist/utils/toolUtils.d.ts.map +1 -0
- package/dist/utils/toolUtils.js +14 -0
- package/package.json +51 -0
|
@@ -0,0 +1,1194 @@
|
|
|
1
|
+
import { useState, useCallback, useEffect, useMemo, useReducer } from "react";
|
|
2
|
+
import {
|
|
3
|
+
toCodePoints,
|
|
4
|
+
cpLen,
|
|
5
|
+
cpSlice,
|
|
6
|
+
stripUnsafeCharacters,
|
|
7
|
+
getCachedStringWidth,
|
|
8
|
+
isWordCharStrict,
|
|
9
|
+
isWhitespace,
|
|
10
|
+
isWordCharWithCombining,
|
|
11
|
+
isDifferentScript
|
|
12
|
+
} from "../../utils/textUtils.js";
|
|
13
|
+
const findNextWordStartInLine = (line, col) => {
|
|
14
|
+
const chars = toCodePoints(line);
|
|
15
|
+
let i = col;
|
|
16
|
+
if (i >= chars.length) return null;
|
|
17
|
+
const currentChar = chars[i];
|
|
18
|
+
if (isWordCharStrict(currentChar)) {
|
|
19
|
+
while (i < chars.length && isWordCharWithCombining(chars[i])) {
|
|
20
|
+
if (i + 1 < chars.length && isWordCharStrict(chars[i + 1]) && isDifferentScript(chars[i], chars[i + 1])) {
|
|
21
|
+
i++;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
} else if (!isWhitespace(currentChar)) {
|
|
27
|
+
while (i < chars.length && !isWordCharStrict(chars[i]) && !isWhitespace(chars[i])) {
|
|
28
|
+
i++;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
while (i < chars.length && isWhitespace(chars[i])) {
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
return i < chars.length ? i : null;
|
|
35
|
+
};
|
|
36
|
+
const findPrevWordStartInLine = (line, col) => {
|
|
37
|
+
const chars = toCodePoints(line);
|
|
38
|
+
let i = col;
|
|
39
|
+
if (i <= 0) return null;
|
|
40
|
+
i--;
|
|
41
|
+
while (i >= 0 && isWhitespace(chars[i])) {
|
|
42
|
+
i--;
|
|
43
|
+
}
|
|
44
|
+
if (i < 0) return null;
|
|
45
|
+
if (isWordCharStrict(chars[i])) {
|
|
46
|
+
while (i >= 0 && isWordCharStrict(chars[i])) {
|
|
47
|
+
if (i - 1 >= 0 && isWordCharStrict(chars[i - 1]) && isDifferentScript(chars[i], chars[i - 1])) {
|
|
48
|
+
return i;
|
|
49
|
+
}
|
|
50
|
+
i--;
|
|
51
|
+
}
|
|
52
|
+
return i + 1;
|
|
53
|
+
} else {
|
|
54
|
+
while (i >= 0 && !isWordCharStrict(chars[i]) && !isWhitespace(chars[i])) {
|
|
55
|
+
i--;
|
|
56
|
+
}
|
|
57
|
+
return i + 1;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const findWordEndInLine = (line, col) => {
|
|
61
|
+
const chars = toCodePoints(line);
|
|
62
|
+
let i = col;
|
|
63
|
+
const atEndOfWordChar = i < chars.length && isWordCharWithCombining(chars[i]) && (i + 1 >= chars.length || !isWordCharWithCombining(chars[i + 1]) || isWordCharStrict(chars[i]) && i + 1 < chars.length && isWordCharStrict(chars[i + 1]) && isDifferentScript(chars[i], chars[i + 1]));
|
|
64
|
+
const atEndOfPunctuation = i < chars.length && !isWordCharWithCombining(chars[i]) && !isWhitespace(chars[i]) && (i + 1 >= chars.length || isWhitespace(chars[i + 1]) || isWordCharWithCombining(chars[i + 1]));
|
|
65
|
+
if (atEndOfWordChar || atEndOfPunctuation) {
|
|
66
|
+
i++;
|
|
67
|
+
while (i < chars.length && isWhitespace(chars[i])) {
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (i < chars.length && !isWordCharWithCombining(chars[i])) {
|
|
72
|
+
while (i < chars.length && isWhitespace(chars[i])) {
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let foundWord = false;
|
|
77
|
+
let lastBaseCharPos = -1;
|
|
78
|
+
if (i < chars.length && isWordCharWithCombining(chars[i])) {
|
|
79
|
+
while (i < chars.length && isWordCharWithCombining(chars[i])) {
|
|
80
|
+
foundWord = true;
|
|
81
|
+
if (isWordCharStrict(chars[i])) {
|
|
82
|
+
lastBaseCharPos = i;
|
|
83
|
+
}
|
|
84
|
+
if (i + 1 < chars.length && isWordCharStrict(chars[i + 1]) && isDifferentScript(chars[i], chars[i + 1])) {
|
|
85
|
+
i++;
|
|
86
|
+
if (isWordCharStrict(chars[i - 1])) {
|
|
87
|
+
lastBaseCharPos = i - 1;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
} else if (i < chars.length && !isWhitespace(chars[i])) {
|
|
94
|
+
while (i < chars.length && !isWordCharStrict(chars[i]) && !isWhitespace(chars[i])) {
|
|
95
|
+
foundWord = true;
|
|
96
|
+
lastBaseCharPos = i;
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (foundWord && lastBaseCharPos >= col) {
|
|
101
|
+
return lastBaseCharPos;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
const segmenter = new Intl.Segmenter(void 0, { granularity: "word" });
|
|
106
|
+
function findPrevWordBoundary(line, cursorCol) {
|
|
107
|
+
const codePoints = toCodePoints(line);
|
|
108
|
+
const prefix = codePoints.slice(0, cursorCol).join("");
|
|
109
|
+
const cursorIdx = prefix.length;
|
|
110
|
+
let targetIdx = 0;
|
|
111
|
+
for (const seg of segmenter.segment(line)) {
|
|
112
|
+
if (seg.index >= cursorIdx) break;
|
|
113
|
+
if (seg.isWordLike) {
|
|
114
|
+
targetIdx = seg.index;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return toCodePoints(line.slice(0, targetIdx)).length;
|
|
118
|
+
}
|
|
119
|
+
function findNextWordBoundary(line, cursorCol) {
|
|
120
|
+
const codePoints = toCodePoints(line);
|
|
121
|
+
const prefix = codePoints.slice(0, cursorCol).join("");
|
|
122
|
+
const cursorIdx = prefix.length;
|
|
123
|
+
let targetIdx = line.length;
|
|
124
|
+
for (const seg of segmenter.segment(line)) {
|
|
125
|
+
const segEnd = seg.index + seg.segment.length;
|
|
126
|
+
if (segEnd > cursorIdx) {
|
|
127
|
+
if (seg.isWordLike) {
|
|
128
|
+
targetIdx = segEnd;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return toCodePoints(line.slice(0, targetIdx)).length;
|
|
134
|
+
}
|
|
135
|
+
const findNextWordAcrossLines = (lines, cursorRow, cursorCol, searchForWordStart) => {
|
|
136
|
+
const currentLine = lines[cursorRow] || "";
|
|
137
|
+
const colInCurrentLine = searchForWordStart ? findNextWordStartInLine(currentLine, cursorCol) : findWordEndInLine(currentLine, cursorCol);
|
|
138
|
+
if (colInCurrentLine !== null) {
|
|
139
|
+
return { row: cursorRow, col: colInCurrentLine };
|
|
140
|
+
}
|
|
141
|
+
for (let row = cursorRow + 1; row < lines.length; row++) {
|
|
142
|
+
const line = lines[row] || "";
|
|
143
|
+
const chars = toCodePoints(line);
|
|
144
|
+
if (chars.length === 0) {
|
|
145
|
+
let hasWordsInLaterLines = false;
|
|
146
|
+
for (let laterRow = row + 1; laterRow < lines.length; laterRow++) {
|
|
147
|
+
const laterLine = lines[laterRow] || "";
|
|
148
|
+
const laterChars = toCodePoints(laterLine);
|
|
149
|
+
let firstNonWhitespace2 = 0;
|
|
150
|
+
while (firstNonWhitespace2 < laterChars.length && isWhitespace(laterChars[firstNonWhitespace2])) {
|
|
151
|
+
firstNonWhitespace2++;
|
|
152
|
+
}
|
|
153
|
+
if (firstNonWhitespace2 < laterChars.length) {
|
|
154
|
+
hasWordsInLaterLines = true;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!hasWordsInLaterLines) {
|
|
159
|
+
return { row, col: 0 };
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
let firstNonWhitespace = 0;
|
|
164
|
+
while (firstNonWhitespace < chars.length && isWhitespace(chars[firstNonWhitespace])) {
|
|
165
|
+
firstNonWhitespace++;
|
|
166
|
+
}
|
|
167
|
+
if (firstNonWhitespace < chars.length) {
|
|
168
|
+
if (searchForWordStart) {
|
|
169
|
+
return { row, col: firstNonWhitespace };
|
|
170
|
+
} else {
|
|
171
|
+
const endCol = findWordEndInLine(line, firstNonWhitespace);
|
|
172
|
+
if (endCol !== null) {
|
|
173
|
+
return { row, col: endCol };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
};
|
|
180
|
+
const findPrevWordAcrossLines = (lines, cursorRow, cursorCol) => {
|
|
181
|
+
const currentLine = lines[cursorRow] || "";
|
|
182
|
+
const colInCurrentLine = findPrevWordStartInLine(currentLine, cursorCol);
|
|
183
|
+
if (colInCurrentLine !== null) {
|
|
184
|
+
return { row: cursorRow, col: colInCurrentLine };
|
|
185
|
+
}
|
|
186
|
+
for (let row = cursorRow - 1; row >= 0; row--) {
|
|
187
|
+
const line = lines[row] || "";
|
|
188
|
+
const chars = toCodePoints(line);
|
|
189
|
+
if (chars.length === 0) continue;
|
|
190
|
+
let lastWordStart = chars.length;
|
|
191
|
+
while (lastWordStart > 0 && isWhitespace(chars[lastWordStart - 1])) {
|
|
192
|
+
lastWordStart--;
|
|
193
|
+
}
|
|
194
|
+
if (lastWordStart > 0) {
|
|
195
|
+
const wordStart = findPrevWordStartInLine(line, lastWordStart);
|
|
196
|
+
if (wordStart !== null) {
|
|
197
|
+
return { row, col: wordStart };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
};
|
|
203
|
+
const getPositionFromOffsets = (startOffset, endOffset, lines) => {
|
|
204
|
+
let offset = 0;
|
|
205
|
+
let startRow = 0;
|
|
206
|
+
let startCol = 0;
|
|
207
|
+
let endRow = 0;
|
|
208
|
+
let endCol = 0;
|
|
209
|
+
for (let i = 0; i < lines.length; i++) {
|
|
210
|
+
const lineLength = lines[i].length + 1;
|
|
211
|
+
if (offset + lineLength > startOffset) {
|
|
212
|
+
startRow = i;
|
|
213
|
+
startCol = startOffset - offset;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
offset += lineLength;
|
|
217
|
+
}
|
|
218
|
+
offset = 0;
|
|
219
|
+
for (let i = 0; i < lines.length; i++) {
|
|
220
|
+
const lineLength = lines[i].length + (i < lines.length - 1 ? 1 : 0);
|
|
221
|
+
if (offset + lineLength >= endOffset) {
|
|
222
|
+
endRow = i;
|
|
223
|
+
endCol = endOffset - offset;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
offset += lineLength;
|
|
227
|
+
}
|
|
228
|
+
return { startRow, startCol, endRow, endCol };
|
|
229
|
+
};
|
|
230
|
+
const getLineRangeOffsets = (startRow, lineCount, lines) => {
|
|
231
|
+
let startOffset = 0;
|
|
232
|
+
for (let i = 0; i < startRow; i++) {
|
|
233
|
+
startOffset += lines[i].length + 1;
|
|
234
|
+
}
|
|
235
|
+
let endOffset = startOffset;
|
|
236
|
+
for (let i = 0; i < lineCount; i++) {
|
|
237
|
+
const lineIndex = startRow + i;
|
|
238
|
+
if (lineIndex < lines.length) {
|
|
239
|
+
endOffset += lines[lineIndex].length;
|
|
240
|
+
if (lineIndex < lines.length - 1) {
|
|
241
|
+
endOffset += 1;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return { startOffset, endOffset };
|
|
246
|
+
};
|
|
247
|
+
const replaceRangeInternal = (state, startRow, startCol, endRow, endCol, text) => {
|
|
248
|
+
const currentLine = (row) => state.lines[row] || "";
|
|
249
|
+
const currentLineLen = (row) => cpLen(currentLine(row));
|
|
250
|
+
const clamp2 = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
251
|
+
if (startRow > endRow || startRow === endRow && startCol > endCol || startRow < 0 || startCol < 0 || endRow >= state.lines.length || endRow < state.lines.length && endCol > currentLineLen(endRow)) {
|
|
252
|
+
return state;
|
|
253
|
+
}
|
|
254
|
+
const newLines = [...state.lines];
|
|
255
|
+
const sCol = clamp2(startCol, 0, currentLineLen(startRow));
|
|
256
|
+
const eCol = clamp2(endCol, 0, currentLineLen(endRow));
|
|
257
|
+
const prefix = cpSlice(currentLine(startRow), 0, sCol);
|
|
258
|
+
const suffix = cpSlice(currentLine(endRow), eCol);
|
|
259
|
+
const normalisedReplacement = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
260
|
+
const replacementParts = normalisedReplacement.split("\n");
|
|
261
|
+
const firstLine = prefix + replacementParts[0];
|
|
262
|
+
if (replacementParts.length === 1) {
|
|
263
|
+
newLines.splice(startRow, endRow - startRow + 1, firstLine + suffix);
|
|
264
|
+
} else {
|
|
265
|
+
const lastLine = replacementParts[replacementParts.length - 1] + suffix;
|
|
266
|
+
const middleLines = replacementParts.slice(1, -1);
|
|
267
|
+
newLines.splice(startRow, endRow - startRow + 1, firstLine, ...middleLines, lastLine);
|
|
268
|
+
}
|
|
269
|
+
const finalCursorRow = startRow + replacementParts.length - 1;
|
|
270
|
+
const finalCursorCol = (replacementParts.length > 1 ? 0 : sCol) + cpLen(replacementParts[replacementParts.length - 1]);
|
|
271
|
+
return {
|
|
272
|
+
...state,
|
|
273
|
+
lines: newLines,
|
|
274
|
+
cursorRow: Math.min(Math.max(finalCursorRow, 0), newLines.length - 1),
|
|
275
|
+
cursorCol: Math.max(0, Math.min(finalCursorCol, cpLen(newLines[finalCursorRow] || ""))),
|
|
276
|
+
preferredCol: null
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
function clamp(v, min, max) {
|
|
280
|
+
return v < min ? min : v > max ? max : v;
|
|
281
|
+
}
|
|
282
|
+
function calculateInitialCursorPosition(initialLines, offset) {
|
|
283
|
+
let remainingChars = offset;
|
|
284
|
+
let row = 0;
|
|
285
|
+
while (row < initialLines.length) {
|
|
286
|
+
const lineLength = cpLen(initialLines[row]);
|
|
287
|
+
const totalCharsInLineAndNewline = lineLength + (row < initialLines.length - 1 ? 1 : 0);
|
|
288
|
+
if (remainingChars <= lineLength) {
|
|
289
|
+
return [row, remainingChars];
|
|
290
|
+
}
|
|
291
|
+
remainingChars -= totalCharsInLineAndNewline;
|
|
292
|
+
row++;
|
|
293
|
+
}
|
|
294
|
+
if (initialLines.length > 0) {
|
|
295
|
+
const lastRow = initialLines.length - 1;
|
|
296
|
+
return [lastRow, cpLen(initialLines[lastRow])];
|
|
297
|
+
}
|
|
298
|
+
return [0, 0];
|
|
299
|
+
}
|
|
300
|
+
function offsetToLogicalPos(text, offset) {
|
|
301
|
+
let row = 0;
|
|
302
|
+
let col = 0;
|
|
303
|
+
let currentOffset = 0;
|
|
304
|
+
if (offset === 0) return [0, 0];
|
|
305
|
+
const lines = text.split("\n");
|
|
306
|
+
for (let i = 0; i < lines.length; i++) {
|
|
307
|
+
const line = lines[i];
|
|
308
|
+
const lineLength = cpLen(line);
|
|
309
|
+
const lineLengthWithNewline = lineLength + (i < lines.length - 1 ? 1 : 0);
|
|
310
|
+
if (offset <= currentOffset + lineLength) {
|
|
311
|
+
row = i;
|
|
312
|
+
col = offset - currentOffset;
|
|
313
|
+
return [row, col];
|
|
314
|
+
} else if (offset <= currentOffset + lineLengthWithNewline) {
|
|
315
|
+
row = i;
|
|
316
|
+
col = lineLength;
|
|
317
|
+
if (offset === currentOffset + lineLengthWithNewline && i < lines.length - 1) {
|
|
318
|
+
return [i + 1, 0];
|
|
319
|
+
}
|
|
320
|
+
return [row, col];
|
|
321
|
+
}
|
|
322
|
+
currentOffset += lineLengthWithNewline;
|
|
323
|
+
}
|
|
324
|
+
if (lines.length > 0) {
|
|
325
|
+
row = lines.length - 1;
|
|
326
|
+
col = cpLen(lines[row]);
|
|
327
|
+
} else {
|
|
328
|
+
row = 0;
|
|
329
|
+
col = 0;
|
|
330
|
+
}
|
|
331
|
+
return [row, col];
|
|
332
|
+
}
|
|
333
|
+
function logicalPosToOffset(lines, row, col) {
|
|
334
|
+
let offset = 0;
|
|
335
|
+
const actualRow = Math.min(row, lines.length - 1);
|
|
336
|
+
for (let i = 0; i < actualRow; i++) {
|
|
337
|
+
offset += cpLen(lines[i]) + 1;
|
|
338
|
+
}
|
|
339
|
+
if (actualRow >= 0 && actualRow < lines.length) {
|
|
340
|
+
offset += Math.min(col, cpLen(lines[actualRow]));
|
|
341
|
+
}
|
|
342
|
+
return offset;
|
|
343
|
+
}
|
|
344
|
+
function calculateLayout(logicalLines, viewportWidth) {
|
|
345
|
+
const visualLines = [];
|
|
346
|
+
const logicalToVisualMap = [];
|
|
347
|
+
const visualToLogicalMap = [];
|
|
348
|
+
logicalLines.forEach((logLine, logIndex) => {
|
|
349
|
+
logicalToVisualMap[logIndex] = [];
|
|
350
|
+
if (logLine.length === 0) {
|
|
351
|
+
logicalToVisualMap[logIndex].push([visualLines.length, 0]);
|
|
352
|
+
visualToLogicalMap.push([logIndex, 0]);
|
|
353
|
+
visualLines.push("");
|
|
354
|
+
} else {
|
|
355
|
+
let currentPosInLogLine = 0;
|
|
356
|
+
const codePointsInLogLine = toCodePoints(logLine);
|
|
357
|
+
while (currentPosInLogLine < codePointsInLogLine.length) {
|
|
358
|
+
let currentChunk = "";
|
|
359
|
+
let currentChunkVisualWidth = 0;
|
|
360
|
+
let numCodePointsInChunk = 0;
|
|
361
|
+
let lastWordBreakPoint = -1;
|
|
362
|
+
let numCodePointsAtLastWordBreak = 0;
|
|
363
|
+
for (let i = currentPosInLogLine; i < codePointsInLogLine.length; i++) {
|
|
364
|
+
const char = codePointsInLogLine[i];
|
|
365
|
+
const charVisualWidth = getCachedStringWidth(char);
|
|
366
|
+
if (currentChunkVisualWidth + charVisualWidth > viewportWidth) {
|
|
367
|
+
if (lastWordBreakPoint !== -1 && numCodePointsAtLastWordBreak > 0 && currentPosInLogLine + numCodePointsAtLastWordBreak < i) {
|
|
368
|
+
currentChunk = codePointsInLogLine.slice(
|
|
369
|
+
currentPosInLogLine,
|
|
370
|
+
currentPosInLogLine + numCodePointsAtLastWordBreak
|
|
371
|
+
).join("");
|
|
372
|
+
numCodePointsInChunk = numCodePointsAtLastWordBreak;
|
|
373
|
+
} else {
|
|
374
|
+
if (numCodePointsInChunk === 0 && charVisualWidth > viewportWidth) {
|
|
375
|
+
currentChunk = char;
|
|
376
|
+
numCodePointsInChunk = 1;
|
|
377
|
+
} else if (numCodePointsInChunk === 0 && charVisualWidth <= viewportWidth) {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
currentChunk += char;
|
|
383
|
+
currentChunkVisualWidth += charVisualWidth;
|
|
384
|
+
numCodePointsInChunk++;
|
|
385
|
+
if (char === " ") {
|
|
386
|
+
lastWordBreakPoint = i;
|
|
387
|
+
numCodePointsAtLastWordBreak = numCodePointsInChunk - 1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (numCodePointsInChunk === 0 && currentPosInLogLine < codePointsInLogLine.length) {
|
|
391
|
+
const firstChar = codePointsInLogLine[currentPosInLogLine];
|
|
392
|
+
currentChunk = firstChar;
|
|
393
|
+
numCodePointsInChunk = 1;
|
|
394
|
+
}
|
|
395
|
+
if (numCodePointsInChunk === 0 && currentPosInLogLine < codePointsInLogLine.length) {
|
|
396
|
+
currentChunk = codePointsInLogLine[currentPosInLogLine];
|
|
397
|
+
numCodePointsInChunk = 1;
|
|
398
|
+
}
|
|
399
|
+
logicalToVisualMap[logIndex].push([visualLines.length, currentPosInLogLine]);
|
|
400
|
+
visualToLogicalMap.push([logIndex, currentPosInLogLine]);
|
|
401
|
+
visualLines.push(currentChunk);
|
|
402
|
+
const logicalStartOfThisChunk = currentPosInLogLine;
|
|
403
|
+
currentPosInLogLine += numCodePointsInChunk;
|
|
404
|
+
if (logicalStartOfThisChunk + numCodePointsInChunk < codePointsInLogLine.length && currentPosInLogLine < codePointsInLogLine.length && // Redundant if previous is true, but safe
|
|
405
|
+
codePointsInLogLine[currentPosInLogLine] === " ") {
|
|
406
|
+
currentPosInLogLine++;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
if (logicalLines.length === 0 || logicalLines.length === 1 && logicalLines[0] === "") {
|
|
412
|
+
if (visualLines.length === 0) {
|
|
413
|
+
visualLines.push("");
|
|
414
|
+
if (!logicalToVisualMap[0]) logicalToVisualMap[0] = [];
|
|
415
|
+
logicalToVisualMap[0].push([0, 0]);
|
|
416
|
+
visualToLogicalMap.push([0, 0]);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
visualLines,
|
|
421
|
+
logicalToVisualMap,
|
|
422
|
+
visualToLogicalMap
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function calculateVisualCursorFromLayout(layout, logicalCursor) {
|
|
426
|
+
const { logicalToVisualMap, visualLines } = layout;
|
|
427
|
+
const [logicalRow, logicalCol] = logicalCursor;
|
|
428
|
+
const segmentsForLogicalLine = logicalToVisualMap[logicalRow];
|
|
429
|
+
if (!segmentsForLogicalLine || segmentsForLogicalLine.length === 0) {
|
|
430
|
+
return [0, 0];
|
|
431
|
+
}
|
|
432
|
+
let targetSegmentIndex = segmentsForLogicalLine.findIndex(([, startColInLogical2], index) => {
|
|
433
|
+
const nextStartColInLogical = index + 1 < segmentsForLogicalLine.length ? segmentsForLogicalLine[index + 1][1] : Infinity;
|
|
434
|
+
return logicalCol >= startColInLogical2 && logicalCol < nextStartColInLogical;
|
|
435
|
+
});
|
|
436
|
+
if (targetSegmentIndex === -1) {
|
|
437
|
+
if (logicalCol === 0) {
|
|
438
|
+
targetSegmentIndex = 0;
|
|
439
|
+
} else {
|
|
440
|
+
targetSegmentIndex = segmentsForLogicalLine.length - 1;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const [visualRow, startColInLogical] = segmentsForLogicalLine[targetSegmentIndex];
|
|
444
|
+
const visualCol = logicalCol - startColInLogical;
|
|
445
|
+
const clampedVisualCol = Math.min(visualCol, cpLen(visualLines[visualRow] ?? ""));
|
|
446
|
+
return [visualRow, clampedVisualCol];
|
|
447
|
+
}
|
|
448
|
+
const historyLimit = 100;
|
|
449
|
+
const pushUndo = (currentState) => {
|
|
450
|
+
const snapshot = {
|
|
451
|
+
lines: [...currentState.lines],
|
|
452
|
+
cursorRow: currentState.cursorRow,
|
|
453
|
+
cursorCol: currentState.cursorCol
|
|
454
|
+
};
|
|
455
|
+
const newStack = [...currentState.undoStack, snapshot];
|
|
456
|
+
if (newStack.length > historyLimit) {
|
|
457
|
+
newStack.shift();
|
|
458
|
+
}
|
|
459
|
+
return { ...currentState, undoStack: newStack, redoStack: [] };
|
|
460
|
+
};
|
|
461
|
+
function textBufferReducerLogic(state, action, options = {}) {
|
|
462
|
+
const pushUndoLocal = pushUndo;
|
|
463
|
+
const currentLine = (r) => state.lines[r] ?? "";
|
|
464
|
+
const currentLineLen = (r) => cpLen(currentLine(r));
|
|
465
|
+
switch (action.type) {
|
|
466
|
+
case "set_text": {
|
|
467
|
+
let nextState = state;
|
|
468
|
+
if (action.pushToUndo !== false) {
|
|
469
|
+
nextState = pushUndoLocal(state);
|
|
470
|
+
}
|
|
471
|
+
const newContentLines = action.payload.replace(/\r\n?/g, "\n").split("\n");
|
|
472
|
+
const lines = newContentLines.length === 0 ? [""] : newContentLines;
|
|
473
|
+
const lastNewLineIndex = lines.length - 1;
|
|
474
|
+
return {
|
|
475
|
+
...nextState,
|
|
476
|
+
lines,
|
|
477
|
+
cursorRow: lastNewLineIndex,
|
|
478
|
+
cursorCol: cpLen(lines[lastNewLineIndex] ?? ""),
|
|
479
|
+
preferredCol: null
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
case "insert": {
|
|
483
|
+
let payload = action.payload;
|
|
484
|
+
if (options.singleLine) {
|
|
485
|
+
payload = payload.replace(/[\r\n]/g, "");
|
|
486
|
+
}
|
|
487
|
+
if (options.inputFilter) {
|
|
488
|
+
payload = options.inputFilter(payload);
|
|
489
|
+
}
|
|
490
|
+
if (payload.length === 0) {
|
|
491
|
+
return state;
|
|
492
|
+
}
|
|
493
|
+
const nextState = pushUndoLocal(state);
|
|
494
|
+
const newLines = [...nextState.lines];
|
|
495
|
+
let newCursorRow = nextState.cursorRow;
|
|
496
|
+
let newCursorCol = nextState.cursorCol;
|
|
497
|
+
const currentLine2 = (r) => newLines[r] ?? "";
|
|
498
|
+
const str = stripUnsafeCharacters(payload.replace(/\r\n/g, "\n").replace(/\r/g, "\n"));
|
|
499
|
+
const parts = str.split("\n");
|
|
500
|
+
const lineContent = currentLine2(newCursorRow);
|
|
501
|
+
const before = cpSlice(lineContent, 0, newCursorCol);
|
|
502
|
+
const after = cpSlice(lineContent, newCursorCol);
|
|
503
|
+
if (parts.length > 1) {
|
|
504
|
+
newLines[newCursorRow] = before + parts[0];
|
|
505
|
+
const remainingParts = parts.slice(1);
|
|
506
|
+
const lastPartOriginal = remainingParts.pop() ?? "";
|
|
507
|
+
newLines.splice(newCursorRow + 1, 0, ...remainingParts);
|
|
508
|
+
newLines.splice(newCursorRow + parts.length - 1, 0, lastPartOriginal + after);
|
|
509
|
+
newCursorRow = newCursorRow + parts.length - 1;
|
|
510
|
+
newCursorCol = cpLen(lastPartOriginal);
|
|
511
|
+
} else {
|
|
512
|
+
newLines[newCursorRow] = before + parts[0] + after;
|
|
513
|
+
newCursorCol = cpLen(before) + cpLen(parts[0]);
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
...nextState,
|
|
517
|
+
lines: newLines,
|
|
518
|
+
cursorRow: newCursorRow,
|
|
519
|
+
cursorCol: newCursorCol,
|
|
520
|
+
preferredCol: null
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
case "backspace": {
|
|
524
|
+
if (state.cursorCol === 0 && state.cursorRow === 0) return state;
|
|
525
|
+
const nextState = pushUndoLocal(state);
|
|
526
|
+
const newLines = [...nextState.lines];
|
|
527
|
+
let newCursorRow = nextState.cursorRow;
|
|
528
|
+
let newCursorCol = nextState.cursorCol;
|
|
529
|
+
const currentLine2 = (r) => newLines[r] ?? "";
|
|
530
|
+
if (newCursorCol > 0) {
|
|
531
|
+
const lineContent = currentLine2(newCursorRow);
|
|
532
|
+
newLines[newCursorRow] = cpSlice(lineContent, 0, newCursorCol - 1) + cpSlice(lineContent, newCursorCol);
|
|
533
|
+
newCursorCol--;
|
|
534
|
+
} else if (newCursorRow > 0) {
|
|
535
|
+
const prevLineContent = currentLine2(newCursorRow - 1);
|
|
536
|
+
const currentLineContentVal = currentLine2(newCursorRow);
|
|
537
|
+
const newCol = cpLen(prevLineContent);
|
|
538
|
+
newLines[newCursorRow - 1] = prevLineContent + currentLineContentVal;
|
|
539
|
+
newLines.splice(newCursorRow, 1);
|
|
540
|
+
newCursorRow--;
|
|
541
|
+
newCursorCol = newCol;
|
|
542
|
+
}
|
|
543
|
+
return {
|
|
544
|
+
...nextState,
|
|
545
|
+
lines: newLines,
|
|
546
|
+
cursorRow: newCursorRow,
|
|
547
|
+
cursorCol: newCursorCol,
|
|
548
|
+
preferredCol: null
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
case "set_viewport": {
|
|
552
|
+
const { width, height } = action.payload;
|
|
553
|
+
if (width === state.viewportWidth && height === state.viewportHeight) {
|
|
554
|
+
return state;
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
...state,
|
|
558
|
+
viewportWidth: width,
|
|
559
|
+
viewportHeight: height
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
case "move": {
|
|
563
|
+
const { dir } = action.payload;
|
|
564
|
+
const { cursorRow, cursorCol, lines, visualLayout, preferredCol } = state;
|
|
565
|
+
if (dir === "left" || dir === "right" || dir === "up" || dir === "down" || dir === "home" || dir === "end") {
|
|
566
|
+
const visualCursor = calculateVisualCursorFromLayout(visualLayout, [
|
|
567
|
+
cursorRow,
|
|
568
|
+
cursorCol
|
|
569
|
+
]);
|
|
570
|
+
const { visualLines, visualToLogicalMap } = visualLayout;
|
|
571
|
+
let newVisualRow = visualCursor[0];
|
|
572
|
+
let newVisualCol = visualCursor[1];
|
|
573
|
+
let newPreferredCol = preferredCol;
|
|
574
|
+
const currentVisLineLen = cpLen(visualLines[newVisualRow] ?? "");
|
|
575
|
+
switch (dir) {
|
|
576
|
+
case "left":
|
|
577
|
+
newPreferredCol = null;
|
|
578
|
+
if (newVisualCol > 0) {
|
|
579
|
+
newVisualCol--;
|
|
580
|
+
} else if (newVisualRow > 0) {
|
|
581
|
+
newVisualRow--;
|
|
582
|
+
newVisualCol = cpLen(visualLines[newVisualRow] ?? "");
|
|
583
|
+
}
|
|
584
|
+
break;
|
|
585
|
+
case "right":
|
|
586
|
+
newPreferredCol = null;
|
|
587
|
+
if (newVisualCol < currentVisLineLen) {
|
|
588
|
+
newVisualCol++;
|
|
589
|
+
} else if (newVisualRow < visualLines.length - 1) {
|
|
590
|
+
newVisualRow++;
|
|
591
|
+
newVisualCol = 0;
|
|
592
|
+
}
|
|
593
|
+
break;
|
|
594
|
+
case "up":
|
|
595
|
+
if (newVisualRow > 0) {
|
|
596
|
+
if (newPreferredCol === null) newPreferredCol = newVisualCol;
|
|
597
|
+
newVisualRow--;
|
|
598
|
+
newVisualCol = clamp(
|
|
599
|
+
newPreferredCol,
|
|
600
|
+
0,
|
|
601
|
+
cpLen(visualLines[newVisualRow] ?? "")
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
case "down":
|
|
606
|
+
if (newVisualRow < visualLines.length - 1) {
|
|
607
|
+
if (newPreferredCol === null) newPreferredCol = newVisualCol;
|
|
608
|
+
newVisualRow++;
|
|
609
|
+
newVisualCol = clamp(
|
|
610
|
+
newPreferredCol,
|
|
611
|
+
0,
|
|
612
|
+
cpLen(visualLines[newVisualRow] ?? "")
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
case "home":
|
|
617
|
+
newPreferredCol = null;
|
|
618
|
+
newVisualCol = 0;
|
|
619
|
+
break;
|
|
620
|
+
case "end":
|
|
621
|
+
newPreferredCol = null;
|
|
622
|
+
newVisualCol = currentVisLineLen;
|
|
623
|
+
break;
|
|
624
|
+
default:
|
|
625
|
+
return state;
|
|
626
|
+
}
|
|
627
|
+
if (visualToLogicalMap[newVisualRow]) {
|
|
628
|
+
const [logRow, logStartCol] = visualToLogicalMap[newVisualRow];
|
|
629
|
+
return {
|
|
630
|
+
...state,
|
|
631
|
+
cursorRow: logRow,
|
|
632
|
+
cursorCol: clamp(logStartCol + newVisualCol, 0, cpLen(lines[logRow] ?? "")),
|
|
633
|
+
preferredCol: newPreferredCol
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
return state;
|
|
637
|
+
}
|
|
638
|
+
switch (dir) {
|
|
639
|
+
case "wordLeft": {
|
|
640
|
+
if (cursorCol === 0 && cursorRow === 0) return state;
|
|
641
|
+
let newCursorRow = cursorRow;
|
|
642
|
+
let newCursorCol = cursorCol;
|
|
643
|
+
if (cursorCol === 0) {
|
|
644
|
+
newCursorRow--;
|
|
645
|
+
newCursorCol = cpLen(lines[newCursorRow] ?? "");
|
|
646
|
+
} else {
|
|
647
|
+
const lineContent = lines[cursorRow] ?? "";
|
|
648
|
+
newCursorCol = findPrevWordBoundary(lineContent, cursorCol);
|
|
649
|
+
}
|
|
650
|
+
return {
|
|
651
|
+
...state,
|
|
652
|
+
cursorRow: newCursorRow,
|
|
653
|
+
cursorCol: newCursorCol,
|
|
654
|
+
preferredCol: null
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
case "wordRight": {
|
|
658
|
+
const lineContent = lines[cursorRow] ?? "";
|
|
659
|
+
if (cursorRow === lines.length - 1 && cursorCol === cpLen(lineContent)) {
|
|
660
|
+
return state;
|
|
661
|
+
}
|
|
662
|
+
let newCursorRow = cursorRow;
|
|
663
|
+
let newCursorCol = cursorCol;
|
|
664
|
+
const lineLen = cpLen(lineContent);
|
|
665
|
+
if (cursorCol >= lineLen) {
|
|
666
|
+
newCursorRow++;
|
|
667
|
+
newCursorCol = 0;
|
|
668
|
+
} else {
|
|
669
|
+
newCursorCol = findNextWordBoundary(lineContent, cursorCol);
|
|
670
|
+
}
|
|
671
|
+
return {
|
|
672
|
+
...state,
|
|
673
|
+
cursorRow: newCursorRow,
|
|
674
|
+
cursorCol: newCursorCol,
|
|
675
|
+
preferredCol: null
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
default:
|
|
679
|
+
return state;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
case "set_cursor": {
|
|
683
|
+
return {
|
|
684
|
+
...state,
|
|
685
|
+
...action.payload
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
case "delete": {
|
|
689
|
+
const { cursorRow, cursorCol, lines } = state;
|
|
690
|
+
const lineContent = currentLine(cursorRow);
|
|
691
|
+
if (cursorCol < currentLineLen(cursorRow)) {
|
|
692
|
+
const nextState = pushUndoLocal(state);
|
|
693
|
+
const newLines = [...nextState.lines];
|
|
694
|
+
newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol) + cpSlice(lineContent, cursorCol + 1);
|
|
695
|
+
return {
|
|
696
|
+
...nextState,
|
|
697
|
+
lines: newLines,
|
|
698
|
+
preferredCol: null
|
|
699
|
+
};
|
|
700
|
+
} else if (cursorRow < lines.length - 1) {
|
|
701
|
+
const nextState = pushUndoLocal(state);
|
|
702
|
+
const nextLineContent = currentLine(cursorRow + 1);
|
|
703
|
+
const newLines = [...nextState.lines];
|
|
704
|
+
newLines[cursorRow] = lineContent + nextLineContent;
|
|
705
|
+
newLines.splice(cursorRow + 1, 1);
|
|
706
|
+
return {
|
|
707
|
+
...nextState,
|
|
708
|
+
lines: newLines,
|
|
709
|
+
preferredCol: null
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
return state;
|
|
713
|
+
}
|
|
714
|
+
case "delete_word_left": {
|
|
715
|
+
const { cursorRow, cursorCol } = state;
|
|
716
|
+
if (cursorCol === 0 && cursorRow === 0) return state;
|
|
717
|
+
const nextState = pushUndoLocal(state);
|
|
718
|
+
const newLines = [...nextState.lines];
|
|
719
|
+
let newCursorRow = cursorRow;
|
|
720
|
+
let newCursorCol = cursorCol;
|
|
721
|
+
if (newCursorCol > 0) {
|
|
722
|
+
const lineContent = currentLine(newCursorRow);
|
|
723
|
+
const prevWordStart = findPrevWordStartInLine(lineContent, newCursorCol);
|
|
724
|
+
const start = prevWordStart === null ? 0 : prevWordStart;
|
|
725
|
+
newLines[newCursorRow] = cpSlice(lineContent, 0, start) + cpSlice(lineContent, newCursorCol);
|
|
726
|
+
newCursorCol = start;
|
|
727
|
+
} else {
|
|
728
|
+
const prevLineContent = currentLine(cursorRow - 1);
|
|
729
|
+
const currentLineContentVal = currentLine(cursorRow);
|
|
730
|
+
const newCol = cpLen(prevLineContent);
|
|
731
|
+
newLines[cursorRow - 1] = prevLineContent + currentLineContentVal;
|
|
732
|
+
newLines.splice(cursorRow, 1);
|
|
733
|
+
newCursorRow--;
|
|
734
|
+
newCursorCol = newCol;
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
...nextState,
|
|
738
|
+
lines: newLines,
|
|
739
|
+
cursorRow: newCursorRow,
|
|
740
|
+
cursorCol: newCursorCol,
|
|
741
|
+
preferredCol: null
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
case "delete_word_right": {
|
|
745
|
+
const { cursorRow, cursorCol, lines } = state;
|
|
746
|
+
const lineContent = currentLine(cursorRow);
|
|
747
|
+
const lineLen = cpLen(lineContent);
|
|
748
|
+
if (cursorCol >= lineLen && cursorRow === lines.length - 1) {
|
|
749
|
+
return state;
|
|
750
|
+
}
|
|
751
|
+
const nextState = pushUndoLocal(state);
|
|
752
|
+
const newLines = [...nextState.lines];
|
|
753
|
+
if (cursorCol >= lineLen) {
|
|
754
|
+
const nextLineContent = currentLine(cursorRow + 1);
|
|
755
|
+
newLines[cursorRow] = lineContent + nextLineContent;
|
|
756
|
+
newLines.splice(cursorRow + 1, 1);
|
|
757
|
+
} else {
|
|
758
|
+
const nextWordStart = findNextWordStartInLine(lineContent, cursorCol);
|
|
759
|
+
const end = nextWordStart === null ? lineLen : nextWordStart;
|
|
760
|
+
newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol) + cpSlice(lineContent, end);
|
|
761
|
+
}
|
|
762
|
+
return {
|
|
763
|
+
...nextState,
|
|
764
|
+
lines: newLines,
|
|
765
|
+
preferredCol: null
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
case "kill_line_right": {
|
|
769
|
+
const { cursorRow, cursorCol, lines } = state;
|
|
770
|
+
const lineContent = currentLine(cursorRow);
|
|
771
|
+
if (cursorCol < currentLineLen(cursorRow)) {
|
|
772
|
+
const nextState = pushUndoLocal(state);
|
|
773
|
+
const newLines = [...nextState.lines];
|
|
774
|
+
newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol);
|
|
775
|
+
return {
|
|
776
|
+
...nextState,
|
|
777
|
+
lines: newLines
|
|
778
|
+
};
|
|
779
|
+
} else if (cursorRow < lines.length - 1) {
|
|
780
|
+
const nextState = pushUndoLocal(state);
|
|
781
|
+
const nextLineContent = currentLine(cursorRow + 1);
|
|
782
|
+
const newLines = [...nextState.lines];
|
|
783
|
+
newLines[cursorRow] = lineContent + nextLineContent;
|
|
784
|
+
newLines.splice(cursorRow + 1, 1);
|
|
785
|
+
return {
|
|
786
|
+
...nextState,
|
|
787
|
+
lines: newLines,
|
|
788
|
+
preferredCol: null
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
return state;
|
|
792
|
+
}
|
|
793
|
+
case "kill_line_left": {
|
|
794
|
+
const { cursorRow, cursorCol } = state;
|
|
795
|
+
if (cursorCol > 0) {
|
|
796
|
+
const nextState = pushUndoLocal(state);
|
|
797
|
+
const lineContent = currentLine(cursorRow);
|
|
798
|
+
const newLines = [...nextState.lines];
|
|
799
|
+
newLines[cursorRow] = cpSlice(lineContent, cursorCol);
|
|
800
|
+
return {
|
|
801
|
+
...nextState,
|
|
802
|
+
lines: newLines,
|
|
803
|
+
cursorCol: 0,
|
|
804
|
+
preferredCol: null
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
return state;
|
|
808
|
+
}
|
|
809
|
+
case "undo": {
|
|
810
|
+
const stateToRestore = state.undoStack[state.undoStack.length - 1];
|
|
811
|
+
if (!stateToRestore) return state;
|
|
812
|
+
const currentSnapshot = {
|
|
813
|
+
lines: [...state.lines],
|
|
814
|
+
cursorRow: state.cursorRow,
|
|
815
|
+
cursorCol: state.cursorCol
|
|
816
|
+
};
|
|
817
|
+
return {
|
|
818
|
+
...state,
|
|
819
|
+
...stateToRestore,
|
|
820
|
+
undoStack: state.undoStack.slice(0, -1),
|
|
821
|
+
redoStack: [...state.redoStack, currentSnapshot]
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
case "redo": {
|
|
825
|
+
const stateToRestore = state.redoStack[state.redoStack.length - 1];
|
|
826
|
+
if (!stateToRestore) return state;
|
|
827
|
+
const currentSnapshot = {
|
|
828
|
+
lines: [...state.lines],
|
|
829
|
+
cursorRow: state.cursorRow,
|
|
830
|
+
cursorCol: state.cursorCol
|
|
831
|
+
};
|
|
832
|
+
return {
|
|
833
|
+
...state,
|
|
834
|
+
...stateToRestore,
|
|
835
|
+
redoStack: state.redoStack.slice(0, -1),
|
|
836
|
+
undoStack: [...state.undoStack, currentSnapshot]
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
case "replace_range": {
|
|
840
|
+
const { startRow, startCol, endRow, endCol, text } = action.payload;
|
|
841
|
+
const nextState = pushUndoLocal(state);
|
|
842
|
+
return replaceRangeInternal(nextState, startRow, startCol, endRow, endCol, text);
|
|
843
|
+
}
|
|
844
|
+
case "move_to_offset": {
|
|
845
|
+
const { offset } = action.payload;
|
|
846
|
+
const [newRow, newCol] = offsetToLogicalPos(state.lines.join("\n"), offset);
|
|
847
|
+
return {
|
|
848
|
+
...state,
|
|
849
|
+
cursorRow: newRow,
|
|
850
|
+
cursorCol: newCol,
|
|
851
|
+
preferredCol: null
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
case "create_undo_snapshot": {
|
|
855
|
+
return pushUndoLocal(state);
|
|
856
|
+
}
|
|
857
|
+
default:
|
|
858
|
+
return state;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function textBufferReducer(state, action, options = {}) {
|
|
862
|
+
const newState = textBufferReducerLogic(state, action, options);
|
|
863
|
+
if (newState.lines !== state.lines || newState.viewportWidth !== state.viewportWidth) {
|
|
864
|
+
return {
|
|
865
|
+
...newState,
|
|
866
|
+
visualLayout: calculateLayout(newState.lines, newState.viewportWidth)
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
return newState;
|
|
870
|
+
}
|
|
871
|
+
function useTextBuffer({
|
|
872
|
+
initialText = "",
|
|
873
|
+
initialCursorOffset = 0,
|
|
874
|
+
viewport,
|
|
875
|
+
onChange,
|
|
876
|
+
inputFilter,
|
|
877
|
+
singleLine = false
|
|
878
|
+
}) {
|
|
879
|
+
const initialState = useMemo(() => {
|
|
880
|
+
const lines2 = initialText.split("\n");
|
|
881
|
+
const [initialCursorRow, initialCursorCol] = calculateInitialCursorPosition(
|
|
882
|
+
lines2.length === 0 ? [""] : lines2,
|
|
883
|
+
initialCursorOffset
|
|
884
|
+
);
|
|
885
|
+
const visualLayout2 = calculateLayout(lines2.length === 0 ? [""] : lines2, viewport.width);
|
|
886
|
+
return {
|
|
887
|
+
lines: lines2.length === 0 ? [""] : lines2,
|
|
888
|
+
cursorRow: initialCursorRow,
|
|
889
|
+
cursorCol: initialCursorCol,
|
|
890
|
+
preferredCol: null,
|
|
891
|
+
undoStack: [],
|
|
892
|
+
redoStack: [],
|
|
893
|
+
viewportWidth: viewport.width,
|
|
894
|
+
viewportHeight: viewport.height,
|
|
895
|
+
visualLayout: visualLayout2
|
|
896
|
+
};
|
|
897
|
+
}, [initialText, initialCursorOffset, viewport.width, viewport.height]);
|
|
898
|
+
const [state, dispatch] = useReducer(
|
|
899
|
+
(s, a) => textBufferReducer(s, a, { inputFilter, singleLine }),
|
|
900
|
+
initialState
|
|
901
|
+
);
|
|
902
|
+
const { lines, cursorRow, cursorCol, preferredCol, visualLayout } = state;
|
|
903
|
+
const text = useMemo(() => lines.join("\n"), [lines]);
|
|
904
|
+
const visualCursor = useMemo(
|
|
905
|
+
() => calculateVisualCursorFromLayout(visualLayout, [cursorRow, cursorCol]),
|
|
906
|
+
[visualLayout, cursorRow, cursorCol]
|
|
907
|
+
);
|
|
908
|
+
const { visualLines, visualToLogicalMap } = visualLayout;
|
|
909
|
+
const [visualScrollRow, setVisualScrollRow] = useState(0);
|
|
910
|
+
useEffect(() => {
|
|
911
|
+
if (onChange) {
|
|
912
|
+
onChange(text);
|
|
913
|
+
}
|
|
914
|
+
}, [text, onChange]);
|
|
915
|
+
useEffect(() => {
|
|
916
|
+
dispatch({
|
|
917
|
+
type: "set_viewport",
|
|
918
|
+
payload: { width: viewport.width, height: viewport.height }
|
|
919
|
+
});
|
|
920
|
+
}, [viewport.width, viewport.height]);
|
|
921
|
+
useEffect(() => {
|
|
922
|
+
const { height } = viewport;
|
|
923
|
+
const totalVisualLines = visualLines.length;
|
|
924
|
+
const maxScrollStart = Math.max(0, totalVisualLines - height);
|
|
925
|
+
let newVisualScrollRow = visualScrollRow;
|
|
926
|
+
if (visualCursor[0] < visualScrollRow) {
|
|
927
|
+
newVisualScrollRow = visualCursor[0];
|
|
928
|
+
} else if (visualCursor[0] >= visualScrollRow + height) {
|
|
929
|
+
newVisualScrollRow = visualCursor[0] - height + 1;
|
|
930
|
+
}
|
|
931
|
+
newVisualScrollRow = clamp(newVisualScrollRow, 0, maxScrollStart);
|
|
932
|
+
if (newVisualScrollRow !== visualScrollRow) {
|
|
933
|
+
setVisualScrollRow(newVisualScrollRow);
|
|
934
|
+
}
|
|
935
|
+
}, [visualCursor, visualScrollRow, viewport, visualLines.length]);
|
|
936
|
+
const insert = useCallback(
|
|
937
|
+
(ch, { paste: _paste = false } = {}) => {
|
|
938
|
+
if (!singleLine && /[\n\r]/.test(ch)) {
|
|
939
|
+
dispatch({ type: "insert", payload: ch });
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
let currentText = "";
|
|
943
|
+
for (const char of toCodePoints(ch)) {
|
|
944
|
+
if (char.codePointAt(0) === 127) {
|
|
945
|
+
if (currentText.length > 0) {
|
|
946
|
+
dispatch({ type: "insert", payload: currentText });
|
|
947
|
+
currentText = "";
|
|
948
|
+
}
|
|
949
|
+
dispatch({ type: "backspace" });
|
|
950
|
+
} else {
|
|
951
|
+
currentText += char;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (currentText.length > 0) {
|
|
955
|
+
dispatch({ type: "insert", payload: currentText });
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
[singleLine]
|
|
959
|
+
);
|
|
960
|
+
const newline = useCallback(() => {
|
|
961
|
+
if (singleLine) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
dispatch({ type: "insert", payload: "\n" });
|
|
965
|
+
}, [singleLine]);
|
|
966
|
+
const backspace = useCallback(() => {
|
|
967
|
+
dispatch({ type: "backspace" });
|
|
968
|
+
}, []);
|
|
969
|
+
const del = useCallback(() => {
|
|
970
|
+
dispatch({ type: "delete" });
|
|
971
|
+
}, []);
|
|
972
|
+
const move = useCallback(
|
|
973
|
+
(dir) => {
|
|
974
|
+
dispatch({ type: "move", payload: { dir } });
|
|
975
|
+
},
|
|
976
|
+
[dispatch]
|
|
977
|
+
);
|
|
978
|
+
const undo = useCallback(() => {
|
|
979
|
+
dispatch({ type: "undo" });
|
|
980
|
+
}, []);
|
|
981
|
+
const redo = useCallback(() => {
|
|
982
|
+
dispatch({ type: "redo" });
|
|
983
|
+
}, []);
|
|
984
|
+
const setText = useCallback((newText) => {
|
|
985
|
+
dispatch({ type: "set_text", payload: newText });
|
|
986
|
+
}, []);
|
|
987
|
+
const deleteWordLeft = useCallback(() => {
|
|
988
|
+
dispatch({ type: "delete_word_left" });
|
|
989
|
+
}, []);
|
|
990
|
+
const deleteWordRight = useCallback(() => {
|
|
991
|
+
dispatch({ type: "delete_word_right" });
|
|
992
|
+
}, []);
|
|
993
|
+
const killLineRight = useCallback(() => {
|
|
994
|
+
dispatch({ type: "kill_line_right" });
|
|
995
|
+
}, []);
|
|
996
|
+
const killLineLeft = useCallback(() => {
|
|
997
|
+
dispatch({ type: "kill_line_left" });
|
|
998
|
+
}, []);
|
|
999
|
+
const setViewport = useCallback((width, height) => {
|
|
1000
|
+
dispatch({ type: "set_viewport", payload: { width, height } });
|
|
1001
|
+
}, []);
|
|
1002
|
+
const handleInput = useCallback(
|
|
1003
|
+
(key) => {
|
|
1004
|
+
const { sequence: input } = key;
|
|
1005
|
+
if (key.paste) {
|
|
1006
|
+
insert(input, { paste: key.paste });
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (!singleLine && (key.name === "return" || input === "\r" || input === "\n" || input === "\\r"))
|
|
1010
|
+
newline();
|
|
1011
|
+
else if (key.name === "left" && !key.meta && !key.ctrl) move("left");
|
|
1012
|
+
else if (key.ctrl && key.name === "b") move("left");
|
|
1013
|
+
else if (key.name === "right" && !key.meta && !key.ctrl) move("right");
|
|
1014
|
+
else if (key.ctrl && key.name === "f") move("right");
|
|
1015
|
+
else if (key.name === "up") move("up");
|
|
1016
|
+
else if (key.name === "down") move("down");
|
|
1017
|
+
else if ((key.ctrl || key.meta) && key.name === "left") move("wordLeft");
|
|
1018
|
+
else if (key.meta && key.name === "b") move("wordLeft");
|
|
1019
|
+
else if ((key.ctrl || key.meta) && key.name === "right") move("wordRight");
|
|
1020
|
+
else if (key.meta && key.name === "f") move("wordRight");
|
|
1021
|
+
else if (key.name === "home") move("home");
|
|
1022
|
+
else if (key.ctrl && key.name === "a") move("home");
|
|
1023
|
+
else if (key.name === "end") move("end");
|
|
1024
|
+
else if (key.ctrl && key.name === "e") move("end");
|
|
1025
|
+
else if (key.ctrl && key.name === "w") deleteWordLeft();
|
|
1026
|
+
else if ((key.meta || key.ctrl) && (key.name === "backspace" || input === "\x7F"))
|
|
1027
|
+
deleteWordLeft();
|
|
1028
|
+
else if ((key.meta || key.ctrl) && key.name === "delete") deleteWordRight();
|
|
1029
|
+
else if (key.name === "backspace" || input === "\x7F" || key.ctrl && key.name === "h")
|
|
1030
|
+
backspace();
|
|
1031
|
+
else if (key.name === "delete" || key.ctrl && key.name === "d") del();
|
|
1032
|
+
else if (key.ctrl && !key.shift && key.name === "z") undo();
|
|
1033
|
+
else if (key.ctrl && key.shift && key.name === "z") redo();
|
|
1034
|
+
else if (key.insertable) {
|
|
1035
|
+
insert(input, { paste: key.paste });
|
|
1036
|
+
}
|
|
1037
|
+
},
|
|
1038
|
+
[
|
|
1039
|
+
newline,
|
|
1040
|
+
move,
|
|
1041
|
+
deleteWordLeft,
|
|
1042
|
+
deleteWordRight,
|
|
1043
|
+
backspace,
|
|
1044
|
+
del,
|
|
1045
|
+
insert,
|
|
1046
|
+
undo,
|
|
1047
|
+
redo,
|
|
1048
|
+
singleLine
|
|
1049
|
+
]
|
|
1050
|
+
);
|
|
1051
|
+
const renderedVisualLines = useMemo(
|
|
1052
|
+
() => visualLines.slice(visualScrollRow, visualScrollRow + viewport.height),
|
|
1053
|
+
[visualLines, visualScrollRow, viewport.height]
|
|
1054
|
+
);
|
|
1055
|
+
const replaceRange = useCallback(
|
|
1056
|
+
(startRow, startCol, endRow, endCol, text2) => {
|
|
1057
|
+
dispatch({
|
|
1058
|
+
type: "replace_range",
|
|
1059
|
+
payload: { startRow, startCol, endRow, endCol, text: text2 }
|
|
1060
|
+
});
|
|
1061
|
+
},
|
|
1062
|
+
[]
|
|
1063
|
+
);
|
|
1064
|
+
const replaceRangeByOffset = useCallback(
|
|
1065
|
+
(startOffset, endOffset, replacementText) => {
|
|
1066
|
+
const [startRow, startCol] = offsetToLogicalPos(text, startOffset);
|
|
1067
|
+
const [endRow, endCol] = offsetToLogicalPos(text, endOffset);
|
|
1068
|
+
replaceRange(startRow, startCol, endRow, endCol, replacementText);
|
|
1069
|
+
},
|
|
1070
|
+
[text, replaceRange]
|
|
1071
|
+
);
|
|
1072
|
+
const moveToOffset = useCallback((offset) => {
|
|
1073
|
+
dispatch({ type: "move_to_offset", payload: { offset } });
|
|
1074
|
+
}, []);
|
|
1075
|
+
const moveToVisualPosition = useCallback(
|
|
1076
|
+
(visRow, visCol) => {
|
|
1077
|
+
const { visualLines: visualLines2, visualToLogicalMap: visualToLogicalMap2 } = visualLayout;
|
|
1078
|
+
const clampedVisRow = Math.max(0, Math.min(visRow, visualLines2.length - 1));
|
|
1079
|
+
const visualLine = visualLines2[clampedVisRow] || "";
|
|
1080
|
+
if (visualToLogicalMap2[clampedVisRow]) {
|
|
1081
|
+
const [logRow, logStartCol] = visualToLogicalMap2[clampedVisRow];
|
|
1082
|
+
const codePoints = toCodePoints(visualLine);
|
|
1083
|
+
let currentVisX = 0;
|
|
1084
|
+
let charOffset = 0;
|
|
1085
|
+
for (const char of codePoints) {
|
|
1086
|
+
const charWidth = getCachedStringWidth(char);
|
|
1087
|
+
if (visCol < currentVisX + charWidth) {
|
|
1088
|
+
if (charWidth > 1 && visCol >= currentVisX + charWidth / 2) {
|
|
1089
|
+
charOffset++;
|
|
1090
|
+
}
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1093
|
+
currentVisX += charWidth;
|
|
1094
|
+
charOffset++;
|
|
1095
|
+
}
|
|
1096
|
+
charOffset = Math.min(charOffset, codePoints.length);
|
|
1097
|
+
const newCursorRow = logRow;
|
|
1098
|
+
const newCursorCol = logStartCol + charOffset;
|
|
1099
|
+
dispatch({
|
|
1100
|
+
type: "set_cursor",
|
|
1101
|
+
payload: {
|
|
1102
|
+
cursorRow: newCursorRow,
|
|
1103
|
+
cursorCol: newCursorCol,
|
|
1104
|
+
preferredCol: charOffset
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
},
|
|
1109
|
+
[visualLayout]
|
|
1110
|
+
);
|
|
1111
|
+
const getOffset = useCallback(
|
|
1112
|
+
() => logicalPosToOffset(lines, cursorRow, cursorCol),
|
|
1113
|
+
[lines, cursorRow, cursorCol]
|
|
1114
|
+
);
|
|
1115
|
+
const returnValue = useMemo(
|
|
1116
|
+
() => ({
|
|
1117
|
+
lines,
|
|
1118
|
+
text,
|
|
1119
|
+
cursor: [cursorRow, cursorCol],
|
|
1120
|
+
preferredCol,
|
|
1121
|
+
allVisualLines: visualLines,
|
|
1122
|
+
viewportVisualLines: renderedVisualLines,
|
|
1123
|
+
visualCursor,
|
|
1124
|
+
visualScrollRow,
|
|
1125
|
+
visualToLogicalMap,
|
|
1126
|
+
setText,
|
|
1127
|
+
insert,
|
|
1128
|
+
newline,
|
|
1129
|
+
backspace,
|
|
1130
|
+
del,
|
|
1131
|
+
move,
|
|
1132
|
+
undo,
|
|
1133
|
+
redo,
|
|
1134
|
+
replaceRange,
|
|
1135
|
+
replaceRangeByOffset,
|
|
1136
|
+
moveToOffset,
|
|
1137
|
+
getOffset,
|
|
1138
|
+
moveToVisualPosition,
|
|
1139
|
+
deleteWordLeft,
|
|
1140
|
+
deleteWordRight,
|
|
1141
|
+
killLineRight,
|
|
1142
|
+
killLineLeft,
|
|
1143
|
+
handleInput,
|
|
1144
|
+
setViewport
|
|
1145
|
+
}),
|
|
1146
|
+
[
|
|
1147
|
+
lines,
|
|
1148
|
+
text,
|
|
1149
|
+
cursorRow,
|
|
1150
|
+
cursorCol,
|
|
1151
|
+
preferredCol,
|
|
1152
|
+
visualLines,
|
|
1153
|
+
renderedVisualLines,
|
|
1154
|
+
visualCursor,
|
|
1155
|
+
visualScrollRow,
|
|
1156
|
+
visualToLogicalMap,
|
|
1157
|
+
setText,
|
|
1158
|
+
insert,
|
|
1159
|
+
newline,
|
|
1160
|
+
backspace,
|
|
1161
|
+
del,
|
|
1162
|
+
move,
|
|
1163
|
+
undo,
|
|
1164
|
+
redo,
|
|
1165
|
+
replaceRange,
|
|
1166
|
+
replaceRangeByOffset,
|
|
1167
|
+
moveToOffset,
|
|
1168
|
+
getOffset,
|
|
1169
|
+
moveToVisualPosition,
|
|
1170
|
+
deleteWordLeft,
|
|
1171
|
+
deleteWordRight,
|
|
1172
|
+
killLineRight,
|
|
1173
|
+
killLineLeft,
|
|
1174
|
+
handleInput,
|
|
1175
|
+
setViewport
|
|
1176
|
+
]
|
|
1177
|
+
);
|
|
1178
|
+
return returnValue;
|
|
1179
|
+
}
|
|
1180
|
+
export {
|
|
1181
|
+
findNextWordAcrossLines,
|
|
1182
|
+
findNextWordStartInLine,
|
|
1183
|
+
findPrevWordAcrossLines,
|
|
1184
|
+
findPrevWordStartInLine,
|
|
1185
|
+
findWordEndInLine,
|
|
1186
|
+
getLineRangeOffsets,
|
|
1187
|
+
getPositionFromOffsets,
|
|
1188
|
+
logicalPosToOffset,
|
|
1189
|
+
offsetToLogicalPos,
|
|
1190
|
+
pushUndo,
|
|
1191
|
+
replaceRangeInternal,
|
|
1192
|
+
textBufferReducer,
|
|
1193
|
+
useTextBuffer
|
|
1194
|
+
};
|