@google/gemini-cli 0.0.3-preview.4 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +12 -2
- package/dist/package.json +6 -7
- package/dist/src/commands/extensions/disable.d.ts +1 -1
- package/dist/src/commands/extensions/disable.js +3 -3
- package/dist/src/commands/extensions/disable.js.map +1 -1
- package/dist/src/commands/extensions/enable.d.ts +1 -1
- package/dist/src/commands/extensions/enable.js +6 -8
- package/dist/src/commands/extensions/enable.js.map +1 -1
- package/dist/src/commands/extensions/examples/context/GEMINI.md +8 -0
- package/dist/src/commands/extensions/examples/context/gemini-extension.json +5 -0
- package/dist/src/commands/extensions/examples/custom-commands/commands/fs/grep-code.toml +6 -0
- package/dist/src/commands/extensions/examples/custom-commands/gemini-extension.json +4 -0
- package/dist/src/commands/extensions/examples/exclude-tools/gemini-extension.json +5 -0
- package/dist/src/commands/extensions/examples/mcp-server/example.js +46 -0
- package/dist/src/commands/extensions/examples/mcp-server/example.js.map +1 -0
- package/dist/src/commands/extensions/examples/mcp-server/example.ts +60 -0
- package/dist/src/commands/extensions/examples/mcp-server/gemini-extension.json +10 -0
- package/dist/src/commands/extensions/install.d.ts +1 -0
- package/dist/src/commands/extensions/install.js +41 -12
- package/dist/src/commands/extensions/install.js.map +1 -1
- package/dist/src/commands/extensions/install.test.js +79 -3
- package/dist/src/commands/extensions/install.test.js.map +1 -1
- package/dist/src/commands/extensions/link.d.ts +12 -0
- package/dist/src/commands/extensions/link.js +37 -0
- package/dist/src/commands/extensions/link.js.map +1 -0
- package/dist/src/commands/extensions/new.d.ts +7 -0
- package/dist/src/commands/extensions/new.js +70 -0
- package/dist/src/commands/extensions/new.js.map +1 -0
- package/dist/src/commands/extensions/new.test.d.ts +6 -0
- package/dist/src/commands/extensions/new.test.js +50 -0
- package/dist/src/commands/extensions/new.test.js.map +1 -0
- package/dist/src/commands/extensions/uninstall.js +1 -1
- package/dist/src/commands/extensions/uninstall.js.map +1 -1
- package/dist/src/commands/extensions/update.d.ts +2 -1
- package/dist/src/commands/extensions/update.js +46 -15
- package/dist/src/commands/extensions/update.js.map +1 -1
- package/dist/src/commands/extensions.js +4 -0
- package/dist/src/commands/extensions.js.map +1 -1
- package/dist/src/commands/mcp/add.js +1 -1
- package/dist/src/commands/mcp/add.js.map +1 -1
- package/dist/src/commands/mcp/list.js +2 -2
- package/dist/src/commands/mcp/list.js.map +1 -1
- package/dist/src/commands/mcp/remove.js +1 -1
- package/dist/src/commands/mcp/remove.js.map +1 -1
- package/dist/src/config/auth.d.ts +1 -1
- package/dist/src/config/auth.js +4 -4
- package/dist/src/config/auth.js.map +1 -1
- package/dist/src/config/auth.test.js +15 -7
- package/dist/src/config/auth.test.js.map +1 -1
- package/dist/src/config/config.d.ts +4 -1
- package/dist/src/config/config.js +57 -23
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/extension.d.ts +20 -13
- package/dist/src/config/extension.js +261 -109
- package/dist/src/config/extension.js.map +1 -1
- package/dist/src/config/extensions/extensionEnablement.d.ts +30 -0
- package/dist/src/config/extensions/extensionEnablement.js +113 -0
- package/dist/src/config/extensions/extensionEnablement.js.map +1 -0
- package/dist/src/config/extensions/extensionEnablement.test.d.ts +6 -0
- package/dist/src/config/extensions/extensionEnablement.test.js +116 -0
- package/dist/src/config/extensions/extensionEnablement.test.js.map +1 -0
- package/dist/src/config/extensions/github.d.ts +25 -0
- package/dist/src/config/extensions/github.js +258 -0
- package/dist/src/config/extensions/github.js.map +1 -0
- package/dist/src/config/extensions/github.test.d.ts +6 -0
- package/dist/src/config/extensions/github.test.js +232 -0
- package/dist/src/config/extensions/github.test.js.map +1 -0
- package/dist/src/config/extensions/variableSchema.d.ts +8 -0
- package/dist/src/config/extensions/variableSchema.js +4 -0
- package/dist/src/config/extensions/variableSchema.js.map +1 -1
- package/dist/src/config/keyBindings.d.ts +5 -1
- package/dist/src/config/keyBindings.js +14 -25
- package/dist/src/config/keyBindings.js.map +1 -1
- package/dist/src/config/policy-engine.integration.test.d.ts +6 -0
- package/dist/src/config/policy-engine.integration.test.js +270 -0
- package/dist/src/config/policy-engine.integration.test.js.map +1 -0
- package/dist/src/config/policy.d.ts +8 -0
- package/dist/src/config/policy.js +150 -0
- package/dist/src/config/policy.js.map +1 -0
- package/dist/src/config/policy.test.d.ts +6 -0
- package/dist/src/config/policy.test.js +336 -0
- package/dist/src/config/policy.test.js.map +1 -0
- package/dist/src/config/settings.d.ts +8 -5
- package/dist/src/config/settings.js +148 -251
- package/dist/src/config/settings.js.map +1 -1
- package/dist/src/config/settingsSchema.d.ts +232 -23
- package/dist/src/config/settingsSchema.js +222 -20
- package/dist/src/config/settingsSchema.js.map +1 -1
- package/dist/src/config/settingsSchema.test.js +68 -55
- package/dist/src/config/settingsSchema.test.js.map +1 -1
- package/dist/src/config/trustedFolders.d.ts +13 -3
- package/dist/src/config/trustedFolders.js +66 -42
- package/dist/src/config/trustedFolders.js.map +1 -1
- package/dist/src/config/trustedFolders.test.js +107 -12
- package/dist/src/config/trustedFolders.test.js.map +1 -1
- package/dist/src/core/auth.d.ts +13 -0
- package/dist/src/core/auth.js +27 -0
- package/dist/src/core/auth.js.map +1 -0
- package/dist/src/core/initializer.d.ts +21 -0
- package/dist/src/core/initializer.js +33 -0
- package/dist/src/core/initializer.js.map +1 -0
- package/dist/src/core/theme.d.ts +12 -0
- package/dist/src/core/theme.js +20 -0
- package/dist/src/core/theme.js.map +1 -0
- package/dist/src/gemini.d.ts +2 -1
- package/dist/src/gemini.js +96 -51
- package/dist/src/gemini.js.map +1 -1
- package/dist/src/gemini.test.js +113 -42
- package/dist/src/gemini.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/nonInteractiveCli.js +87 -71
- package/dist/src/nonInteractiveCli.js.map +1 -1
- package/dist/src/services/BuiltinCommandLoader.js +1 -1
- package/dist/src/services/BuiltinCommandLoader.js.map +1 -1
- package/dist/src/services/BuiltinCommandLoader.test.js +16 -17
- package/dist/src/services/BuiltinCommandLoader.test.js.map +1 -1
- package/dist/src/services/FileCommandLoader.d.ts +2 -0
- package/dist/src/services/FileCommandLoader.js +7 -0
- package/dist/src/services/FileCommandLoader.js.map +1 -1
- package/dist/src/services/McpPromptLoader.js +43 -8
- package/dist/src/services/McpPromptLoader.js.map +1 -1
- package/dist/src/services/McpPromptLoader.test.js +228 -1
- package/dist/src/services/McpPromptLoader.test.js.map +1 -1
- package/dist/src/services/prompt-processors/shellProcessor.js +8 -1
- package/dist/src/services/prompt-processors/shellProcessor.js.map +1 -1
- package/dist/src/ui/App.d.ts +1 -10
- package/dist/src/ui/App.js +13 -667
- package/dist/src/ui/App.js.map +1 -1
- package/dist/src/ui/AppContainer.d.ts +17 -0
- package/dist/src/ui/AppContainer.js +879 -0
- package/dist/src/ui/AppContainer.js.map +1 -0
- package/dist/src/ui/AppContainer.test.d.ts +6 -0
- package/dist/src/ui/AppContainer.test.js +414 -0
- package/dist/src/ui/AppContainer.test.js.map +1 -0
- package/dist/src/ui/IdeIntegrationNudge.d.ts +2 -2
- package/dist/src/ui/IdeIntegrationNudge.js +3 -3
- package/dist/src/ui/IdeIntegrationNudge.js.map +1 -1
- package/dist/src/ui/auth/AuthDialog.d.ts +18 -0
- package/dist/src/ui/auth/AuthDialog.js +99 -0
- package/dist/src/ui/auth/AuthDialog.js.map +1 -0
- package/dist/src/ui/auth/AuthDialog.test.d.ts +6 -0
- package/dist/src/ui/auth/AuthDialog.test.js +184 -0
- package/dist/src/ui/auth/AuthDialog.test.js.map +1 -0
- package/dist/src/ui/{components → auth}/AuthInProgress.js +2 -2
- package/dist/src/ui/auth/AuthInProgress.js.map +1 -0
- package/dist/src/ui/auth/useAuth.d.ts +15 -0
- package/dist/src/ui/auth/useAuth.js +73 -0
- package/dist/src/ui/auth/useAuth.js.map +1 -0
- package/dist/src/ui/commands/aboutCommand.js +9 -3
- package/dist/src/ui/commands/aboutCommand.js.map +1 -1
- package/dist/src/ui/commands/bugCommand.js +9 -4
- package/dist/src/ui/commands/bugCommand.js.map +1 -1
- package/dist/src/ui/commands/chatCommand.d.ts +2 -0
- package/dist/src/ui/commands/chatCommand.js +82 -3
- package/dist/src/ui/commands/chatCommand.js.map +1 -1
- package/dist/src/ui/commands/clearCommand.js +1 -1
- package/dist/src/ui/commands/clearCommand.js.map +1 -1
- package/dist/src/ui/commands/corgiCommand.js +1 -0
- package/dist/src/ui/commands/corgiCommand.js.map +1 -1
- package/dist/src/ui/commands/directoryCommand.js +1 -1
- package/dist/src/ui/commands/directoryCommand.js.map +1 -1
- package/dist/src/ui/commands/extensionsCommand.js +70 -16
- package/dist/src/ui/commands/extensionsCommand.js.map +1 -1
- package/dist/src/ui/commands/ideCommand.d.ts +1 -2
- package/dist/src/ui/commands/ideCommand.js +19 -10
- package/dist/src/ui/commands/ideCommand.js.map +1 -1
- package/dist/src/ui/commands/mcpCommand.js +14 -5
- package/dist/src/ui/commands/mcpCommand.js.map +1 -1
- package/dist/src/ui/commands/memoryCommand.js +1 -1
- package/dist/src/ui/commands/memoryCommand.js.map +1 -1
- package/dist/src/ui/commands/types.d.ts +5 -1
- package/dist/src/ui/commands/types.js +0 -1
- package/dist/src/ui/commands/types.js.map +1 -1
- package/dist/src/ui/components/AboutBox.js +2 -2
- package/dist/src/ui/components/AboutBox.js.map +1 -1
- package/dist/src/ui/components/AnsiOutput.d.ts +13 -0
- package/dist/src/ui/components/AnsiOutput.js +12 -0
- package/dist/src/ui/components/AnsiOutput.js.map +1 -0
- package/dist/src/ui/components/AnsiOutput.test.d.ts +6 -0
- package/dist/src/ui/components/AnsiOutput.test.js +97 -0
- package/dist/src/ui/components/AnsiOutput.test.js.map +1 -0
- package/dist/src/ui/components/AppHeader.d.ts +10 -0
- package/dist/src/ui/components/AppHeader.js +22 -0
- package/dist/src/ui/components/AppHeader.js.map +1 -0
- package/dist/src/ui/components/AutoAcceptIndicator.js +4 -4
- package/dist/src/ui/components/AutoAcceptIndicator.js.map +1 -1
- package/dist/src/ui/components/Composer.d.ts +6 -0
- package/dist/src/ui/components/Composer.js +73 -0
- package/dist/src/ui/components/Composer.js.map +1 -0
- package/dist/src/ui/components/Composer.test.d.ts +6 -0
- package/dist/src/ui/components/Composer.test.js +337 -0
- package/dist/src/ui/components/Composer.test.js.map +1 -0
- package/dist/src/ui/components/ConfigInitDisplay.d.ts +6 -0
- package/dist/src/ui/components/ConfigInitDisplay.js +38 -0
- package/dist/src/ui/components/ConfigInitDisplay.js.map +1 -0
- package/dist/src/ui/components/ConsoleSummaryDisplay.js +2 -2
- package/dist/src/ui/components/ConsoleSummaryDisplay.js.map +1 -1
- package/dist/src/ui/components/ContextSummaryDisplay.js +3 -3
- package/dist/src/ui/components/ContextSummaryDisplay.js.map +1 -1
- package/dist/src/ui/components/ContextUsageDisplay.js +2 -2
- package/dist/src/ui/components/ContextUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/DebugProfiler.js +2 -2
- package/dist/src/ui/components/DebugProfiler.js.map +1 -1
- package/dist/src/ui/components/DetailedMessagesDisplay.js +7 -7
- package/dist/src/ui/components/DetailedMessagesDisplay.js.map +1 -1
- package/dist/src/ui/components/DialogManager.d.ts +6 -0
- package/dist/src/ui/components/DialogManager.js +85 -0
- package/dist/src/ui/components/DialogManager.js.map +1 -0
- package/dist/src/ui/components/EditorSettingsDialog.js +5 -5
- package/dist/src/ui/components/EditorSettingsDialog.js.map +1 -1
- package/dist/src/ui/components/FolderTrustDialog.js +19 -9
- package/dist/src/ui/components/FolderTrustDialog.js.map +1 -1
- package/dist/src/ui/components/FolderTrustDialog.test.js +35 -10
- package/dist/src/ui/components/FolderTrustDialog.test.js.map +1 -1
- package/dist/src/ui/components/Footer.d.ts +4 -2
- package/dist/src/ui/components/Footer.js +8 -3
- package/dist/src/ui/components/Footer.js.map +1 -1
- package/dist/src/ui/components/GeminiRespondingSpinner.d.ts +5 -0
- package/dist/src/ui/components/GeminiRespondingSpinner.js +7 -2
- package/dist/src/ui/components/GeminiRespondingSpinner.js.map +1 -1
- package/dist/src/ui/components/Header.js +2 -2
- package/dist/src/ui/components/Header.js.map +1 -1
- package/dist/src/ui/components/Help.d.ts +1 -1
- package/dist/src/ui/components/Help.js +9 -6
- package/dist/src/ui/components/Help.js.map +1 -1
- package/dist/src/ui/components/Help.test.d.ts +6 -0
- package/dist/src/ui/components/Help.test.js +57 -0
- package/dist/src/ui/components/Help.test.js.map +1 -0
- package/dist/src/ui/components/HistoryItemDisplay.d.ts +2 -2
- package/dist/src/ui/components/HistoryItemDisplay.js +3 -1
- package/dist/src/ui/components/HistoryItemDisplay.js.map +1 -1
- package/dist/src/ui/components/InputPrompt.d.ts +9 -0
- package/dist/src/ui/components/InputPrompt.js +180 -42
- package/dist/src/ui/components/InputPrompt.js.map +1 -1
- package/dist/src/ui/components/LoadingIndicator.js +2 -2
- package/dist/src/ui/components/LoadingIndicator.js.map +1 -1
- package/dist/src/ui/components/LoopDetectionConfirmation.d.ts +13 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.js +35 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.js.map +1 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.d.ts +6 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.js +25 -0
- package/dist/src/ui/components/LoopDetectionConfirmation.test.js.map +1 -0
- package/dist/src/ui/components/MainContent.d.ts +6 -0
- package/dist/src/ui/components/MainContent.js +23 -0
- package/dist/src/ui/components/MainContent.js.map +1 -0
- package/dist/src/ui/components/MemoryUsageDisplay.js +6 -4
- package/dist/src/ui/components/MemoryUsageDisplay.js.map +1 -1
- package/dist/src/ui/components/ModelStatsDisplay.js +7 -7
- package/dist/src/ui/components/ModelStatsDisplay.js.map +1 -1
- package/dist/src/ui/components/Notifications.d.ts +6 -0
- package/dist/src/ui/components/Notifications.js +23 -0
- package/dist/src/ui/components/Notifications.js.map +1 -0
- package/dist/src/ui/components/PrepareLabel.d.ts +5 -5
- package/dist/src/ui/components/PrepareLabel.js +67 -11
- package/dist/src/ui/components/PrepareLabel.js.map +1 -1
- package/dist/src/ui/components/PrepareLabel.test.d.ts +6 -0
- package/dist/src/ui/components/PrepareLabel.test.js +71 -0
- package/dist/src/ui/components/PrepareLabel.test.js.map +1 -0
- package/dist/src/ui/components/ProQuotaDialog.d.ts +13 -0
- package/dist/src/ui/components/ProQuotaDialog.js +21 -0
- package/dist/src/ui/components/ProQuotaDialog.js.map +1 -0
- package/dist/src/ui/components/ProQuotaDialog.test.d.ts +6 -0
- package/dist/src/ui/components/ProQuotaDialog.test.js +56 -0
- package/dist/src/ui/components/ProQuotaDialog.test.js.map +1 -0
- package/dist/src/ui/components/QueuedMessageDisplay.d.ts +9 -0
- package/dist/src/ui/components/QueuedMessageDisplay.js +20 -0
- package/dist/src/ui/components/QueuedMessageDisplay.js.map +1 -0
- package/dist/src/ui/components/QueuedMessageDisplay.test.d.ts +6 -0
- package/dist/src/ui/components/QueuedMessageDisplay.test.js +56 -0
- package/dist/src/ui/components/QueuedMessageDisplay.test.js.map +1 -0
- package/dist/src/ui/components/QuittingDisplay.d.ts +6 -0
- package/dist/src/ui/components/QuittingDisplay.js +20 -0
- package/dist/src/ui/components/QuittingDisplay.js.map +1 -0
- package/dist/src/ui/components/SettingsDialog.d.ts +2 -1
- package/dist/src/ui/components/SettingsDialog.js +93 -22
- package/dist/src/ui/components/SettingsDialog.js.map +1 -1
- package/dist/src/ui/components/SettingsDialog.test.js +436 -80
- package/dist/src/ui/components/SettingsDialog.test.js.map +1 -1
- package/dist/src/ui/components/ShellConfirmationDialog.js +2 -2
- package/dist/src/ui/components/ShellConfirmationDialog.js.map +1 -1
- package/dist/src/ui/components/ShellInputPrompt.d.ts +11 -0
- package/dist/src/ui/components/ShellInputPrompt.js +36 -0
- package/dist/src/ui/components/ShellInputPrompt.js.map +1 -0
- package/dist/src/ui/components/ShellModeIndicator.js +2 -2
- package/dist/src/ui/components/ShellModeIndicator.js.map +1 -1
- package/dist/src/ui/components/ShowMoreLines.js +2 -2
- package/dist/src/ui/components/ShowMoreLines.js.map +1 -1
- package/dist/src/ui/components/StatsDisplay.js +6 -6
- package/dist/src/ui/components/StatsDisplay.js.map +1 -1
- package/dist/src/ui/components/SuggestionsDisplay.d.ts +7 -2
- package/dist/src/ui/components/SuggestionsDisplay.js +17 -17
- package/dist/src/ui/components/SuggestionsDisplay.js.map +1 -1
- package/dist/src/ui/components/ThemeDialog.js +12 -29
- package/dist/src/ui/components/ThemeDialog.js.map +1 -1
- package/dist/src/ui/components/ThemeDialog.test.d.ts +6 -0
- package/dist/src/ui/components/ThemeDialog.test.js +75 -0
- package/dist/src/ui/components/ThemeDialog.test.js.map +1 -0
- package/dist/src/ui/components/Tips.js +2 -2
- package/dist/src/ui/components/Tips.js.map +1 -1
- package/dist/src/ui/components/ToolStatsDisplay.js +4 -4
- package/dist/src/ui/components/ToolStatsDisplay.js.map +1 -1
- package/dist/src/ui/components/UpdateNotification.js +2 -2
- package/dist/src/ui/components/UpdateNotification.js.map +1 -1
- package/dist/src/ui/components/WorkspaceMigrationDialog.js +4 -4
- package/dist/src/ui/components/WorkspaceMigrationDialog.js.map +1 -1
- package/dist/src/ui/components/messages/CompressionMessage.d.ts +1 -2
- package/dist/src/ui/components/messages/CompressionMessage.js +37 -8
- package/dist/src/ui/components/messages/CompressionMessage.js.map +1 -1
- package/dist/src/ui/components/messages/CompressionMessage.test.d.ts +6 -0
- package/dist/src/ui/components/messages/CompressionMessage.test.js +160 -0
- package/dist/src/ui/components/messages/CompressionMessage.test.js.map +1 -0
- package/dist/src/ui/components/messages/DiffRenderer.d.ts +2 -1
- package/dist/src/ui/components/messages/DiffRenderer.js +14 -22
- package/dist/src/ui/components/messages/DiffRenderer.js.map +1 -1
- package/dist/src/ui/components/messages/ErrorMessage.js +2 -2
- package/dist/src/ui/components/messages/ErrorMessage.js.map +1 -1
- package/dist/src/ui/components/messages/GeminiMessage.js +2 -2
- package/dist/src/ui/components/messages/GeminiMessage.js.map +1 -1
- package/dist/src/ui/components/messages/InfoMessage.js +2 -2
- package/dist/src/ui/components/messages/InfoMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js +33 -21
- package/dist/src/ui/components/messages/ToolConfirmationMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js +0 -8
- package/dist/src/ui/components/messages/ToolConfirmationMessage.test.js.map +1 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.d.ts +3 -2
- package/dist/src/ui/components/messages/ToolGroupMessage.js +17 -9
- package/dist/src/ui/components/messages/ToolGroupMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolGroupMessage.test.js +17 -15
- package/dist/src/ui/components/messages/ToolGroupMessage.test.js.map +1 -1
- package/dist/src/ui/components/messages/ToolMessage.d.ts +4 -0
- package/dist/src/ui/components/messages/ToolMessage.js +24 -10
- package/dist/src/ui/components/messages/ToolMessage.js.map +1 -1
- package/dist/src/ui/components/messages/ToolMessage.test.js +33 -1
- package/dist/src/ui/components/messages/ToolMessage.test.js.map +1 -1
- package/dist/src/ui/components/messages/UserMessage.js +3 -3
- package/dist/src/ui/components/messages/UserMessage.js.map +1 -1
- package/dist/src/ui/components/messages/UserShellMessage.js +2 -2
- package/dist/src/ui/components/messages/UserShellMessage.js.map +1 -1
- package/dist/src/ui/components/messages/WarningMessage.d.ts +11 -0
- package/dist/src/ui/components/messages/WarningMessage.js +10 -0
- package/dist/src/ui/components/messages/WarningMessage.js.map +1 -0
- package/dist/src/ui/components/shared/EnumSelector.d.ts +18 -0
- package/dist/src/ui/components/shared/EnumSelector.js +44 -0
- package/dist/src/ui/components/shared/EnumSelector.js.map +1 -0
- package/dist/src/ui/components/shared/EnumSelector.test.d.ts +6 -0
- package/dist/src/ui/components/shared/EnumSelector.test.js +70 -0
- package/dist/src/ui/components/shared/EnumSelector.test.js.map +1 -0
- package/dist/src/ui/components/shared/MaxSizedBox.js +2 -2
- package/dist/src/ui/components/shared/MaxSizedBox.js.map +1 -1
- package/dist/src/ui/components/shared/RadioButtonSelect.js +12 -12
- package/dist/src/ui/components/shared/RadioButtonSelect.js.map +1 -1
- package/dist/src/ui/components/shared/ScopeSelector.d.ts +19 -0
- package/dist/src/ui/components/shared/ScopeSelector.js +11 -0
- package/dist/src/ui/components/shared/ScopeSelector.js.map +1 -0
- package/dist/src/ui/components/shared/text-buffer.d.ts +25 -2
- package/dist/src/ui/components/shared/text-buffer.js +296 -187
- package/dist/src/ui/components/shared/text-buffer.js.map +1 -1
- package/dist/src/ui/components/views/ExtensionsList.d.ts +6 -0
- package/dist/src/ui/components/views/ExtensionsList.js +47 -0
- package/dist/src/ui/components/views/ExtensionsList.js.map +1 -0
- package/dist/src/ui/components/views/ExtensionsList.test.d.ts +6 -0
- package/dist/src/ui/components/views/ExtensionsList.test.js +97 -0
- package/dist/src/ui/components/views/ExtensionsList.test.js.map +1 -0
- package/dist/src/ui/constants.d.ts +1 -0
- package/dist/src/ui/constants.js +1 -0
- package/dist/src/ui/constants.js.map +1 -1
- package/dist/src/ui/contexts/AppContext.d.ts +11 -0
- package/dist/src/ui/contexts/AppContext.js +15 -0
- package/dist/src/ui/contexts/AppContext.js.map +1 -0
- package/dist/src/ui/contexts/ConfigContext.d.ts +9 -0
- package/dist/src/ui/contexts/ConfigContext.js +16 -0
- package/dist/src/ui/contexts/ConfigContext.js.map +1 -0
- package/dist/src/ui/contexts/FocusContext.d.ts +7 -0
- package/dist/src/ui/contexts/FocusContext.js +9 -0
- package/dist/src/ui/contexts/FocusContext.js.map +1 -0
- package/dist/src/ui/contexts/KeypressContext.d.ts +3 -0
- package/dist/src/ui/contexts/KeypressContext.js +306 -44
- package/dist/src/ui/contexts/KeypressContext.js.map +1 -1
- package/dist/src/ui/contexts/KeypressContext.test.js +288 -2
- package/dist/src/ui/contexts/KeypressContext.test.js.map +1 -1
- package/dist/src/ui/contexts/SessionContext.d.ts +6 -0
- package/dist/src/ui/contexts/SessionContext.js +107 -5
- package/dist/src/ui/contexts/SessionContext.js.map +1 -1
- package/dist/src/ui/contexts/UIActionsContext.d.ts +36 -0
- package/dist/src/ui/contexts/UIActionsContext.js +20 -0
- package/dist/src/ui/contexts/UIActionsContext.js.map +1 -0
- package/dist/src/ui/contexts/UIStateContext.d.ts +95 -0
- package/dist/src/ui/contexts/UIStateContext.js +15 -0
- package/dist/src/ui/contexts/UIStateContext.js.map +1 -0
- package/dist/src/ui/hooks/atCommandProcessor.test.js +7 -5
- package/dist/src/ui/hooks/atCommandProcessor.test.js.map +1 -1
- package/dist/src/ui/hooks/keyToAnsi.d.ts +15 -0
- package/dist/src/ui/hooks/keyToAnsi.js +67 -0
- package/dist/src/ui/hooks/keyToAnsi.js.map +1 -0
- package/dist/src/ui/hooks/shellCommandProcessor.d.ts +2 -1
- package/dist/src/ui/hooks/shellCommandProcessor.js +60 -15
- package/dist/src/ui/hooks/shellCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/shellCommandProcessor.test.js +196 -17
- package/dist/src/ui/hooks/shellCommandProcessor.test.js.map +1 -1
- package/dist/src/ui/hooks/slashCommandProcessor.d.ts +15 -2
- package/dist/src/ui/hooks/slashCommandProcessor.js +36 -73
- package/dist/src/ui/hooks/slashCommandProcessor.js.map +1 -1
- package/dist/src/ui/hooks/useAutoAcceptIndicator.d.ts +3 -2
- package/dist/src/ui/hooks/useAutoAcceptIndicator.js +9 -5
- package/dist/src/ui/hooks/useAutoAcceptIndicator.js.map +1 -1
- package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js +69 -0
- package/dist/src/ui/hooks/useAutoAcceptIndicator.test.js.map +1 -1
- package/dist/src/ui/hooks/useFolderTrust.d.ts +1 -1
- package/dist/src/ui/hooks/useFolderTrust.js +12 -11
- package/dist/src/ui/hooks/useFolderTrust.js.map +1 -1
- package/dist/src/ui/hooks/useGeminiStream.d.ts +13 -2
- package/dist/src/ui/hooks/useGeminiStream.js +150 -60
- package/dist/src/ui/hooks/useGeminiStream.js.map +1 -1
- package/dist/src/ui/hooks/useGitBranchName.js +15 -18
- package/dist/src/ui/hooks/useGitBranchName.js.map +1 -1
- package/dist/src/ui/hooks/useGitBranchName.test.js +49 -53
- package/dist/src/ui/hooks/useGitBranchName.test.js.map +1 -1
- package/dist/src/ui/hooks/useIdeTrustListener.d.ts +14 -0
- package/dist/src/ui/hooks/useIdeTrustListener.js +39 -0
- package/dist/src/ui/hooks/useIdeTrustListener.js.map +1 -0
- package/dist/src/ui/hooks/useInputHistoryStore.d.ts +19 -0
- package/dist/src/ui/hooks/useInputHistoryStore.js +81 -0
- package/dist/src/ui/hooks/useInputHistoryStore.js.map +1 -0
- package/dist/src/ui/hooks/useInputHistoryStore.test.d.ts +6 -0
- package/dist/src/ui/hooks/useInputHistoryStore.test.js +234 -0
- package/dist/src/ui/hooks/useInputHistoryStore.test.js.map +1 -0
- package/dist/src/ui/hooks/useLoadingIndicator.d.ts +1 -1
- package/dist/src/ui/hooks/useLoadingIndicator.js +2 -2
- package/dist/src/ui/hooks/useLoadingIndicator.js.map +1 -1
- package/dist/src/ui/hooks/useLoadingIndicator.test.js +2 -2
- package/dist/src/ui/hooks/useLoadingIndicator.test.js.map +1 -1
- package/dist/src/ui/hooks/useMemoryMonitor.d.ts +13 -0
- package/dist/src/ui/hooks/useMemoryMonitor.js +28 -0
- package/dist/src/ui/hooks/useMemoryMonitor.js.map +1 -0
- package/dist/src/ui/hooks/useMemoryMonitor.test.d.ts +6 -0
- package/dist/src/ui/hooks/useMemoryMonitor.test.js +57 -0
- package/dist/src/ui/hooks/useMemoryMonitor.test.js.map +1 -0
- package/dist/src/ui/hooks/useMessageQueue.d.ts +2 -1
- package/dist/src/ui/hooks/useMessageQueue.js +5 -3
- package/dist/src/ui/hooks/useMessageQueue.js.map +1 -1
- package/dist/src/ui/hooks/useMessageQueue.test.js +9 -0
- package/dist/src/ui/hooks/useMessageQueue.test.js.map +1 -1
- package/dist/src/ui/hooks/usePhraseCycler.d.ts +1 -1
- package/dist/src/ui/hooks/usePhraseCycler.js +11 -8
- package/dist/src/ui/hooks/usePhraseCycler.js.map +1 -1
- package/dist/src/ui/hooks/usePrivacySettings.d.ts +1 -1
- package/dist/src/ui/hooks/usePrivacySettings.js +8 -13
- package/dist/src/ui/hooks/usePrivacySettings.js.map +1 -1
- package/dist/src/ui/hooks/usePrivacySettings.test.js +33 -97
- package/dist/src/ui/hooks/usePrivacySettings.test.js.map +1 -1
- package/dist/src/ui/hooks/useQuotaAndFallback.d.ts +21 -0
- package/dist/src/ui/hooks/useQuotaAndFallback.js +122 -0
- package/dist/src/ui/hooks/useQuotaAndFallback.js.map +1 -0
- package/dist/src/ui/hooks/useQuotaAndFallback.test.d.ts +6 -0
- package/dist/src/ui/hooks/useQuotaAndFallback.test.js +267 -0
- package/dist/src/ui/hooks/useQuotaAndFallback.test.js.map +1 -0
- package/dist/src/ui/hooks/useReactToolScheduler.d.ts +3 -2
- package/dist/src/ui/hooks/useReactToolScheduler.js +23 -17
- package/dist/src/ui/hooks/useReactToolScheduler.js.map +1 -1
- package/dist/src/ui/hooks/useReverseSearchCompletion.d.ts +1 -1
- package/dist/src/ui/hooks/useReverseSearchCompletion.js +67 -20
- package/dist/src/ui/hooks/useReverseSearchCompletion.js.map +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.d.ts +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.js +276 -67
- package/dist/src/ui/hooks/useSlashCompletion.js.map +1 -1
- package/dist/src/ui/hooks/useSlashCompletion.test.d.ts +4 -1
- package/dist/src/ui/hooks/useSlashCompletion.test.js +357 -65
- package/dist/src/ui/hooks/useSlashCompletion.test.js.map +1 -1
- package/dist/src/ui/hooks/useStateAndRef.d.ts +1 -1
- package/dist/src/ui/hooks/useStateAndRef.js +2 -2
- package/dist/src/ui/hooks/useStateAndRef.js.map +1 -1
- package/dist/src/ui/hooks/useThemeCommand.d.ts +1 -1
- package/dist/src/ui/hooks/useThemeCommand.js +3 -14
- package/dist/src/ui/hooks/useThemeCommand.js.map +1 -1
- package/dist/src/ui/hooks/useToolScheduler.test.js +66 -61
- package/dist/src/ui/hooks/useToolScheduler.test.js.map +1 -1
- package/dist/src/ui/hooks/useWorkspaceMigration.js +2 -1
- package/dist/src/ui/hooks/useWorkspaceMigration.js.map +1 -1
- package/dist/src/ui/keyMatchers.test.js +17 -0
- package/dist/src/ui/keyMatchers.test.js.map +1 -1
- package/dist/src/ui/privacy/CloudFreePrivacyNotice.js +5 -5
- package/dist/src/ui/privacy/CloudFreePrivacyNotice.js.map +1 -1
- package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js +2 -2
- package/dist/src/ui/privacy/CloudPaidPrivacyNotice.js.map +1 -1
- package/dist/src/ui/privacy/GeminiPrivacyNotice.js +2 -2
- package/dist/src/ui/privacy/GeminiPrivacyNotice.js.map +1 -1
- package/dist/src/ui/state/extensions.d.ts +14 -0
- package/dist/src/ui/state/extensions.js +16 -0
- package/dist/src/ui/state/extensions.js.map +1 -0
- package/dist/src/ui/themes/ayu.js +1 -1
- package/dist/src/ui/themes/dracula.js +2 -2
- package/dist/src/ui/themes/github-dark.js +1 -1
- package/dist/src/ui/themes/theme.js +17 -17
- package/dist/src/ui/themes/theme.js.map +1 -1
- package/dist/src/ui/types.d.ts +34 -3
- package/dist/src/ui/types.js +12 -0
- package/dist/src/ui/types.js.map +1 -1
- package/dist/src/ui/utils/CodeColorizer.js +3 -2
- package/dist/src/ui/utils/CodeColorizer.js.map +1 -1
- package/dist/src/ui/utils/InlineMarkdownRenderer.js +7 -7
- package/dist/src/ui/utils/InlineMarkdownRenderer.js.map +1 -1
- package/dist/src/ui/utils/MarkdownDisplay.js +10 -10
- package/dist/src/ui/utils/MarkdownDisplay.js.map +1 -1
- package/dist/src/ui/utils/MarkdownDisplay.test.js +6 -2
- package/dist/src/ui/utils/MarkdownDisplay.test.js.map +1 -1
- package/dist/src/ui/utils/TableRenderer.js +4 -4
- package/dist/src/ui/utils/TableRenderer.js.map +1 -1
- package/dist/src/ui/utils/clipboardUtils.js +5 -6
- package/dist/src/ui/utils/clipboardUtils.js.map +1 -1
- package/dist/src/ui/utils/displayUtils.js +4 -4
- package/dist/src/ui/utils/displayUtils.js.map +1 -1
- package/dist/src/ui/utils/highlight.d.ts +11 -0
- package/dist/src/ui/utils/highlight.js +78 -0
- package/dist/src/ui/utils/highlight.js.map +1 -0
- package/dist/src/ui/utils/highlight.test.d.ts +6 -0
- package/dist/src/ui/utils/highlight.test.js +120 -0
- package/dist/src/ui/utils/highlight.test.js.map +1 -0
- package/dist/src/ui/utils/kittyProtocolDetector.js +39 -29
- package/dist/src/ui/utils/kittyProtocolDetector.js.map +1 -1
- package/dist/src/ui/utils/platformConstants.d.ts +24 -1
- package/dist/src/ui/utils/platformConstants.js +26 -1
- package/dist/src/ui/utils/platformConstants.js.map +1 -1
- package/dist/src/ui/utils/textUtils.d.ts +9 -0
- package/dist/src/ui/utils/textUtils.js +52 -3
- package/dist/src/ui/utils/textUtils.js.map +1 -1
- package/dist/src/utils/commands.d.ts +20 -0
- package/dist/src/utils/commands.js +53 -0
- package/dist/src/utils/commands.js.map +1 -0
- package/dist/src/utils/commands.test.d.ts +6 -0
- package/dist/src/utils/commands.test.js +115 -0
- package/dist/src/utils/commands.test.js.map +1 -0
- package/dist/src/utils/commentJson.d.ts +9 -0
- package/dist/src/utils/commentJson.js +48 -0
- package/dist/src/utils/commentJson.js.map +1 -0
- package/dist/src/utils/commentJson.test.d.ts +6 -0
- package/dist/src/utils/commentJson.test.js +146 -0
- package/dist/src/utils/commentJson.test.js.map +1 -0
- package/dist/src/utils/deepMerge.d.ts +10 -0
- package/dist/src/utils/deepMerge.js +58 -0
- package/dist/src/utils/deepMerge.js.map +1 -0
- package/dist/src/utils/deepMerge.test.d.ts +6 -0
- package/dist/src/utils/deepMerge.test.js +143 -0
- package/dist/src/utils/deepMerge.test.js.map +1 -0
- package/dist/src/utils/envVarResolver.d.ts +39 -0
- package/dist/src/utils/envVarResolver.js +97 -0
- package/dist/src/utils/envVarResolver.js.map +1 -0
- package/dist/src/utils/envVarResolver.test.d.ts +6 -0
- package/dist/src/utils/envVarResolver.test.js +221 -0
- package/dist/src/utils/envVarResolver.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +21 -0
- package/dist/src/utils/errors.js +93 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/errors.test.d.ts +6 -0
- package/dist/src/utils/errors.test.js +303 -0
- package/dist/src/utils/errors.test.js.map +1 -0
- package/dist/src/utils/events.d.ts +2 -1
- package/dist/src/utils/events.js +1 -0
- package/dist/src/utils/events.js.map +1 -1
- package/dist/src/utils/processUtils.d.ts +13 -0
- package/dist/src/utils/processUtils.js +18 -0
- package/dist/src/utils/processUtils.js.map +1 -0
- package/dist/src/utils/processUtils.test.d.ts +6 -0
- package/dist/src/utils/processUtils.test.js +20 -0
- package/dist/src/utils/processUtils.test.js.map +1 -0
- package/dist/src/utils/sandbox.d.ts +1 -1
- package/dist/src/utils/sandbox.js +19 -8
- package/dist/src/utils/sandbox.js.map +1 -1
- package/dist/src/utils/settingsUtils.d.ts +16 -6
- package/dist/src/utils/settingsUtils.js +35 -25
- package/dist/src/utils/settingsUtils.js.map +1 -1
- package/dist/src/utils/settingsUtils.test.js +455 -158
- package/dist/src/utils/settingsUtils.test.js.map +1 -1
- package/dist/src/utils/userStartupWarnings.d.ts +1 -1
- package/dist/src/utils/userStartupWarnings.js +1 -1
- package/dist/src/utils/userStartupWarnings.js.map +1 -1
- package/dist/src/validateNonInterActiveAuth.d.ts +2 -1
- package/dist/src/validateNonInterActiveAuth.js +33 -12
- package/dist/src/validateNonInterActiveAuth.js.map +1 -1
- package/dist/src/zed-integration/schema.d.ts +578 -578
- package/dist/src/zed-integration/zedIntegration.js +17 -12
- package/dist/src/zed-integration/zedIntegration.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/npm-shrinkwrap.json +17168 -0
- package/package.json +7 -8
- package/dist/google-gemini-cli-0.3.0-preview.3.tgz +0 -0
- package/dist/src/ui/components/AuthDialog.d.ts +0 -16
- package/dist/src/ui/components/AuthDialog.js +0 -92
- package/dist/src/ui/components/AuthDialog.js.map +0 -1
- package/dist/src/ui/components/AuthDialog.test.js +0 -276
- package/dist/src/ui/components/AuthDialog.test.js.map +0 -1
- package/dist/src/ui/components/AuthInProgress.js.map +0 -1
- package/dist/src/ui/hooks/useAuthCommand.d.ts +0 -14
- package/dist/src/ui/hooks/useAuthCommand.js +0 -66
- package/dist/src/ui/hooks/useAuthCommand.js.map +0 -1
- /package/dist/src/{ui/components/AuthDialog.test.d.ts → commands/extensions/examples/mcp-server/example.d.ts} +0 -0
- /package/dist/src/ui/{components → auth}/AuthInProgress.d.ts +0 -0
|
@@ -8,9 +8,8 @@ import fs from 'node:fs';
|
|
|
8
8
|
import os from 'node:os';
|
|
9
9
|
import pathMod from 'node:path';
|
|
10
10
|
import { useState, useCallback, useEffect, useMemo, useReducer } from 'react';
|
|
11
|
-
import stringWidth from 'string-width';
|
|
12
11
|
import { unescapePath } from '@google/gemini-cli-core';
|
|
13
|
-
import { toCodePoints, cpLen, cpSlice, stripUnsafeCharacters, } from '../../utils/textUtils.js';
|
|
12
|
+
import { toCodePoints, cpLen, cpSlice, stripUnsafeCharacters, getCachedStringWidth, } from '../../utils/textUtils.js';
|
|
14
13
|
import { handleVimAction } from './vim-buffer-actions.js';
|
|
15
14
|
// Simple helper for word‑wise ops.
|
|
16
15
|
function isWordChar(ch) {
|
|
@@ -455,12 +454,12 @@ export function logicalPosToOffset(lines, row, col) {
|
|
|
455
454
|
}
|
|
456
455
|
return offset;
|
|
457
456
|
}
|
|
458
|
-
//
|
|
459
|
-
|
|
457
|
+
// Calculates the visual wrapping of lines and the mapping between logical and visual coordinates.
|
|
458
|
+
// This is an expensive operation and should be memoized.
|
|
459
|
+
function calculateLayout(logicalLines, viewportWidth) {
|
|
460
460
|
const visualLines = [];
|
|
461
461
|
const logicalToVisualMap = [];
|
|
462
462
|
const visualToLogicalMap = [];
|
|
463
|
-
let currentVisualCursor = [0, 0];
|
|
464
463
|
logicalLines.forEach((logLine, logIndex) => {
|
|
465
464
|
logicalToVisualMap[logIndex] = [];
|
|
466
465
|
if (logLine.length === 0) {
|
|
@@ -468,9 +467,6 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
|
|
|
468
467
|
logicalToVisualMap[logIndex].push([visualLines.length, 0]);
|
|
469
468
|
visualToLogicalMap.push([logIndex, 0]);
|
|
470
469
|
visualLines.push('');
|
|
471
|
-
if (logIndex === logicalCursor[0] && logicalCursor[1] === 0) {
|
|
472
|
-
currentVisualCursor = [visualLines.length - 1, 0];
|
|
473
|
-
}
|
|
474
470
|
}
|
|
475
471
|
else {
|
|
476
472
|
// Non-empty logical line
|
|
@@ -485,7 +481,7 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
|
|
|
485
481
|
// Iterate through code points to build the current visual line (chunk)
|
|
486
482
|
for (let i = currentPosInLogLine; i < codePointsInLogLine.length; i++) {
|
|
487
483
|
const char = codePointsInLogLine[i];
|
|
488
|
-
const charVisualWidth =
|
|
484
|
+
const charVisualWidth = getCachedStringWidth(char);
|
|
489
485
|
if (currentChunkVisualWidth + charVisualWidth > viewportWidth) {
|
|
490
486
|
// Character would exceed viewport width
|
|
491
487
|
if (lastWordBreakPoint !== -1 &&
|
|
@@ -551,27 +547,6 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
|
|
|
551
547
|
]);
|
|
552
548
|
visualToLogicalMap.push([logIndex, currentPosInLogLine]);
|
|
553
549
|
visualLines.push(currentChunk);
|
|
554
|
-
// Cursor mapping logic
|
|
555
|
-
// Note: currentPosInLogLine here is the start of the currentChunk within the logical line.
|
|
556
|
-
if (logIndex === logicalCursor[0]) {
|
|
557
|
-
const cursorLogCol = logicalCursor[1]; // This is a code point index
|
|
558
|
-
if (cursorLogCol >= currentPosInLogLine &&
|
|
559
|
-
cursorLogCol < currentPosInLogLine + numCodePointsInChunk // Cursor is within this chunk
|
|
560
|
-
) {
|
|
561
|
-
currentVisualCursor = [
|
|
562
|
-
visualLines.length - 1,
|
|
563
|
-
cursorLogCol - currentPosInLogLine, // Visual col is also code point index within visual line
|
|
564
|
-
];
|
|
565
|
-
}
|
|
566
|
-
else if (cursorLogCol === currentPosInLogLine + numCodePointsInChunk &&
|
|
567
|
-
numCodePointsInChunk > 0) {
|
|
568
|
-
// Cursor is exactly at the end of this non-empty chunk
|
|
569
|
-
currentVisualCursor = [
|
|
570
|
-
visualLines.length - 1,
|
|
571
|
-
numCodePointsInChunk,
|
|
572
|
-
];
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
550
|
const logicalStartOfThisChunk = currentPosInLogLine;
|
|
576
551
|
currentPosInLogLine += numCodePointsInChunk;
|
|
577
552
|
// If the chunk processed did not consume the entire logical line,
|
|
@@ -584,20 +559,6 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
|
|
|
584
559
|
currentPosInLogLine++;
|
|
585
560
|
}
|
|
586
561
|
}
|
|
587
|
-
// After all chunks of a non-empty logical line are processed,
|
|
588
|
-
// if the cursor is at the very end of this logical line, update visual cursor.
|
|
589
|
-
if (logIndex === logicalCursor[0] &&
|
|
590
|
-
logicalCursor[1] === codePointsInLogLine.length // Cursor at end of logical line
|
|
591
|
-
) {
|
|
592
|
-
const lastVisualLineIdx = visualLines.length - 1;
|
|
593
|
-
if (lastVisualLineIdx >= 0 &&
|
|
594
|
-
visualLines[lastVisualLineIdx] !== undefined) {
|
|
595
|
-
currentVisualCursor = [
|
|
596
|
-
lastVisualLineIdx,
|
|
597
|
-
cpLen(visualLines[lastVisualLineIdx]), // Cursor at end of last visual line for this logical line
|
|
598
|
-
];
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
562
|
}
|
|
602
563
|
});
|
|
603
564
|
// If the entire logical text was empty, ensure there's one empty visual line.
|
|
@@ -610,23 +571,46 @@ function calculateVisualLayout(logicalLines, logicalCursor, viewportWidth) {
|
|
|
610
571
|
logicalToVisualMap[0].push([0, 0]);
|
|
611
572
|
visualToLogicalMap.push([0, 0]);
|
|
612
573
|
}
|
|
613
|
-
currentVisualCursor = [0, 0];
|
|
614
|
-
}
|
|
615
|
-
// Handle cursor at the very end of the text (after all processing)
|
|
616
|
-
// This case might be covered by the loop end condition now, but kept for safety.
|
|
617
|
-
else if (logicalCursor[0] === logicalLines.length - 1 &&
|
|
618
|
-
logicalCursor[1] === cpLen(logicalLines[logicalLines.length - 1]) &&
|
|
619
|
-
visualLines.length > 0) {
|
|
620
|
-
const lastVisLineIdx = visualLines.length - 1;
|
|
621
|
-
currentVisualCursor = [lastVisLineIdx, cpLen(visualLines[lastVisLineIdx])];
|
|
622
574
|
}
|
|
623
575
|
return {
|
|
624
576
|
visualLines,
|
|
625
|
-
visualCursor: currentVisualCursor,
|
|
626
577
|
logicalToVisualMap,
|
|
627
578
|
visualToLogicalMap,
|
|
628
579
|
};
|
|
629
580
|
}
|
|
581
|
+
// Calculates the visual cursor position based on a pre-calculated layout.
|
|
582
|
+
// This is a lightweight operation.
|
|
583
|
+
function calculateVisualCursorFromLayout(layout, logicalCursor) {
|
|
584
|
+
const { logicalToVisualMap, visualLines } = layout;
|
|
585
|
+
const [logicalRow, logicalCol] = logicalCursor;
|
|
586
|
+
const segmentsForLogicalLine = logicalToVisualMap[logicalRow];
|
|
587
|
+
if (!segmentsForLogicalLine || segmentsForLogicalLine.length === 0) {
|
|
588
|
+
// This can happen for an empty document.
|
|
589
|
+
return [0, 0];
|
|
590
|
+
}
|
|
591
|
+
// Find the segment where the logical column fits.
|
|
592
|
+
// The segments are sorted by startColInLogical.
|
|
593
|
+
let targetSegmentIndex = segmentsForLogicalLine.findIndex(([, startColInLogical], index) => {
|
|
594
|
+
const nextStartColInLogical = index + 1 < segmentsForLogicalLine.length
|
|
595
|
+
? segmentsForLogicalLine[index + 1][1]
|
|
596
|
+
: Infinity;
|
|
597
|
+
return (logicalCol >= startColInLogical && logicalCol < nextStartColInLogical);
|
|
598
|
+
});
|
|
599
|
+
// If not found, it means the cursor is at the end of the logical line.
|
|
600
|
+
if (targetSegmentIndex === -1) {
|
|
601
|
+
if (logicalCol === 0) {
|
|
602
|
+
targetSegmentIndex = 0;
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
targetSegmentIndex = segmentsForLogicalLine.length - 1;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const [visualRow, startColInLogical] = segmentsForLogicalLine[targetSegmentIndex];
|
|
609
|
+
const visualCol = logicalCol - startColInLogical;
|
|
610
|
+
// The visual column should not exceed the length of the visual line.
|
|
611
|
+
const clampedVisualCol = Math.min(visualCol, cpLen(visualLines[visualRow] ?? ''));
|
|
612
|
+
return [visualRow, clampedVisualCol];
|
|
613
|
+
}
|
|
630
614
|
const historyLimit = 100;
|
|
631
615
|
export const pushUndo = (currentState) => {
|
|
632
616
|
const snapshot = {
|
|
@@ -640,7 +624,7 @@ export const pushUndo = (currentState) => {
|
|
|
640
624
|
}
|
|
641
625
|
return { ...currentState, undoStack: newStack, redoStack: [] };
|
|
642
626
|
};
|
|
643
|
-
|
|
627
|
+
function textBufferReducerLogic(state, action) {
|
|
644
628
|
const pushUndoLocal = pushUndo;
|
|
645
629
|
const currentLine = (r) => state.lines[r] ?? '';
|
|
646
630
|
const currentLineLen = (r) => cpLen(currentLine(r));
|
|
@@ -727,68 +711,101 @@ export function textBufferReducer(state, action) {
|
|
|
727
711
|
preferredCol: null,
|
|
728
712
|
};
|
|
729
713
|
}
|
|
730
|
-
case '
|
|
731
|
-
|
|
714
|
+
case 'set_viewport': {
|
|
715
|
+
const { width, height } = action.payload;
|
|
716
|
+
if (width === state.viewportWidth && height === state.viewportHeight) {
|
|
732
717
|
return state;
|
|
733
718
|
}
|
|
734
|
-
return {
|
|
719
|
+
return {
|
|
720
|
+
...state,
|
|
721
|
+
viewportWidth: width,
|
|
722
|
+
viewportHeight: height,
|
|
723
|
+
};
|
|
735
724
|
}
|
|
736
725
|
case 'move': {
|
|
737
726
|
const { dir } = action.payload;
|
|
738
|
-
const {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
727
|
+
const { cursorRow, cursorCol, lines, visualLayout, preferredCol } = state;
|
|
728
|
+
// Visual movements
|
|
729
|
+
if (dir === 'left' ||
|
|
730
|
+
dir === 'right' ||
|
|
731
|
+
dir === 'up' ||
|
|
732
|
+
dir === 'down' ||
|
|
733
|
+
dir === 'home' ||
|
|
734
|
+
dir === 'end') {
|
|
735
|
+
const visualCursor = calculateVisualCursorFromLayout(visualLayout, [
|
|
736
|
+
cursorRow,
|
|
737
|
+
cursorCol,
|
|
738
|
+
]);
|
|
739
|
+
const { visualLines, visualToLogicalMap } = visualLayout;
|
|
740
|
+
let newVisualRow = visualCursor[0];
|
|
741
|
+
let newVisualCol = visualCursor[1];
|
|
742
|
+
let newPreferredCol = preferredCol;
|
|
743
|
+
const currentVisLineLen = cpLen(visualLines[newVisualRow] ?? '');
|
|
744
|
+
switch (dir) {
|
|
745
|
+
case 'left':
|
|
746
|
+
newPreferredCol = null;
|
|
747
|
+
if (newVisualCol > 0) {
|
|
748
|
+
newVisualCol--;
|
|
749
|
+
}
|
|
750
|
+
else if (newVisualRow > 0) {
|
|
751
|
+
newVisualRow--;
|
|
752
|
+
newVisualCol = cpLen(visualLines[newVisualRow] ?? '');
|
|
753
|
+
}
|
|
754
|
+
break;
|
|
755
|
+
case 'right':
|
|
756
|
+
newPreferredCol = null;
|
|
757
|
+
if (newVisualCol < currentVisLineLen) {
|
|
758
|
+
newVisualCol++;
|
|
759
|
+
}
|
|
760
|
+
else if (newVisualRow < visualLines.length - 1) {
|
|
761
|
+
newVisualRow++;
|
|
762
|
+
newVisualCol = 0;
|
|
763
|
+
}
|
|
764
|
+
break;
|
|
765
|
+
case 'up':
|
|
766
|
+
if (newVisualRow > 0) {
|
|
767
|
+
if (newPreferredCol === null)
|
|
768
|
+
newPreferredCol = newVisualCol;
|
|
769
|
+
newVisualRow--;
|
|
770
|
+
newVisualCol = clamp(newPreferredCol, 0, cpLen(visualLines[newVisualRow] ?? ''));
|
|
771
|
+
}
|
|
772
|
+
break;
|
|
773
|
+
case 'down':
|
|
774
|
+
if (newVisualRow < visualLines.length - 1) {
|
|
775
|
+
if (newPreferredCol === null)
|
|
776
|
+
newPreferredCol = newVisualCol;
|
|
777
|
+
newVisualRow++;
|
|
778
|
+
newVisualCol = clamp(newPreferredCol, 0, cpLen(visualLines[newVisualRow] ?? ''));
|
|
779
|
+
}
|
|
780
|
+
break;
|
|
781
|
+
case 'home':
|
|
782
|
+
newPreferredCol = null;
|
|
763
783
|
newVisualCol = 0;
|
|
784
|
+
break;
|
|
785
|
+
case 'end':
|
|
786
|
+
newPreferredCol = null;
|
|
787
|
+
newVisualCol = currentVisLineLen;
|
|
788
|
+
break;
|
|
789
|
+
default: {
|
|
790
|
+
const exhaustiveCheck = dir;
|
|
791
|
+
console.error(`Unknown visual movement direction: ${exhaustiveCheck}`);
|
|
792
|
+
return state;
|
|
764
793
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
newVisualCol = clamp(newPreferredCol, 0, cpLen(visualLines[newVisualRow] ?? ''));
|
|
780
|
-
}
|
|
781
|
-
break;
|
|
782
|
-
case 'home':
|
|
783
|
-
newPreferredCol = null;
|
|
784
|
-
newVisualCol = 0;
|
|
785
|
-
break;
|
|
786
|
-
case 'end':
|
|
787
|
-
newPreferredCol = null;
|
|
788
|
-
newVisualCol = currentVisLineLen;
|
|
789
|
-
break;
|
|
794
|
+
}
|
|
795
|
+
if (visualToLogicalMap[newVisualRow]) {
|
|
796
|
+
const [logRow, logStartCol] = visualToLogicalMap[newVisualRow];
|
|
797
|
+
return {
|
|
798
|
+
...state,
|
|
799
|
+
cursorRow: logRow,
|
|
800
|
+
cursorCol: clamp(logStartCol + newVisualCol, 0, cpLen(lines[logRow] ?? '')),
|
|
801
|
+
preferredCol: newPreferredCol,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
return state;
|
|
805
|
+
}
|
|
806
|
+
// Logical movements
|
|
807
|
+
switch (dir) {
|
|
790
808
|
case 'wordLeft': {
|
|
791
|
-
const { cursorRow, cursorCol, lines } = state;
|
|
792
809
|
if (cursorCol === 0 && cursorRow === 0)
|
|
793
810
|
return state;
|
|
794
811
|
let newCursorRow = cursorRow;
|
|
@@ -827,7 +844,6 @@ export function textBufferReducer(state, action) {
|
|
|
827
844
|
};
|
|
828
845
|
}
|
|
829
846
|
case 'wordRight': {
|
|
830
|
-
const { cursorRow, cursorCol, lines } = state;
|
|
831
847
|
if (cursorRow === lines.length - 1 &&
|
|
832
848
|
cursorCol === cpLen(lines[cursorRow] ?? '')) {
|
|
833
849
|
return state;
|
|
@@ -856,18 +872,14 @@ export function textBufferReducer(state, action) {
|
|
|
856
872
|
};
|
|
857
873
|
}
|
|
858
874
|
default:
|
|
859
|
-
|
|
875
|
+
return state;
|
|
860
876
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
preferredCol: newPreferredCol,
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
return state;
|
|
877
|
+
}
|
|
878
|
+
case 'set_cursor': {
|
|
879
|
+
return {
|
|
880
|
+
...state,
|
|
881
|
+
...action.payload,
|
|
882
|
+
};
|
|
871
883
|
}
|
|
872
884
|
case 'delete': {
|
|
873
885
|
const { cursorRow, cursorCol, lines } = state;
|
|
@@ -878,7 +890,11 @@ export function textBufferReducer(state, action) {
|
|
|
878
890
|
newLines[cursorRow] =
|
|
879
891
|
cpSlice(lineContent, 0, cursorCol) +
|
|
880
892
|
cpSlice(lineContent, cursorCol + 1);
|
|
881
|
-
return {
|
|
893
|
+
return {
|
|
894
|
+
...nextState,
|
|
895
|
+
lines: newLines,
|
|
896
|
+
preferredCol: null,
|
|
897
|
+
};
|
|
882
898
|
}
|
|
883
899
|
else if (cursorRow < lines.length - 1) {
|
|
884
900
|
const nextState = pushUndoLocal(state);
|
|
@@ -886,7 +902,11 @@ export function textBufferReducer(state, action) {
|
|
|
886
902
|
const newLines = [...nextState.lines];
|
|
887
903
|
newLines[cursorRow] = lineContent + nextLineContent;
|
|
888
904
|
newLines.splice(cursorRow + 1, 1);
|
|
889
|
-
return {
|
|
905
|
+
return {
|
|
906
|
+
...nextState,
|
|
907
|
+
lines: newLines,
|
|
908
|
+
preferredCol: null,
|
|
909
|
+
};
|
|
890
910
|
}
|
|
891
911
|
return state;
|
|
892
912
|
}
|
|
@@ -894,78 +914,62 @@ export function textBufferReducer(state, action) {
|
|
|
894
914
|
const { cursorRow, cursorCol } = state;
|
|
895
915
|
if (cursorCol === 0 && cursorRow === 0)
|
|
896
916
|
return state;
|
|
897
|
-
|
|
917
|
+
const nextState = pushUndoLocal(state);
|
|
918
|
+
const newLines = [...nextState.lines];
|
|
919
|
+
let newCursorRow = cursorRow;
|
|
920
|
+
let newCursorCol = cursorCol;
|
|
921
|
+
if (newCursorCol > 0) {
|
|
922
|
+
const lineContent = currentLine(newCursorRow);
|
|
923
|
+
const prevWordStart = findPrevWordStartInLine(lineContent, newCursorCol);
|
|
924
|
+
const start = prevWordStart === null ? 0 : prevWordStart;
|
|
925
|
+
newLines[newCursorRow] =
|
|
926
|
+
cpSlice(lineContent, 0, start) + cpSlice(lineContent, newCursorCol);
|
|
927
|
+
newCursorCol = start;
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
898
930
|
// Act as a backspace
|
|
899
|
-
const nextState = pushUndoLocal(state);
|
|
900
931
|
const prevLineContent = currentLine(cursorRow - 1);
|
|
901
932
|
const currentLineContentVal = currentLine(cursorRow);
|
|
902
933
|
const newCol = cpLen(prevLineContent);
|
|
903
|
-
const newLines = [...nextState.lines];
|
|
904
934
|
newLines[cursorRow - 1] = prevLineContent + currentLineContentVal;
|
|
905
935
|
newLines.splice(cursorRow, 1);
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
lines: newLines,
|
|
909
|
-
cursorRow: cursorRow - 1,
|
|
910
|
-
cursorCol: newCol,
|
|
911
|
-
preferredCol: null,
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
const nextState = pushUndoLocal(state);
|
|
915
|
-
const lineContent = currentLine(cursorRow);
|
|
916
|
-
const arr = toCodePoints(lineContent);
|
|
917
|
-
let start = cursorCol;
|
|
918
|
-
let onlySpaces = true;
|
|
919
|
-
for (let i = 0; i < start; i++) {
|
|
920
|
-
if (isWordChar(arr[i])) {
|
|
921
|
-
onlySpaces = false;
|
|
922
|
-
break;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
if (onlySpaces && start > 0) {
|
|
926
|
-
start--;
|
|
927
|
-
}
|
|
928
|
-
else {
|
|
929
|
-
while (start > 0 && !isWordChar(arr[start - 1]))
|
|
930
|
-
start--;
|
|
931
|
-
while (start > 0 && isWordChar(arr[start - 1]))
|
|
932
|
-
start--;
|
|
936
|
+
newCursorRow--;
|
|
937
|
+
newCursorCol = newCol;
|
|
933
938
|
}
|
|
934
|
-
const newLines = [...nextState.lines];
|
|
935
|
-
newLines[cursorRow] =
|
|
936
|
-
cpSlice(lineContent, 0, start) + cpSlice(lineContent, cursorCol);
|
|
937
939
|
return {
|
|
938
940
|
...nextState,
|
|
939
941
|
lines: newLines,
|
|
940
|
-
|
|
942
|
+
cursorRow: newCursorRow,
|
|
943
|
+
cursorCol: newCursorCol,
|
|
941
944
|
preferredCol: null,
|
|
942
945
|
};
|
|
943
946
|
}
|
|
944
947
|
case 'delete_word_right': {
|
|
945
948
|
const { cursorRow, cursorCol, lines } = state;
|
|
946
949
|
const lineContent = currentLine(cursorRow);
|
|
947
|
-
const
|
|
948
|
-
if (cursorCol >=
|
|
950
|
+
const lineLen = cpLen(lineContent);
|
|
951
|
+
if (cursorCol >= lineLen && cursorRow === lines.length - 1) {
|
|
949
952
|
return state;
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
+
}
|
|
954
|
+
const nextState = pushUndoLocal(state);
|
|
955
|
+
const newLines = [...nextState.lines];
|
|
956
|
+
if (cursorCol >= lineLen) {
|
|
957
|
+
// Act as a delete, joining with the next line
|
|
953
958
|
const nextLineContent = currentLine(cursorRow + 1);
|
|
954
|
-
const newLines = [...nextState.lines];
|
|
955
959
|
newLines[cursorRow] = lineContent + nextLineContent;
|
|
956
960
|
newLines.splice(cursorRow + 1, 1);
|
|
957
|
-
return { ...nextState, lines: newLines, preferredCol: null };
|
|
958
961
|
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
962
|
+
else {
|
|
963
|
+
const nextWordStart = findNextWordStartInLine(lineContent, cursorCol);
|
|
964
|
+
const end = nextWordStart === null ? lineLen : nextWordStart;
|
|
965
|
+
newLines[cursorRow] =
|
|
966
|
+
cpSlice(lineContent, 0, cursorCol) + cpSlice(lineContent, end);
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
...nextState,
|
|
970
|
+
lines: newLines,
|
|
971
|
+
preferredCol: null,
|
|
972
|
+
};
|
|
969
973
|
}
|
|
970
974
|
case 'kill_line_right': {
|
|
971
975
|
const { cursorRow, cursorCol, lines } = state;
|
|
@@ -974,7 +978,10 @@ export function textBufferReducer(state, action) {
|
|
|
974
978
|
const nextState = pushUndoLocal(state);
|
|
975
979
|
const newLines = [...nextState.lines];
|
|
976
980
|
newLines[cursorRow] = cpSlice(lineContent, 0, cursorCol);
|
|
977
|
-
return {
|
|
981
|
+
return {
|
|
982
|
+
...nextState,
|
|
983
|
+
lines: newLines,
|
|
984
|
+
};
|
|
978
985
|
}
|
|
979
986
|
else if (cursorRow < lines.length - 1) {
|
|
980
987
|
// Act as a delete
|
|
@@ -983,7 +990,11 @@ export function textBufferReducer(state, action) {
|
|
|
983
990
|
const newLines = [...nextState.lines];
|
|
984
991
|
newLines[cursorRow] = lineContent + nextLineContent;
|
|
985
992
|
newLines.splice(cursorRow + 1, 1);
|
|
986
|
-
return {
|
|
993
|
+
return {
|
|
994
|
+
...nextState,
|
|
995
|
+
lines: newLines,
|
|
996
|
+
preferredCol: null,
|
|
997
|
+
};
|
|
987
998
|
}
|
|
988
999
|
return state;
|
|
989
1000
|
}
|
|
@@ -1094,11 +1105,23 @@ export function textBufferReducer(state, action) {
|
|
|
1094
1105
|
}
|
|
1095
1106
|
}
|
|
1096
1107
|
}
|
|
1108
|
+
export function textBufferReducer(state, action) {
|
|
1109
|
+
const newState = textBufferReducerLogic(state, action);
|
|
1110
|
+
if (newState.lines !== state.lines ||
|
|
1111
|
+
newState.viewportWidth !== state.viewportWidth) {
|
|
1112
|
+
return {
|
|
1113
|
+
...newState,
|
|
1114
|
+
visualLayout: calculateLayout(newState.lines, newState.viewportWidth),
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
return newState;
|
|
1118
|
+
}
|
|
1097
1119
|
// --- End of reducer logic ---
|
|
1098
1120
|
export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewport, stdin, setRawMode, onChange, isValidPath, shellModeActive = false, }) {
|
|
1099
1121
|
const initialState = useMemo(() => {
|
|
1100
1122
|
const lines = initialText.split('\n');
|
|
1101
1123
|
const [initialCursorRow, initialCursorCol] = calculateInitialCursorPosition(lines.length === 0 ? [''] : lines, initialCursorOffset);
|
|
1124
|
+
const visualLayout = calculateLayout(lines.length === 0 ? [''] : lines, viewport.width);
|
|
1102
1125
|
return {
|
|
1103
1126
|
lines: lines.length === 0 ? [''] : lines,
|
|
1104
1127
|
cursorRow: initialCursorRow,
|
|
@@ -1109,13 +1132,15 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1109
1132
|
clipboard: null,
|
|
1110
1133
|
selectionAnchor: null,
|
|
1111
1134
|
viewportWidth: viewport.width,
|
|
1135
|
+
viewportHeight: viewport.height,
|
|
1136
|
+
visualLayout,
|
|
1112
1137
|
};
|
|
1113
|
-
}, [initialText, initialCursorOffset, viewport.width]);
|
|
1138
|
+
}, [initialText, initialCursorOffset, viewport.width, viewport.height]);
|
|
1114
1139
|
const [state, dispatch] = useReducer(textBufferReducer, initialState);
|
|
1115
|
-
const { lines, cursorRow, cursorCol, preferredCol, selectionAnchor } = state;
|
|
1140
|
+
const { lines, cursorRow, cursorCol, preferredCol, selectionAnchor, visualLayout, } = state;
|
|
1116
1141
|
const text = useMemo(() => lines.join('\n'), [lines]);
|
|
1117
|
-
const
|
|
1118
|
-
const { visualLines,
|
|
1142
|
+
const visualCursor = useMemo(() => calculateVisualCursorFromLayout(visualLayout, [cursorRow, cursorCol]), [visualLayout, cursorRow, cursorCol]);
|
|
1143
|
+
const { visualLines, visualToLogicalMap } = visualLayout;
|
|
1119
1144
|
const [visualScrollRow, setVisualScrollRow] = useState(0);
|
|
1120
1145
|
useEffect(() => {
|
|
1121
1146
|
if (onChange) {
|
|
@@ -1123,11 +1148,16 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1123
1148
|
}
|
|
1124
1149
|
}, [text, onChange]);
|
|
1125
1150
|
useEffect(() => {
|
|
1126
|
-
dispatch({
|
|
1127
|
-
|
|
1151
|
+
dispatch({
|
|
1152
|
+
type: 'set_viewport',
|
|
1153
|
+
payload: { width: viewport.width, height: viewport.height },
|
|
1154
|
+
});
|
|
1155
|
+
}, [viewport.width, viewport.height]);
|
|
1128
1156
|
// Update visual scroll (vertical)
|
|
1129
1157
|
useEffect(() => {
|
|
1130
1158
|
const { height } = viewport;
|
|
1159
|
+
const totalVisualLines = visualLines.length;
|
|
1160
|
+
const maxScrollStart = Math.max(0, totalVisualLines - height);
|
|
1131
1161
|
let newVisualScrollRow = visualScrollRow;
|
|
1132
1162
|
if (visualCursor[0] < visualScrollRow) {
|
|
1133
1163
|
newVisualScrollRow = visualCursor[0];
|
|
@@ -1135,10 +1165,13 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1135
1165
|
else if (visualCursor[0] >= visualScrollRow + height) {
|
|
1136
1166
|
newVisualScrollRow = visualCursor[0] - height + 1;
|
|
1137
1167
|
}
|
|
1168
|
+
// When the number of visual lines shrinks (e.g., after widening the viewport),
|
|
1169
|
+
// ensure scroll never starts beyond the last valid start so we can render a full window.
|
|
1170
|
+
newVisualScrollRow = clamp(newVisualScrollRow, 0, maxScrollStart);
|
|
1138
1171
|
if (newVisualScrollRow !== visualScrollRow) {
|
|
1139
1172
|
setVisualScrollRow(newVisualScrollRow);
|
|
1140
1173
|
}
|
|
1141
|
-
}, [visualCursor, visualScrollRow, viewport]);
|
|
1174
|
+
}, [visualCursor, visualScrollRow, viewport, visualLines.length]);
|
|
1142
1175
|
const insert = useCallback((ch, { paste = false } = {}) => {
|
|
1143
1176
|
if (/[\n\r]/.test(ch)) {
|
|
1144
1177
|
dispatch({ type: 'insert', payload: ch });
|
|
@@ -1186,7 +1219,7 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1186
1219
|
}, []);
|
|
1187
1220
|
const move = useCallback((dir) => {
|
|
1188
1221
|
dispatch({ type: 'move', payload: { dir } });
|
|
1189
|
-
}, []);
|
|
1222
|
+
}, [dispatch]);
|
|
1190
1223
|
const undo = useCallback(() => {
|
|
1191
1224
|
dispatch({ type: 'undo' });
|
|
1192
1225
|
}, []);
|
|
@@ -1404,10 +1437,24 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1404
1437
|
backspace();
|
|
1405
1438
|
else if (key.name === 'delete' || (key.ctrl && key.name === 'd'))
|
|
1406
1439
|
del();
|
|
1440
|
+
else if (key.ctrl && !key.shift && key.name === 'z')
|
|
1441
|
+
undo();
|
|
1442
|
+
else if (key.ctrl && key.shift && key.name === 'z')
|
|
1443
|
+
redo();
|
|
1407
1444
|
else if (input && !key.ctrl && !key.meta) {
|
|
1408
1445
|
insert(input, { paste: key.paste });
|
|
1409
1446
|
}
|
|
1410
|
-
}, [
|
|
1447
|
+
}, [
|
|
1448
|
+
newline,
|
|
1449
|
+
move,
|
|
1450
|
+
deleteWordLeft,
|
|
1451
|
+
deleteWordRight,
|
|
1452
|
+
backspace,
|
|
1453
|
+
del,
|
|
1454
|
+
insert,
|
|
1455
|
+
undo,
|
|
1456
|
+
redo,
|
|
1457
|
+
]);
|
|
1411
1458
|
const renderedVisualLines = useMemo(() => visualLines.slice(visualScrollRow, visualScrollRow + viewport.height), [visualLines, visualScrollRow, viewport.height]);
|
|
1412
1459
|
const replaceRange = useCallback((startRow, startCol, endRow, endCol, text) => {
|
|
1413
1460
|
dispatch({
|
|
@@ -1423,7 +1470,7 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1423
1470
|
const moveToOffset = useCallback((offset) => {
|
|
1424
1471
|
dispatch({ type: 'move_to_offset', payload: { offset } });
|
|
1425
1472
|
}, []);
|
|
1426
|
-
const returnValue = {
|
|
1473
|
+
const returnValue = useMemo(() => ({
|
|
1427
1474
|
lines,
|
|
1428
1475
|
text,
|
|
1429
1476
|
cursor: [cursorRow, cursorCol],
|
|
@@ -1433,6 +1480,7 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1433
1480
|
viewportVisualLines: renderedVisualLines,
|
|
1434
1481
|
visualCursor,
|
|
1435
1482
|
visualScrollRow,
|
|
1483
|
+
visualToLogicalMap,
|
|
1436
1484
|
setText,
|
|
1437
1485
|
insert,
|
|
1438
1486
|
newline,
|
|
@@ -1483,7 +1531,68 @@ export function useTextBuffer({ initialText = '', initialCursorOffset = 0, viewp
|
|
|
1483
1531
|
vimMoveToLastLine,
|
|
1484
1532
|
vimMoveToLine,
|
|
1485
1533
|
vimEscapeInsertMode,
|
|
1486
|
-
}
|
|
1534
|
+
}), [
|
|
1535
|
+
lines,
|
|
1536
|
+
text,
|
|
1537
|
+
cursorRow,
|
|
1538
|
+
cursorCol,
|
|
1539
|
+
preferredCol,
|
|
1540
|
+
selectionAnchor,
|
|
1541
|
+
visualLines,
|
|
1542
|
+
renderedVisualLines,
|
|
1543
|
+
visualCursor,
|
|
1544
|
+
visualScrollRow,
|
|
1545
|
+
setText,
|
|
1546
|
+
insert,
|
|
1547
|
+
newline,
|
|
1548
|
+
backspace,
|
|
1549
|
+
del,
|
|
1550
|
+
move,
|
|
1551
|
+
undo,
|
|
1552
|
+
redo,
|
|
1553
|
+
replaceRange,
|
|
1554
|
+
replaceRangeByOffset,
|
|
1555
|
+
moveToOffset,
|
|
1556
|
+
deleteWordLeft,
|
|
1557
|
+
deleteWordRight,
|
|
1558
|
+
killLineRight,
|
|
1559
|
+
killLineLeft,
|
|
1560
|
+
handleInput,
|
|
1561
|
+
openInExternalEditor,
|
|
1562
|
+
vimDeleteWordForward,
|
|
1563
|
+
vimDeleteWordBackward,
|
|
1564
|
+
vimDeleteWordEnd,
|
|
1565
|
+
vimChangeWordForward,
|
|
1566
|
+
vimChangeWordBackward,
|
|
1567
|
+
vimChangeWordEnd,
|
|
1568
|
+
vimDeleteLine,
|
|
1569
|
+
vimChangeLine,
|
|
1570
|
+
vimDeleteToEndOfLine,
|
|
1571
|
+
vimChangeToEndOfLine,
|
|
1572
|
+
vimChangeMovement,
|
|
1573
|
+
vimMoveLeft,
|
|
1574
|
+
vimMoveRight,
|
|
1575
|
+
vimMoveUp,
|
|
1576
|
+
vimMoveDown,
|
|
1577
|
+
vimMoveWordForward,
|
|
1578
|
+
vimMoveWordBackward,
|
|
1579
|
+
vimMoveWordEnd,
|
|
1580
|
+
vimDeleteChar,
|
|
1581
|
+
vimInsertAtCursor,
|
|
1582
|
+
vimAppendAtCursor,
|
|
1583
|
+
vimOpenLineBelow,
|
|
1584
|
+
vimOpenLineAbove,
|
|
1585
|
+
vimAppendAtLineEnd,
|
|
1586
|
+
vimInsertAtLineStart,
|
|
1587
|
+
vimMoveToLineStart,
|
|
1588
|
+
vimMoveToLineEnd,
|
|
1589
|
+
vimMoveToFirstNonWhitespace,
|
|
1590
|
+
vimMoveToFirstLine,
|
|
1591
|
+
vimMoveToLastLine,
|
|
1592
|
+
vimMoveToLine,
|
|
1593
|
+
vimEscapeInsertMode,
|
|
1594
|
+
visualToLogicalMap,
|
|
1595
|
+
]);
|
|
1487
1596
|
return returnValue;
|
|
1488
1597
|
}
|
|
1489
1598
|
//# sourceMappingURL=text-buffer.js.map
|