@kabmo-labs/kabmo 0.8.0 → 0.10.0
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/README.md +52 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +336 -336
- package/dist/client/static/js/index-18xe7655.css +1 -0
- package/dist/client/static/js/{index-qwpvd9fv.js → index-nxpe7835.js} +933 -898
- package/package.json +11 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +249 -0
- package/src/client/components/common/code-surface/bracket-guide.ts +131 -0
- package/src/client/components/common/code-surface/documents.test.ts +122 -0
- package/src/client/components/common/code-surface/documents.ts +286 -0
- package/src/client/components/common/code-surface/extensions.test.ts +115 -0
- package/src/client/components/common/code-surface/extensions.ts +295 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +218 -0
- package/src/client/components/common/code-surface/fold.test.ts +148 -0
- package/src/client/components/common/code-surface/fold.ts +118 -0
- package/src/client/components/common/code-surface/handle.ts +102 -0
- package/src/client/components/common/code-surface/indent-guide.ts +104 -0
- package/src/client/components/common/code-surface/indent.test.ts +239 -0
- package/src/client/components/common/code-surface/indent.ts +124 -0
- package/src/client/components/common/code-surface/index.tsx +283 -314
- package/src/client/components/common/code-surface/keymap.test.ts +133 -0
- package/src/client/components/common/code-surface/keymap.ts +256 -0
- package/src/client/components/common/code-surface/line-commands.test.ts +90 -0
- package/src/client/components/common/code-surface/line-commands.ts +103 -0
- package/src/client/components/common/code-surface/marks.ts +74 -0
- package/src/client/components/common/code-surface/props.ts +87 -0
- package/src/client/components/common/code-surface/shiki.ts +234 -0
- package/src/client/components/common/code-surface/stream-language.test.ts +118 -0
- package/src/client/components/common/code-surface/stream-language.ts +123 -0
- package/src/client/components/common/code-surface/sync.test.ts +185 -0
- package/src/client/components/common/code-surface/sync.ts +58 -0
- package/src/client/components/common/code-surface/theme.test.ts +237 -0
- package/src/client/components/common/code-surface/theme.ts +224 -0
- package/src/client/components/common/code-surface/typing.test.ts +97 -0
- package/src/client/components/common/code-surface/typing.ts +111 -0
- package/src/client/components/common/editor-view-buttons/index.test.tsx +148 -0
- package/src/client/components/common/editor-view-buttons/index.tsx +109 -0
- package/src/client/components/common/shell-update-button/Modal.tsx +163 -0
- package/src/client/components/common/shell-update-button/index.test.tsx +251 -0
- package/src/client/components/common/shell-update-button/index.tsx +125 -0
- package/src/client/components/common/toolbar-row/index.test.tsx +215 -0
- package/src/client/components/common/toolbar-row/index.tsx +260 -0
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +58 -78
- package/src/client/components/layout/desktop-layout/index.tsx +65 -67
- package/src/client/components/layout/desktop-layout/resizer/index.tsx +6 -3
- package/src/client/components/layout/session-sidebar/Footer.tsx +8 -15
- package/src/client/components/mobile/LayoutWrapper.tsx +1 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullDiff.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +98 -71
- package/src/client/components/mobile/mobile-right-sidebar/Header.tsx +20 -1
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.test.tsx +137 -0
- package/src/client/components/mobile/mobile-right-sidebar/OutlineButton.tsx +14 -3
- package/src/client/components/mobile/mobile-right-sidebar/editor-props.ts +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/Footer.tsx +9 -21
- package/src/client/components/settings/Modal.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +9 -0
- package/src/client/components/settings/categories/appearance-settings/EditorIndentSection.tsx +87 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.test.tsx +167 -0
- package/src/client/components/settings/categories/appearance-settings/EditorThemeSection.tsx +184 -0
- package/src/client/components/settings/categories/appearance-settings/EditorTypingSection.tsx +99 -0
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +8 -2
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +16 -8
- package/src/client/components/workspace/chat-timeline/SystemNotice.tsx +9 -4
- package/src/client/components/workspace/chat-timeline/TaskResultContent.tsx +9 -7
- package/src/client/components/workspace/chat-timeline/chat-input/expansion.ts +9 -4
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +15 -11
- package/src/client/components/workspace/chat-timeline/chat-input/stretch-send.test.tsx +165 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +132 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +120 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.test.tsx +319 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +285 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +2 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/hashline-patch/index.tsx +34 -29
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AstEdit.tsx +11 -9
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Bash.tsx +10 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Edit.tsx +25 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.tsx +8 -11
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.test.ts +114 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/FileMatches.tsx +111 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Read.tsx +7 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/SearchTool.tsx +9 -59
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ArtifactBody.tsx +2 -7
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.test.ts +43 -30
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/DiffView.tsx +49 -32
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/ExcerptCode.tsx +8 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/HighlightedCode.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/JsonCodeBlock.tsx +4 -4
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +179 -0
- package/src/client/components/workspace/diff-panel/ThemedMergeDiffView.tsx +24 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +224 -186
- package/src/client/components/workspace/diff-panel/ToolbarSegments.tsx +98 -0
- package/src/client/components/workspace/diff-panel/index.tsx +76 -145
- package/src/client/components/workspace/diff-panel/merge.ts +315 -0
- package/src/client/components/workspace/editor/Body.tsx +28 -7
- package/src/client/components/workspace/editor/CommandPalette.tsx +6 -6
- package/src/client/components/workspace/editor/ConflictStrip.tsx +77 -0
- package/src/client/components/workspace/editor/Dialogs.tsx +53 -0
- package/src/client/components/workspace/editor/EmptyEditor.tsx +23 -0
- package/src/client/components/workspace/editor/ExternalChangeStrip.tsx +61 -0
- package/src/client/components/workspace/editor/FileDocument.tsx +146 -63
- package/src/client/components/workspace/editor/FilePane.tsx +47 -7
- package/src/client/components/workspace/editor/FindWidget.test.ts +9 -5
- package/src/client/components/workspace/editor/FindWidget.tsx +36 -2
- package/src/client/components/workspace/editor/GoToLineModal.tsx +123 -0
- package/src/client/components/workspace/editor/Notices.tsx +71 -0
- package/src/client/components/workspace/editor/Pane.tsx +118 -0
- package/src/client/components/workspace/editor/PluginColumn.tsx +32 -0
- package/src/client/components/workspace/editor/QuickOpenModal.tsx +146 -0
- package/src/client/components/workspace/editor/SaveAsModal.tsx +175 -0
- package/src/client/components/workspace/editor/SplitColumn.tsx +98 -0
- package/src/client/components/workspace/editor/SplitPane.tsx +57 -0
- package/src/client/components/workspace/editor/StatusBar.tsx +106 -0
- package/src/client/components/workspace/editor/TabContextMenu.tsx +75 -0
- package/src/client/components/workspace/editor/Tabs.tsx +195 -18
- package/src/client/components/workspace/editor/Toolbar.tsx +110 -140
- package/src/client/components/workspace/editor/index.tsx +201 -193
- package/src/client/components/workspace/editor/props.ts +64 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +300 -0
- package/src/client/components/workspace/file-explorer/Modals.tsx +14 -1
- package/src/client/components/workspace/file-explorer/OutlineSection.test.tsx +18 -0
- package/src/client/components/workspace/file-explorer/OutlineSection.tsx +10 -3
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +2 -1
- package/src/client/components/workspace/file-explorer/clipboard.test.ts +3 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +61 -0
- package/src/client/components/workspace/file-explorer/index.tsx +10 -48
- package/src/client/components/workspace/file-explorer/local-edit.test.ts +8 -3
- package/src/client/components/workspace/search-panel/Body.tsx +7 -2
- package/src/client/components/workspace/worktree-modal/index.test.tsx +118 -0
- package/src/client/hooks/chat/composer/file-drop.ts +22 -37
- package/src/client/hooks/chat/composer/pipeline.test.ts +76 -0
- package/src/client/hooks/chat/composer/pipeline.ts +12 -1
- package/src/client/hooks/chat/omp/reconnect.test.ts +338 -0
- package/src/client/hooks/chat/omp/reconnect.ts +187 -0
- package/src/client/hooks/chat/omp/run-liveness.test.ts +71 -0
- package/src/client/hooks/chat/omp/run-liveness.ts +65 -0
- package/src/client/hooks/chat/omp/session-list.activity.test.ts +114 -0
- package/src/client/hooks/chat/omp/session-list.test-util.ts +164 -0
- package/src/client/hooks/chat/omp/session-list.test.ts +30 -150
- package/src/client/hooks/chat/omp/session-list.tsx +69 -9
- package/src/client/hooks/chat/timeline/generating.ts +19 -2
- package/src/client/hooks/chat/timeline/index.ts +19 -24
- package/src/client/hooks/chat/timeline/lost-run.test.ts +329 -0
- package/src/client/hooks/chat/timeline/lost-run.ts +177 -0
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +205 -0
- package/src/client/hooks/chat/timeline/session-load.test.ts +61 -162
- package/src/client/hooks/chat/timeline/session-load.ts +69 -37
- package/src/client/hooks/chat/timeline/session-switch.test.ts +65 -0
- package/src/client/hooks/chat/timeline/session-switch.ts +63 -0
- package/src/client/hooks/code/deferred-highlight.test.ts +182 -0
- package/src/client/hooks/code/deferred-highlight.ts +129 -0
- package/src/client/hooks/editor/caret-position.test.ts +58 -0
- package/src/client/hooks/editor/caret-position.ts +48 -0
- package/src/client/hooks/editor/file-editor-types.ts +200 -0
- package/src/client/hooks/editor/find-history.test.ts +132 -0
- package/src/client/hooks/editor/find-history.ts +46 -0
- package/src/client/hooks/editor/find-selection-range.test.ts +100 -0
- package/src/client/hooks/editor/find-selection-range.ts +49 -0
- package/src/client/hooks/editor/find-state.ts +14 -1
- package/src/client/hooks/editor/font.test.ts +0 -93
- package/src/client/hooks/editor/indent-settings.test.ts +104 -0
- package/src/client/hooks/editor/indent-settings.ts +88 -0
- package/src/client/hooks/editor/quick-open.test.ts +141 -0
- package/src/client/hooks/editor/quick-open.ts +127 -0
- package/src/client/hooks/editor/save-as.test.ts +156 -0
- package/src/client/hooks/editor/save-as.ts +122 -0
- package/src/client/hooks/editor/save-file.test.ts +179 -0
- package/src/client/hooks/editor/save-file.ts +73 -28
- package/src/client/hooks/editor/theme.test.ts +206 -0
- package/src/client/hooks/editor/theme.ts +82 -0
- package/src/client/hooks/editor/typing-settings.test.ts +73 -0
- package/src/client/hooks/editor/typing-settings.ts +65 -0
- package/src/client/hooks/editor/use-close-guard.ts +98 -0
- package/src/client/hooks/editor/use-editor-drop-overlay.test.ts +159 -0
- package/src/client/hooks/editor/use-editor-drop.shell.test.ts +224 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +101 -0
- package/src/client/hooks/editor/use-editor-drop.ts +120 -77
- package/src/client/hooks/editor/use-editor-find.test.ts +2 -2
- package/src/client/hooks/editor/use-editor-find.ts +45 -10
- package/src/client/hooks/editor/use-editor-panel-keys.ts +152 -0
- package/src/client/hooks/editor/use-editor-tab-state.ts +71 -0
- package/src/client/hooks/editor/use-external-change-notice.ts +71 -0
- package/src/client/hooks/editor/use-external-change.test.ts +88 -0
- package/src/client/hooks/editor/use-external-change.ts +146 -0
- package/src/client/hooks/editor/use-file-editor.ts +83 -116
- package/src/client/hooks/editor/use-file-read.ts +16 -8
- package/src/client/hooks/editor/use-file-writes.ts +28 -3
- package/src/client/hooks/editor/use-mobile-editor-find.ts +69 -0
- package/src/client/hooks/editor/use-mobile-reveal.ts +53 -0
- package/src/client/hooks/editor/use-outline-view.test.ts +182 -0
- package/src/client/hooks/editor/use-outline-view.ts +94 -7
- package/src/client/hooks/editor/use-scroll-restore.test.ts +55 -2
- package/src/client/hooks/editor/use-scroll-restore.ts +124 -4
- package/src/client/hooks/editor/use-search-reveal-jump.ts +57 -0
- package/src/client/hooks/editor/use-search-reveal.ts +1 -1
- package/src/client/hooks/editor/use-split-editor.test.tsx +169 -0
- package/src/client/hooks/editor/use-split-editor.ts +91 -0
- package/src/client/hooks/editor/use-unload-guard.tsx +117 -0
- package/src/client/hooks/editor/use-write-conflict.test.ts +164 -0
- package/src/client/hooks/editor/use-write-conflict.ts +152 -0
- package/src/client/hooks/editor/wheel-zoom.test.ts +141 -0
- package/src/client/hooks/editor/wheel-zoom.ts +96 -0
- package/src/client/hooks/ui/drag-presence.test.ts +193 -0
- package/src/client/hooks/ui/drag-presence.ts +108 -0
- package/src/client/hooks/ui/settings-modal.test.ts +115 -0
- package/src/client/hooks/ui/settings-modal.ts +56 -0
- package/src/client/hooks/ui/updates/shell-download.test.ts +2 -0
- package/src/client/hooks/ui/updates/shell-download.ts +55 -14
- package/src/client/hooks/ui/updates/shell-offer.test.ts +26 -0
- package/src/client/hooks/ui/updates/shell-update.test.ts +140 -0
- package/src/client/hooks/ui/updates/shell-update.ts +119 -0
- package/src/client/hooks/workspace/diff-file.ts +29 -10
- package/src/client/hooks/workspace/diff-git-actions.ts +147 -0
- package/src/client/hooks/workspace/editor-view.ts +61 -0
- package/src/client/hooks/workspace/file-listing.ts +36 -24
- package/src/client/hooks/workspace/file-tabs.test.ts +152 -5
- package/src/client/hooks/workspace/file-tabs.ts +70 -11
- package/src/client/hooks/workspace/file-tree-edits.ts +103 -0
- package/src/client/hooks/workspace/navbar-session-actions.ts +72 -0
- package/src/client/hooks/workspace/worktree/index.ts +20 -5
- package/src/client/lib/desktop/bridge.ts +45 -0
- package/src/client/lib/desktop/dropped-paths.ts +83 -0
- package/src/client/lib/editor/tab-menu.test.ts +127 -0
- package/src/client/lib/editor/tab-menu.ts +127 -0
- package/src/client/lib/editor-dirty-tabs.test.ts +102 -0
- package/src/client/lib/editor-dirty-tabs.ts +103 -0
- package/src/client/lib/native/resume.test.ts +66 -0
- package/src/client/lib/native/resume.ts +42 -0
- package/src/client/lib/search-reveal.ts +1 -1
- package/src/client/main.tsx +13 -1
- package/src/client/tailwind.css +75 -8
- package/src/server/lib/auth/guard.test.ts +28 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/bundler/css.test.ts +31 -0
- package/src/server/lib/fs/listing.test.ts +81 -16
- package/src/server/lib/fs/listing.ts +72 -5
- package/src/server/lib/fs/worktree/create.ts +2 -3
- package/src/server/lib/fs/worktree/list.ts +13 -0
- package/src/server/lib/fs/worktree/remove.ts +3 -3
- package/src/server/lib/fs/write-conflict.test.ts +68 -0
- package/src/server/lib/fs/write-conflict.ts +84 -0
- package/src/server/lib/lifecycle/claim-port.test.ts +156 -0
- package/src/server/lib/lifecycle/port-guard.test.ts +20 -164
- package/src/server/lib/lifecycle/port-guard.ts +39 -7
- package/src/server/lib/lifecycle/probe-health.test.ts +166 -0
- package/src/server/lib/lifecycle/probe.test.ts +77 -164
- package/src/server/lib/lifecycle/probe.ts +121 -13
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +112 -0
- package/src/server/lib/omp/rpc/frame-fold.ts +10 -5
- package/src/server/lib/omp/session/sidebar-activity.server.test.ts +162 -0
- package/src/server/lib/omp/session/sidebar-activity.server.ts +70 -0
- package/src/server/lib/omp/session/telemetry/compute.ts +13 -1
- package/src/server/lib/omp/session/telemetry.test.ts +33 -0
- package/src/server/lib/realtime/signals.server.ts +10 -0
- package/src/server/lib/realtime/topics/catalog.server.ts +4 -1
- package/src/server/lib/realtime/topics.server.ts +16 -0
- package/src/server/lib/updates/shell-assets.ts +94 -3
- package/src/server/lib/updates/shell-cache.ts +105 -0
- package/src/server/lib/updates/shell-pages.test.ts +33 -2
- package/src/server/lib/updates/shell-pages.ts +17 -5
- package/src/server/lib/updates/shell-release-desktop.test.ts +166 -0
- package/src/server/lib/updates/shell-release.test.ts +10 -27
- package/src/server/lib/updates/shell-release.ts +107 -111
- package/src/server/routes/fs/action-save-as.test.ts +82 -0
- package/src/server/routes/fs/action.test.ts +82 -0
- package/src/server/routes/fs/action.ts +54 -1
- package/src/server/routes/fs/exists.ts +11 -1
- package/src/server/routes/fs/git-merge.test.ts +11 -1
- package/src/server/routes/fs/read.test.ts +24 -7
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/fs/scope.test.ts +15 -10
- package/src/server/routes/fs/scope.ts +3 -14
- package/src/server/routes/updates/android.ts +6 -1
- package/src/server/routes/updates/desktop.ts +29 -7
- package/src/server/routes/updates/ios.ts +5 -1
- package/src/server/routes/worktrees/list.ts +11 -1
- package/src/server/routes/worktrees/routes.test.ts +17 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.test.ts +36 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +18 -0
- package/src/shared/lib/chat/timeline/run-signals.test.ts +2 -0
- package/src/shared/lib/code/editor/comment-syntax.test.ts +37 -0
- package/src/shared/lib/code/editor/comment-syntax.ts +55 -0
- package/src/shared/lib/code/editor/find-replace.test.ts +134 -0
- package/src/shared/lib/code/editor/{find.ts → find-replace.ts} +23 -107
- package/src/shared/lib/code/editor/{find.test.ts → find-scan.test.ts} +20 -74
- package/src/shared/lib/code/editor/find-scan.ts +198 -0
- package/src/shared/lib/code/editor/find-selection.test.ts +56 -0
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +65 -0
- package/src/shared/lib/code/editor/indent-guide-rule.ts +47 -0
- package/src/shared/lib/code/editor/indent-rules.test.ts +219 -0
- package/src/shared/lib/code/editor/indent-rules.ts +198 -0
- package/src/shared/lib/code/editor/keymap.test.ts +23 -0
- package/src/shared/lib/code/editor/keymap.ts +43 -6
- package/src/shared/lib/code/editor/lines.test.ts +7 -55
- package/src/shared/lib/code/editor/lines.ts +8 -48
- package/src/shared/lib/code/editor/marks.test.ts +4 -5
- package/src/shared/lib/code/editor/marks.ts +13 -25
- package/src/shared/lib/code/editor/palette.test.ts +25 -2
- package/src/shared/lib/code/editor/palette.ts +10 -0
- package/src/shared/lib/code/editor/stream-modes.ts +225 -0
- package/src/shared/lib/code/editor/theme-loader.ts +97 -0
- package/src/shared/lib/code/editor/themes.generated.ts +156 -0
- package/src/shared/lib/code/editor/themes.test.ts +165 -0
- package/src/shared/lib/code/editor/themes.ts +165 -0
- package/src/shared/lib/code/highlight-memo.test.ts +103 -0
- package/src/shared/lib/code/highlight-memo.ts +149 -0
- package/src/shared/lib/code/highlighter-warmup.ts +112 -0
- package/src/shared/lib/code/highlighter.ts +3 -1
- package/src/shared/lib/code/idle.ts +37 -0
- package/src/shared/lib/code/outline/rows.test.ts +96 -0
- package/src/shared/lib/code/outline/rows.ts +94 -0
- package/src/shared/lib/code/syntax-highlight.test.ts +2 -80
- package/src/shared/lib/code/syntax-highlight.ts +2 -3
- package/src/shared/lib/fs/file-kind-classify.test.ts +25 -11
- package/src/shared/lib/fs/file-kind.ts +47 -13
- package/src/shared/lib/fs/file-tree.test.ts +41 -0
- package/src/shared/lib/fs/file-tree.ts +126 -34
- package/src/shared/lib/fs/file-url.test.ts +52 -0
- package/src/shared/lib/fs/file-url.ts +37 -0
- package/src/shared/lib/fs/folder-chain.test.ts +87 -0
- package/src/shared/lib/fs/folder-chain.ts +91 -0
- package/src/shared/lib/fs/fs-helpers.test.ts +4 -50
- package/src/shared/lib/fs/patch-sides.test.ts +114 -0
- package/src/shared/lib/fs/patch-sides.ts +139 -0
- package/src/shared/lib/realtime/connection.test.ts +5 -1
- package/src/shared/lib/realtime/connection.ts +25 -119
- package/src/shared/lib/realtime/frozen-recovery.test.ts +93 -0
- package/src/shared/lib/realtime/protocol.ts +16 -0
- package/src/shared/lib/realtime/resume.ts +223 -0
- package/src/shared/lib/realtime/state.ts +22 -0
- package/src/shared/lib/realtime/watchdog-wiring.test.ts +224 -0
- package/src/shared/lib/realtime/watchdog.test.ts +99 -0
- package/src/shared/lib/realtime/watchdog.ts +72 -0
- package/src/shared/lib/ui/toolbar-overflow.test.ts +83 -0
- package/src/shared/lib/ui/toolbar-overflow.ts +86 -0
- package/src/shared/lib/updates/shell-arch.ts +54 -0
- package/src/shared/lib/updates/shell-ua.ts +4 -4
- package/src/shared/lib/workspace/editor-view-mode.test.ts +70 -0
- package/src/shared/lib/workspace/editor-view-mode.ts +48 -0
- package/src/shared/lib/workspace/panel-widths.test.ts +30 -0
- package/src/shared/lib/workspace/panel-widths.ts +25 -5
- package/src/shared/lib/workspace/session-state/cache.ts +159 -0
- package/src/shared/lib/workspace/session-state/harness.test-util.ts +55 -0
- package/src/shared/lib/workspace/session-state/merge.ts +100 -0
- package/src/shared/lib/workspace/session-state/store-load.test.ts +206 -0
- package/src/shared/lib/workspace/session-state/store.test.ts +17 -139
- package/src/shared/lib/workspace/session-state/store.ts +92 -130
- package/src/shared/lib/workspace/split-editor.test.ts +104 -0
- package/src/shared/lib/workspace/split-editor.ts +129 -0
- package/src/shared/lib/workspace/workspace-panel-widths.ts +124 -0
- package/src/shared/types/realtime.ts +29 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/test-support/file-explorer-disk.test-util.ts +30 -3
- package/src/test-support/loopback.ts +183 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-gtbpewr7.css +0 -1
- package/src/client/components/common/code-editor/handler.test.ts +0 -274
- package/src/client/components/common/code-editor/handler.ts +0 -175
- package/src/client/components/common/code-editor/index.tsx +0 -314
- package/src/client/components/common/code-surface/measure.ts +0 -148
- package/src/client/components/workspace/chat-timeline/target-picker/index.test.tsx +0 -227
- package/src/client/components/workspace/chat-timeline/target-picker/index.tsx +0 -260
- package/src/client/components/workspace/diff-panel/SplitView.tsx +0 -209
- package/src/client/components/workspace/diff-panel/UnifiedView.tsx +0 -150
- package/src/client/hooks/editor/scroll-container.test.ts +0 -102
- package/src/client/hooks/editor/scroll-container.ts +0 -26
- package/src/client/hooks/editor/use-code-window.ts +0 -100
- package/src/client/hooks/editor/use-editor-history.test.ts +0 -216
- package/src/client/hooks/editor/use-editor-history.ts +0 -134
- package/src/client/hooks/editor/use-occurrences.test.ts +0 -236
- package/src/client/hooks/editor/use-occurrences.ts +0 -98
- package/src/shared/lib/code/editor/commands.test.ts +0 -155
- package/src/shared/lib/code/editor/commands.ts +0 -260
- package/src/shared/lib/code/editor/edits.test.ts +0 -100
- package/src/shared/lib/code/editor/edits.ts +0 -122
- package/src/shared/lib/code/editor/history.test.ts +0 -118
- package/src/shared/lib/code/editor/history.ts +0 -101
- package/src/shared/lib/code/editor/layers.test.ts +0 -77
- package/src/shared/lib/code/editor/layers.ts +0 -67
- package/src/shared/lib/code/editor/line-edits.test.ts +0 -131
- package/src/shared/lib/code/editor/line-edits.ts +0 -159
- package/src/shared/lib/code/editor/occurrences.test.ts +0 -117
- package/src/shared/lib/code/editor/occurrences.ts +0 -111
- package/src/shared/lib/code/editor/reset-css.test.ts +0 -35
- package/src/shared/lib/code/editor/reset-css.ts +0 -32
- package/src/shared/lib/code/editor/text-commands.test.ts +0 -178
- package/src/shared/lib/code/editor/text-commands.ts +0 -154
- package/src/shared/lib/code/lazy-window.test.ts +0 -161
- package/src/shared/lib/code/lazy-window.ts +0 -156
- package/src/shared/lib/code/windowed-highlight.ts +0 -114
- package/src/shared/lib/fs/diff-parser.test.ts +0 -116
- package/src/shared/lib/fs/diff-parser.ts +0 -213
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The indent table, and the GATE that keeps it honest.
|
|
8
|
+
*
|
|
9
|
+
* The gate is the load-bearing half. Measured: an `indentService` that returns a
|
|
10
|
+
* NUMBER overrides a stream mode's own answer (JavaScript's 11 became 0), while
|
|
11
|
+
* returning `undefined` falls through. So every language whose installed mode
|
|
12
|
+
* answers must be ABSENT from `INDENT_RULES`, and the first test below
|
|
13
|
+
* re-derives that set from the installed `@codemirror/legacy-modes` — a mode that
|
|
14
|
+
* later grows an `indent()` fails here instead of silently degrading 34 working
|
|
15
|
+
* languages.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, expect, test } from 'bun:test';
|
|
19
|
+
|
|
20
|
+
import { StreamLanguage, indentUnit, getIndentation } from '@codemirror/language';
|
|
21
|
+
import { EditorState } from '@codemirror/state';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
INDENT_RULES,
|
|
25
|
+
indentAfter,
|
|
26
|
+
indentForCloser,
|
|
27
|
+
indentOnInputPattern,
|
|
28
|
+
leadingWidth,
|
|
29
|
+
} from '@/shared/lib/code/editor/indent-rules';
|
|
30
|
+
import { STREAM_MODE_LOADERS, STREAM_MODE_EXPORTS, TEXTUAL_ONLY_LANGS } from '@/shared/lib/code/editor/stream-modes';
|
|
31
|
+
|
|
32
|
+
/** One "a block just opened" snippet per language, as the survey used. */
|
|
33
|
+
const OPENER: Record<string, string> = {
|
|
34
|
+
typescript: 'if (x) {', javascript: 'if (x) {', tsx: 'const a = (', jsx: 'const a = (',
|
|
35
|
+
c: 'void f() {', cpp: 'void f() {', csharp: 'void F() {', java: 'void f() {',
|
|
36
|
+
go: 'func f() {', rust: 'fn f() {', kotlin: 'fun f() {', swift: 'func f() {',
|
|
37
|
+
dart: 'void f() {', scala: 'def f = {', groovy: 'def f() {', 'objective-c': 'void f() {',
|
|
38
|
+
css: 'a {', scss: 'a {', less: 'a {', stylus: 'a', sass: 'a', json: '{', json5: '{',
|
|
39
|
+
xml: '<a>', julia: 'function f()', lua: 'if x then', r: 'if (TRUE) {',
|
|
40
|
+
clojure: '(defn f [x]', racket: '(define (f x)', scheme: '(define (f x)',
|
|
41
|
+
elixir: 'defmodule M do', erlang: 'f() ->', python: 'def f():', ruby: 'def f',
|
|
42
|
+
perl: 'if ($x) {', powershell: 'if ($x) {', yaml: 'a:', toml: 'a = {', hcl: 'a {',
|
|
43
|
+
ini: '[a', protobuf: 'message M {', dockerfile: 'RUN a \\', bash: 'if true; then',
|
|
44
|
+
haskell: 'f x =', ocaml: 'let f x =', makefile: 'all:', properties: 'a=1', sql: 'SELECT',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Languages whose installed mode answers `getIndentation` for its opener. */
|
|
48
|
+
async function languagesTheModeAnswers(): Promise<Set<string>> {
|
|
49
|
+
const answering = new Set<string>();
|
|
50
|
+
for (const [language, opener] of Object.entries(OPENER)) {
|
|
51
|
+
const loader = STREAM_MODE_LOADERS[language];
|
|
52
|
+
if (!loader) continue;
|
|
53
|
+
const module = (await loader()) as Record<string, unknown>;
|
|
54
|
+
const mode = module[STREAM_MODE_EXPORTS[language]];
|
|
55
|
+
const state = EditorState.create({
|
|
56
|
+
doc: opener,
|
|
57
|
+
extensions: [indentUnit.of(' '), StreamLanguage.define(mode as never)],
|
|
58
|
+
});
|
|
59
|
+
if (getIndentation(state, opener.length) !== null) answering.add(language);
|
|
60
|
+
}
|
|
61
|
+
return answering;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('INDENT_RULES is exactly the set of languages whose parser cannot answer', () => {
|
|
65
|
+
test('a language whose mode answers must NOT have an `opens` rule, or it overrides the mode', async () => {
|
|
66
|
+
const answering = await languagesTheModeAnswers();
|
|
67
|
+
// Measured on 6.5.5: 34 ids answer. Asserting the count is what makes an
|
|
68
|
+
// upstream change to one mode show up as a failure rather than a silent
|
|
69
|
+
// regression in a language nobody re-checked.
|
|
70
|
+
expect(answering.size).toBe(34);
|
|
71
|
+
|
|
72
|
+
const overridden = Object.keys(INDENT_RULES).filter(
|
|
73
|
+
(language) => answering.has(language) && INDENT_RULES[language]?.opens !== undefined,
|
|
74
|
+
);
|
|
75
|
+
expect(overridden).toEqual([]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('every mode-less language has an `opens` rule, so Enter is answered', async () => {
|
|
79
|
+
const answering = await languagesTheModeAnswers();
|
|
80
|
+
const needsOpens = [
|
|
81
|
+
...Object.keys(STREAM_MODE_LOADERS).filter((language) => !answering.has(language)),
|
|
82
|
+
...TEXTUAL_ONLY_LANGS,
|
|
83
|
+
];
|
|
84
|
+
const missing = needsOpens.filter((language) => INDENT_RULES[language]?.opens === undefined);
|
|
85
|
+
expect(missing).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a closer rule may be added to a language whose mode answers Enter', () => {
|
|
89
|
+
// `go`'s own regexp demands exactly one space, so ` }` never dedents there.
|
|
90
|
+
// These entries add the closer half ONLY — an `opens` would shadow the mode.
|
|
91
|
+
const answeringWithCloser = ['go', 'tsx', 'jsx'];
|
|
92
|
+
for (const language of answeringWithCloser) {
|
|
93
|
+
expect(INDENT_RULES[language]?.closes).toBeDefined();
|
|
94
|
+
expect(INDENT_RULES[language]?.opens).toBeUndefined();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('indentAfter — what Enter asks of the line above', () => {
|
|
100
|
+
test('a YAML key opens a block', () => {
|
|
101
|
+
expect(indentAfter('yaml', 'a:')).toBe(2);
|
|
102
|
+
expect(indentAfter('yaml', 'a:\n b: 1'.split('\n')[1])).toBe(2);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('a YAML list item does NOT open one — its continuation is at its own column', () => {
|
|
106
|
+
expect(indentAfter('yaml', '- item')).toBe(0);
|
|
107
|
+
expect(indentAfter('yaml', ' - item')).toBe(2);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('a brace opens a block in the brace families', () => {
|
|
111
|
+
expect(indentAfter('toml', 'a = {')).toBe(2);
|
|
112
|
+
expect(indentAfter('hcl', 'resource "a" "b" {')).toBe(2);
|
|
113
|
+
expect(indentAfter('graphql', 'query Q {')).toBe(2);
|
|
114
|
+
expect(indentAfter('php', 'function f() {')).toBe(2);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('a keyword opens a block in bash, and a trailing backslash continues in Dockerfile', () => {
|
|
118
|
+
expect(indentAfter('bash', 'if true; then')).toBe(2);
|
|
119
|
+
expect(indentAfter('bash', 'for x in a; do')).toBe(2);
|
|
120
|
+
expect(indentAfter('bash', 'echo hi')).toBe(0);
|
|
121
|
+
expect(indentAfter('dockerfile', 'RUN apt-get install \\')).toBe(2);
|
|
122
|
+
expect(indentAfter('dockerfile', 'FROM node')).toBe(0);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('an expression body opens in the layout languages', () => {
|
|
126
|
+
expect(indentAfter('haskell', 'f x =')).toBe(2);
|
|
127
|
+
expect(indentAfter('ocaml', 'let f x =')).toBe(2);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('an unclosed HTML tag opens, a closing tag does not', () => {
|
|
131
|
+
expect(indentAfter('html', '<div>')).toBe(2);
|
|
132
|
+
expect(indentAfter('html', '</div>')).toBe(0);
|
|
133
|
+
expect(indentAfter('html', '<br/>')).toBe(0);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('the flat languages never move the indent', () => {
|
|
137
|
+
for (const language of ['sql', 'makefile', 'properties', 'markdown', 'diff', 'text']) {
|
|
138
|
+
expect(indentAfter(language, 'anything {')).toBe(0);
|
|
139
|
+
expect(indentAfter(language, ' already indented')).toBe(2);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('a language with no rule answers null, so the parser keeps its own answer', () => {
|
|
144
|
+
expect(indentAfter('typescript', 'if (x) {')).toBeNull();
|
|
145
|
+
expect(indentAfter('python', 'def f():')).toBeNull();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('the unit is the caller’s, so a tab-size setting propagates', () => {
|
|
149
|
+
expect(indentAfter('yaml', 'a:', 4)).toBe(4);
|
|
150
|
+
expect(indentAfter('yaml', ' a:', 4)).toBe(8);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('indentForCloser — what indentOnInput asks of the line that now starts with one', () => {
|
|
155
|
+
test('a closer dedents one level in the bracket families', () => {
|
|
156
|
+
expect(indentForCloser('toml', ' }')).toBe(0);
|
|
157
|
+
expect(indentForCloser('hcl', ' }')).toBe(2);
|
|
158
|
+
expect(indentForCloser('graphql', ' ]')).toBe(0);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('a closer in a flat language is content and is left alone', () => {
|
|
162
|
+
expect(indentForCloser('markdown', ' ]')).toBeNull();
|
|
163
|
+
expect(indentForCloser('yaml', ' }')).toBeNull();
|
|
164
|
+
expect(indentForCloser('sql', ' )')).toBeNull();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('a line that is not a closer is not touched', () => {
|
|
168
|
+
expect(indentForCloser('toml', ' a = 1')).toBeNull();
|
|
169
|
+
// Anchored at both ends: `}x` is content, not a dedent.
|
|
170
|
+
expect(indentForCloser('toml', ' }x')).toBeNull();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('never goes below column zero', () => {
|
|
174
|
+
expect(indentForCloser('toml', '}')).toBe(0);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('indentOnInputPattern', () => {
|
|
179
|
+
test('a bracket family gets its own closer pattern', () => {
|
|
180
|
+
const pattern = indentOnInputPattern('toml');
|
|
181
|
+
expect(pattern).not.toBeNull();
|
|
182
|
+
expect(pattern!.test('}')).toBe(true);
|
|
183
|
+
expect(pattern!.test(' }')).toBe(true);
|
|
184
|
+
expect(pattern!.test('\t}')).toBe(true);
|
|
185
|
+
expect(pattern!.test(' ]')).toBe(true);
|
|
186
|
+
expect(pattern!.test('}x')).toBe(false);
|
|
187
|
+
expect(pattern!.test('a')).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('bash accepts its own keywords as closers', () => {
|
|
191
|
+
const pattern = indentOnInputPattern('bash');
|
|
192
|
+
expect(pattern!.test('fi')).toBe(true);
|
|
193
|
+
expect(pattern!.test('done')).toBe(true);
|
|
194
|
+
expect(pattern!.test('esac')).toBe(true);
|
|
195
|
+
expect(pattern!.test('echo')).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('a language with no closers gets NO pattern — the generic bracket rule is wrong there', () => {
|
|
199
|
+
// Measured before this gate existed: the generic pattern turned `a:\n }`
|
|
200
|
+
// into `a:\n}`, moving YAML content the user did not ask to move.
|
|
201
|
+
for (const language of ['yaml', 'markdown', 'sql', 'makefile', 'properties', 'diff', 'text', 'haskell', 'ocaml', 'dockerfile']) {
|
|
202
|
+
expect(indentOnInputPattern(language)).toBeNull();
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test('a language with no rule at all gets no pattern', () => {
|
|
207
|
+
expect(indentOnInputPattern('typescript')).toBeNull();
|
|
208
|
+
expect(indentOnInputPattern('python')).toBeNull();
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('leadingWidth', () => {
|
|
213
|
+
test('counts the leading whitespace only', () => {
|
|
214
|
+
expect(leadingWidth('abc')).toBe(0);
|
|
215
|
+
expect(leadingWidth(' abc')).toBe(2);
|
|
216
|
+
expect(leadingWidth('\tabc')).toBe(1);
|
|
217
|
+
expect(leadingWidth(' ')).toBe(3);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How each language indents a new line, for the questions its parser cannot
|
|
8
|
+
* answer.
|
|
9
|
+
*
|
|
10
|
+
* The code surface parses with a `StreamLanguage` (`stream-modes.ts`), and a
|
|
11
|
+
* legacy stream mode may ship its own `indent()`. Measured against
|
|
12
|
+
* `@codemirror/legacy-modes` 6.5.5: **34 of the 48 mode-backed ids answer
|
|
13
|
+
* `getIndentation`** for a "block just opened" snippet, 14 answer nothing, and 12
|
|
14
|
+
* ids have no mode at all.
|
|
15
|
+
*
|
|
16
|
+
* ## Two independent halves, because the two failures are independent
|
|
17
|
+
*
|
|
18
|
+
* `opens` answers "what indent should the NEXT line have" (Enter). `closes`
|
|
19
|
+
* answers "this line IS a closer, dedent it" (`indentOnInput`). They are separate
|
|
20
|
+
* fields because a mode can do one and not the other — measured on `go`, whose
|
|
21
|
+
* own regexp is `/^\s([{}]|case |default\s*:)$/`: it indents correctly, and it
|
|
22
|
+
* refuses to dedent ` }` because the pattern demands EXACTLY one space. A single
|
|
23
|
+
* combined entry would have had to override the working half to fix the broken
|
|
24
|
+
* one.
|
|
25
|
+
*
|
|
26
|
+
* ## The gate: an `opens` must never shadow a mode that answers
|
|
27
|
+
*
|
|
28
|
+
* Measured: an `indentService` returning a NUMBER overrides a mode's own answer
|
|
29
|
+
* (JavaScript's 11 became 0); returning `undefined` falls through. So a language
|
|
30
|
+
* whose mode answers has NO `opens`, and `indent-rules.test.ts` re-derives that
|
|
31
|
+
* set from the installed modes — a mode that later grows an `indent()` fails
|
|
32
|
+
* there instead of silently degrading 34 working languages. `closes` carries no
|
|
33
|
+
* such constraint: it only adds the cases a mode declines.
|
|
34
|
+
*
|
|
35
|
+
* ## The rule is a TABLE, not a bracket counter
|
|
36
|
+
*
|
|
37
|
+
* A single "depth of `{[(` on the line" rule was measured and rejected: it gives
|
|
38
|
+
* `yaml a:` and `markdown - item` nothing (no bracket), and over-indents
|
|
39
|
+
* `const s = "{"` (a brace inside a string). Each family states its own opener in
|
|
40
|
+
* one line a reader can check, and a language with no reliable textual rule
|
|
41
|
+
* (`sql`, `makefile`, `properties`, `markdown`) states nothing — absence is what
|
|
42
|
+
* makes `indentAfter` return `null` and leave the language alone.
|
|
43
|
+
*
|
|
44
|
+
* ## What this gets wrong, stated rather than hidden
|
|
45
|
+
*
|
|
46
|
+
* No grammar, so the rules are textual: `yaml` cannot tell a `:` inside a quoted
|
|
47
|
+
* scalar from a key, `bash` cannot tell `then` inside a comment from a keyword,
|
|
48
|
+
* and a `{` inside a string still opens a level. Each costs one wrong INITIAL
|
|
49
|
+
* indent the user fixes with one keystroke, against no indent at all.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/** Column width assumed when the caller has no `indentUnit` (the surface's default). */
|
|
53
|
+
export const DEFAULT_INDENT_WIDTH = 2;
|
|
54
|
+
|
|
55
|
+
/** One language's textual indent rules. Both halves are optional and independent. */
|
|
56
|
+
export interface IndentRule {
|
|
57
|
+
/**
|
|
58
|
+
* Whether this line opens a level for the lines that follow it.
|
|
59
|
+
*
|
|
60
|
+
* ABSENT for a language whose parser answers — presence would override it.
|
|
61
|
+
*/
|
|
62
|
+
opens?: (text: string) => boolean;
|
|
63
|
+
/**
|
|
64
|
+
* A line that IS a closer — anchored at both ends, so `}x` is content rather
|
|
65
|
+
* than a dedent.
|
|
66
|
+
*
|
|
67
|
+
* One pattern serves both `indentForCloser` and the `indentOnInput` language
|
|
68
|
+
* data, which is what stops the two from disagreeing about which lines move. A
|
|
69
|
+
* keyword closer (`fi`, `done`) cannot be expressed as a character set, which
|
|
70
|
+
* is why this is a pattern and not a string of characters.
|
|
71
|
+
*/
|
|
72
|
+
closes?: RegExp;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The line's leading whitespace, in columns (a tab counts as one). */
|
|
76
|
+
export function leadingWidth(text: string): number {
|
|
77
|
+
return /^[ \t]*/.exec(text)?.[0].length ?? 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Ends with a bracket — the C-family shape. */
|
|
81
|
+
const endsWithBracket = (text: string): boolean => /[{[(\[]$/.test(text.trimEnd());
|
|
82
|
+
|
|
83
|
+
/** A single `}`, `]` or `)` on its own line. */
|
|
84
|
+
const BRACKET_CLOSER = /^[ \t]*[}\])]$/;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The rules, keyed by Shiki id — the key `getLanguageFromPath` answers and the
|
|
88
|
+
* surface holds.
|
|
89
|
+
*/
|
|
90
|
+
export const INDENT_RULES: Record<string, IndentRule> = {
|
|
91
|
+
// ── Indentation-significant: a `key:` opens a block ──────────────────────
|
|
92
|
+
// A `- item` deliberately does NOT open one: a list item's continuation sits
|
|
93
|
+
// at the item's own column, not deeper. A comment opens nothing either.
|
|
94
|
+
yaml: {
|
|
95
|
+
opens: (text) => /:\s*$/.test(text.trimEnd()) && !/^[ \t]*#/.test(text),
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
// ── Brace families whose mode answers nothing ────────────────────────────
|
|
99
|
+
toml: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
100
|
+
ini: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
101
|
+
hcl: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
102
|
+
protobuf: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
103
|
+
graphql: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
104
|
+
nix: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
105
|
+
svelte: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
106
|
+
astro: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
107
|
+
vue: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
108
|
+
zig: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
109
|
+
solidity: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
110
|
+
php: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
111
|
+
powershell: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
112
|
+
perl: { opens: endsWithBracket, closes: BRACKET_CLOSER },
|
|
113
|
+
|
|
114
|
+
// ── Keyword-delimited shell ──────────────────────────────────────────────
|
|
115
|
+
bash: {
|
|
116
|
+
opens: (text) => /\b(then|do|else)\s*$/.test(text.trimEnd()),
|
|
117
|
+
closes: /^[ \t]*(fi|done|esac|\})$/,
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
// ── Expression languages whose blocks are layout, not brackets ────────────
|
|
121
|
+
haskell: { opens: (text) => /(=|\bwhere|\bdo|\bof|\bthen|\belse)\s*$/.test(text.trimEnd()) },
|
|
122
|
+
ocaml: { opens: (text) => /(=|\bdo|\bthen|\belse|\bin|\bwith)\s*$/.test(text.trimEnd()) },
|
|
123
|
+
|
|
124
|
+
// ── Continuation by trailing backslash ───────────────────────────────────
|
|
125
|
+
dockerfile: { opens: (text) => /\\$/.test(text.trimEnd()) },
|
|
126
|
+
|
|
127
|
+
// ── Markup: an unclosed, non-self-closing tag opens a level ───────────────
|
|
128
|
+
html: {
|
|
129
|
+
opens: (text) => {
|
|
130
|
+
const line = text.trimEnd();
|
|
131
|
+
return /<[a-zA-Z][^<>]*>$/.test(line) && !/\/>$/.test(line);
|
|
132
|
+
},
|
|
133
|
+
closes: /^[ \t]*<\//,
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// ── Deliberately flat ────────────────────────────────────────────────────
|
|
137
|
+
// `sql` (clauses are keywords with no terminator), `makefile` (a recipe is a
|
|
138
|
+
// TAB, not a level), `properties` (flat), `markdown` (a continuation sits at
|
|
139
|
+
// the item's column), `diff` (hunk bodies are flat), `text` (nothing).
|
|
140
|
+
sql: { opens: () => false },
|
|
141
|
+
makefile: { opens: () => false },
|
|
142
|
+
properties: { opens: () => false },
|
|
143
|
+
markdown: { opens: () => false },
|
|
144
|
+
diff: { opens: () => false },
|
|
145
|
+
text: { opens: () => false },
|
|
146
|
+
|
|
147
|
+
// ── Mode answers Enter, but its own closer pattern is too strict ──────────
|
|
148
|
+
// `go`'s mode regexp is `/^\s([{}]|case |default\s*:)$/` — it demands EXACTLY
|
|
149
|
+
// one space of indentation, so ` }` never matches and never dedents. These
|
|
150
|
+
// entries add the CLOSER half only; their `opens` stays absent on purpose.
|
|
151
|
+
go: { closes: BRACKET_CLOSER },
|
|
152
|
+
tsx: { closes: BRACKET_CLOSER },
|
|
153
|
+
jsx: { closes: BRACKET_CLOSER },
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Whether this language has any rule at all. */
|
|
157
|
+
export function hasIndentRule(language: string): boolean {
|
|
158
|
+
const rule = INDENT_RULES[language];
|
|
159
|
+
return rule !== undefined && (rule.opens !== undefined || rule.closes !== undefined);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The indent for the line AFTER `previousText` — what Enter asks.
|
|
164
|
+
*
|
|
165
|
+
* `null` when the language has no `opens` rule, so the caller can fall through to
|
|
166
|
+
* the parser (or to no indent at all).
|
|
167
|
+
*/
|
|
168
|
+
export function indentAfter(language: string, previousText: string, unit = DEFAULT_INDENT_WIDTH): number | null {
|
|
169
|
+
const opens = INDENT_RULES[language]?.opens;
|
|
170
|
+
if (!opens) return null;
|
|
171
|
+
const own = leadingWidth(previousText);
|
|
172
|
+
return opens(previousText) ? own + unit : own;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The indent a line that IS a closer should have — what `indentOnInput` asks.
|
|
177
|
+
*
|
|
178
|
+
* `null` when the language has no closer rule, or when this line is not one: a
|
|
179
|
+
* `}` at the start of a YAML line is text, and moving it would edit the user's
|
|
180
|
+
* content.
|
|
181
|
+
*/
|
|
182
|
+
export function indentForCloser(language: string, lineText: string, unit = DEFAULT_INDENT_WIDTH): number | null {
|
|
183
|
+
const closes = INDENT_RULES[language]?.closes;
|
|
184
|
+
if (!closes?.test(lineText)) return null;
|
|
185
|
+
return Math.max(0, leadingWidth(lineText) - unit);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The `indentOnInput` pattern for a language, or `null`.
|
|
190
|
+
*
|
|
191
|
+
* It is the rule's OWN `closes`, not a derived character class: measured, a
|
|
192
|
+
* generic bracket pattern turned `a:\n }` into `a:\n}` in YAML, moving content
|
|
193
|
+
* the user never asked to move. And a keyword closer cannot be a character set at
|
|
194
|
+
* all, so the two halves share one pattern instead of approximating it.
|
|
195
|
+
*/
|
|
196
|
+
export function indentOnInputPattern(language: string): RegExp | null {
|
|
197
|
+
return INDENT_RULES[language]?.closes ?? null;
|
|
198
|
+
}
|
|
@@ -86,6 +86,29 @@ describe('editor keymap', () => {
|
|
|
86
86
|
expect(isFindBarCommand('toggleComment')).toBe(false);
|
|
87
87
|
expect(isFindBarCommand('selectNextOccurrence')).toBe(false);
|
|
88
88
|
});
|
|
89
|
+
|
|
90
|
+
test('folding is bound on both platforms, on chords the app already owns', () => {
|
|
91
|
+
// These are CM6's own `foldKeymap` chords. The reason this test exists is
|
|
92
|
+
// that the palette and the tooltips read the SAME table: a fold command
|
|
93
|
+
// listed with a chord nothing binds is the bug the table prevents.
|
|
94
|
+
expect(commandFor(key('BracketLeft', '[', { ctrlKey: true, shiftKey: true }), false)).toBe('fold');
|
|
95
|
+
expect(commandFor(key('BracketRight', ']', { ctrlKey: true, shiftKey: true }), false)).toBe('unfold');
|
|
96
|
+
expect(commandFor(key('BracketLeft', '[', { metaKey: true, altKey: true }), true)).toBe('fold');
|
|
97
|
+
expect(commandFor(key('BracketRight', ']', { metaKey: true, altKey: true }), true)).toBe('unfold');
|
|
98
|
+
// Ctrl-Alt on both: CM6 binds it without a platform override, and it is the
|
|
99
|
+
// one fold chord that cannot collide with macOS's ⌥⌘ pair.
|
|
100
|
+
expect(commandFor(key('BracketLeft', '[', { ctrlKey: true, altKey: true }), false)).toBe('foldAll');
|
|
101
|
+
expect(commandFor(key('BracketRight', ']', { ctrlKey: true, altKey: true }), false)).toBe('unfoldAll');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('the fold chords do not collide with indent or outdent', () => {
|
|
105
|
+
// `⌘]` indents and `⌘⌥]` unfolds: one modifier apart, which is exactly the
|
|
106
|
+
// pair a hand-written table gets wrong.
|
|
107
|
+
expect(editorStrokeFor('indent', true, false)).toEqual({ code: 'BracketRight', meta: true });
|
|
108
|
+
expect(editorStrokeFor('unfold', true, false)).toEqual({ code: 'BracketRight', meta: true, alt: true });
|
|
109
|
+
expect(editorStrokeFor('indent', false, false)).toEqual({ code: 'BracketRight', ctrl: true });
|
|
110
|
+
expect(editorStrokeFor('unfold', false, false)).toEqual({ code: 'BracketRight', ctrl: true, shift: true });
|
|
111
|
+
});
|
|
89
112
|
});
|
|
90
113
|
|
|
91
114
|
describe('binding labels', () => {
|
|
@@ -8,13 +8,16 @@
|
|
|
8
8
|
*
|
|
9
9
|
* One table is the whole truth about an editor shortcut: what it does, which
|
|
10
10
|
* chords reach it on each platform, and what the palette calls it. The
|
|
11
|
-
*
|
|
12
|
-
* palette all read this table, so a shortcut cannot be listed in the
|
|
13
|
-
* and unbound in the editor.
|
|
11
|
+
* generated CodeMirror keymap, the find bar's buttons, the tooltips and the
|
|
12
|
+
* command palette all read this table, so a shortcut cannot be listed in the
|
|
13
|
+
* palette and unbound in the editor.
|
|
14
14
|
*
|
|
15
15
|
* VS Code's defaults are followed wherever this editor has an equivalent. Where
|
|
16
|
-
* it has none —
|
|
17
|
-
*
|
|
16
|
+
* it has none — go-to-definition, the `⌘K` prefix chords — the command is absent
|
|
17
|
+
* rather than bound to something that would surprise. Folding used to be in that
|
|
18
|
+
* list; it is here now because the surface folds by INDENTATION (`fold.ts`), so
|
|
19
|
+
* the commands do something in every language rather than only in the 19 that
|
|
20
|
+
* have a grammar.
|
|
18
21
|
*/
|
|
19
22
|
|
|
20
23
|
import type { KeyBinding, KeyStroke } from '@/shared/lib/ui/key-binding';
|
|
@@ -33,16 +36,24 @@ export type EditorCommand =
|
|
|
33
36
|
| 'selectNextOccurrence'
|
|
34
37
|
| 'selectAllOccurrences'
|
|
35
38
|
| 'insertCursorBelow'
|
|
39
|
+
| 'insertCursorAbove'
|
|
36
40
|
| 'moveLineUp'
|
|
37
41
|
| 'moveLineDown'
|
|
38
42
|
| 'copyLineUp'
|
|
39
43
|
| 'copyLineDown'
|
|
40
44
|
| 'deleteLine'
|
|
41
45
|
| 'toggleComment'
|
|
46
|
+
| 'toggleBlockComment'
|
|
47
|
+
| 'joinLines'
|
|
48
|
+
| 'trimTrailingWhitespace'
|
|
42
49
|
| 'insertLineBelow'
|
|
43
50
|
| 'insertLineAbove'
|
|
44
51
|
| 'indent'
|
|
45
52
|
| 'outdent'
|
|
53
|
+
| 'fold'
|
|
54
|
+
| 'unfold'
|
|
55
|
+
| 'foldAll'
|
|
56
|
+
| 'unfoldAll'
|
|
46
57
|
| 'undo'
|
|
47
58
|
| 'redo'
|
|
48
59
|
| 'lineStart'
|
|
@@ -53,8 +64,8 @@ export type EditorCommand =
|
|
|
53
64
|
| 'selectToLineEnd'
|
|
54
65
|
| 'selectToDocumentStart'
|
|
55
66
|
| 'selectToDocumentEnd'
|
|
56
|
-
| 'selectWord'
|
|
57
67
|
| 'selectLine'
|
|
68
|
+
| 'goToLine'
|
|
58
69
|
| 'escape';
|
|
59
70
|
|
|
60
71
|
/**
|
|
@@ -67,6 +78,9 @@ export type EditorCommand =
|
|
|
67
78
|
*/
|
|
68
79
|
export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
|
|
69
80
|
{ command: 'find', label: 'Find', mac: { code: 'KeyF', meta: true }, other: { code: 'KeyF', ctrl: true } },
|
|
81
|
+
// ⌘G is the convention (VS Code, Sublime, JetBrains); the browser's own "find
|
|
82
|
+
// next" is not a thing a document editor should defer to.
|
|
83
|
+
{ command: 'goToLine', label: 'Go to line', mac: { code: 'KeyG', meta: true }, other: { code: 'KeyG', ctrl: true } },
|
|
70
84
|
{ command: 'replace', label: 'Replace', mac: { code: 'KeyF', meta: true, alt: true }, other: { code: 'KeyH', ctrl: true } },
|
|
71
85
|
{ command: 'nextMatch', label: 'Next match', mac: { code: 'F3' }, other: { code: 'F3' } },
|
|
72
86
|
{ command: 'previousMatch', label: 'Previous match', mac: { code: 'F3', shift: true }, other: { code: 'F3', shift: true } },
|
|
@@ -78,8 +92,15 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
|
|
|
78
92
|
{ command: 'toggleWordWrap', label: 'Toggle word wrap', mac: { code: 'KeyZ', alt: true }, other: { code: 'KeyZ', alt: true } },
|
|
79
93
|
|
|
80
94
|
{ command: 'selectNextOccurrence', label: 'Add selection to next find match', mac: { code: 'KeyD', meta: true }, other: { code: 'KeyD', ctrl: true } },
|
|
95
|
+
// `⌘L` expands the selection by LINE, which is the one line-selection gesture a
|
|
96
|
+
// browser does not already own (⌘L is the address bar in a browser tab, but this
|
|
97
|
+
// panel is not one — and the chord is what every editor uses for it).
|
|
98
|
+
{ command: 'selectLine', label: 'Select line', mac: { code: 'KeyL', meta: true }, other: { code: 'KeyL', ctrl: true } },
|
|
81
99
|
{ command: 'selectAllOccurrences', label: 'Select all occurrences of current selection', mac: { code: 'KeyL', meta: true, shift: true }, other: { code: 'KeyL', ctrl: true, shift: true } },
|
|
82
100
|
{ command: 'insertCursorBelow', label: 'Insert cursor below', mac: { code: 'KeyD', meta: true, shift: true }, other: { code: 'KeyD', ctrl: true, shift: true } },
|
|
101
|
+
// The pair, so the palette lists both or neither: `addCursorBelow` had a row and
|
|
102
|
+
// this one was reachable only through CM6's own `defaultKeymap`.
|
|
103
|
+
{ command: 'insertCursorAbove', label: 'Insert cursor above', mac: { code: 'KeyD', meta: true, alt: true }, other: { code: 'KeyD', ctrl: true, alt: true } },
|
|
83
104
|
|
|
84
105
|
{ command: 'moveLineUp', label: 'Move line up', mac: { code: 'ArrowUp', alt: true }, other: { code: 'ArrowUp', alt: true } },
|
|
85
106
|
{ command: 'moveLineDown', label: 'Move line down', mac: { code: 'ArrowDown', alt: true }, other: { code: 'ArrowDown', alt: true } },
|
|
@@ -91,12 +112,25 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
|
|
|
91
112
|
// `Slash` is a physical key: on a US layout that is `/`, elsewhere it is
|
|
92
113
|
// wherever the user's own layout puts it.
|
|
93
114
|
{ command: 'toggleComment', label: 'Toggle line comment', mac: { code: 'Slash', meta: true }, other: { code: 'Slash', ctrl: true } },
|
|
115
|
+
// The BLOCK form, which is a different command and not a variant of the line one:
|
|
116
|
+
// a language whose only syntax is a line comment (Python, YAML, shell) has nothing
|
|
117
|
+
// for it to do, and CM6 answers `false` there — an inert chord, which is honest.
|
|
118
|
+
{ command: 'toggleBlockComment', label: 'Toggle block comment', mac: { code: 'Slash', meta: true, shift: true }, other: { code: 'Slash', ctrl: true, shift: true } },
|
|
119
|
+
{ command: 'joinLines', label: 'Join lines', mac: { code: 'KeyJ', meta: true, alt: true }, other: { code: 'KeyJ', ctrl: true, alt: true } },
|
|
120
|
+
{ command: 'trimTrailingWhitespace', label: 'Trim trailing whitespace', mac: { code: 'KeyX', meta: true, alt: true }, other: { code: 'KeyX', ctrl: true, alt: true } },
|
|
94
121
|
|
|
95
122
|
{ command: 'insertLineBelow', label: 'Insert line below', mac: { code: 'Enter', meta: true }, other: { code: 'Enter', ctrl: true } },
|
|
96
123
|
{ command: 'insertLineAbove', label: 'Insert line above', mac: { code: 'Enter', meta: true, shift: true }, other: { code: 'Enter', ctrl: true, shift: true } },
|
|
97
124
|
|
|
98
125
|
{ command: 'indent', label: 'Indent line', mac: { code: 'BracketRight', meta: true }, other: { code: 'BracketRight', ctrl: true } },
|
|
99
126
|
{ command: 'outdent', label: 'Outdent line', mac: { code: 'BracketLeft', meta: true }, other: { code: 'BracketLeft', ctrl: true } },
|
|
127
|
+
// The fold chords are CodeMirror's own (`foldKeymap`), kept because they are
|
|
128
|
+
// the convention every editor uses. `fold`/`unfold` carry `Shift` on
|
|
129
|
+
// Windows/Linux and `Alt` on macOS — the chords VS Code and CM6 both bind.
|
|
130
|
+
{ command: 'fold', label: 'Fold block', mac: { code: 'BracketLeft', meta: true, alt: true }, other: { code: 'BracketLeft', ctrl: true, shift: true } },
|
|
131
|
+
{ command: 'unfold', label: 'Unfold block', mac: { code: 'BracketRight', meta: true, alt: true }, other: { code: 'BracketRight', ctrl: true, shift: true } },
|
|
132
|
+
{ command: 'foldAll', label: 'Fold all blocks', mac: { code: 'BracketLeft', ctrl: true, alt: true }, other: { code: 'BracketLeft', ctrl: true, alt: true } },
|
|
133
|
+
{ command: 'unfoldAll', label: 'Unfold all blocks', mac: { code: 'BracketRight', ctrl: true, alt: true }, other: { code: 'BracketRight', ctrl: true, alt: true } },
|
|
100
134
|
|
|
101
135
|
{ command: 'undo', label: 'Undo', mac: { code: 'KeyZ', meta: true }, other: { code: 'KeyZ', ctrl: true } },
|
|
102
136
|
{
|
|
@@ -123,6 +157,9 @@ export const EDITOR_KEY_BINDINGS: readonly KeyBinding<EditorCommand>[] = [
|
|
|
123
157
|
*/
|
|
124
158
|
export const FIND_BAR_COMMANDS: readonly EditorCommand[] = [
|
|
125
159
|
'find',
|
|
160
|
+
// The dialog lives in the panel, not the find bar, but it is dispatched the same
|
|
161
|
+
// way — one place a chord becomes an action.
|
|
162
|
+
'goToLine',
|
|
126
163
|
'replace',
|
|
127
164
|
'nextMatch',
|
|
128
165
|
'previousMatch',
|
|
@@ -4,21 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Line arithmetic, which
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Line arithmetic, which the highlighter's per-line walk and the find widget's
|
|
8
|
+
* "jump to line N" both read.
|
|
9
|
+
*
|
|
10
|
+
* The interesting cases are the two the arithmetic gets wrong by accident: the
|
|
11
|
+
* empty line a trailing newline opens, and an offset past the end of the
|
|
12
|
+
* document.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
import { describe, expect, test } from 'bun:test';
|
|
14
16
|
|
|
15
|
-
import {
|
|
16
|
-
countLines,
|
|
17
|
-
lineIndexAt,
|
|
18
|
-
lineRangeAt,
|
|
19
|
-
lineRangesInSelection,
|
|
20
|
-
lineStartOffset,
|
|
21
|
-
} from '@/shared/lib/code/editor/lines';
|
|
17
|
+
import { lineIndexAt, lineStartOffset } from '@/shared/lib/code/editor/lines';
|
|
22
18
|
|
|
23
19
|
describe('lineIndexAt and lineStartOffset', () => {
|
|
24
20
|
test('are inverses for every line start', () => {
|
|
@@ -34,48 +30,4 @@ describe('lineIndexAt and lineStartOffset', () => {
|
|
|
34
30
|
expect(lineIndexAt('one\ntwo', 999)).toBe(1);
|
|
35
31
|
expect(lineStartOffset('one\ntwo', 99)).toBe(7);
|
|
36
32
|
});
|
|
37
|
-
|
|
38
|
-
test('count a trailing newline as opening one more, empty line', () => {
|
|
39
|
-
expect(countLines('one\ntwo')).toBe(2);
|
|
40
|
-
expect(countLines('one\ntwo\n')).toBe(3);
|
|
41
|
-
expect(countLines('')).toBe(1);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('lineRangeAt', () => {
|
|
46
|
-
test('includes the trailing newline, so the range can delete or move the line', () => {
|
|
47
|
-
expect(lineRangeAt('one\ntwo\nthree', 5)).toEqual({ start: 4, end: 8 });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('the last line has no newline to include', () => {
|
|
51
|
-
expect(lineRangeAt('one\ntwo', 5)).toEqual({ start: 4, end: 7 });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('a caret on the empty line a trailing newline opens yields an empty range there', () => {
|
|
55
|
-
// `a\n` has an empty second line at offset 2; the honest reading of that
|
|
56
|
-
// position is "no characters of its own", not the previous line.
|
|
57
|
-
expect(lineRangeAt('a\n', 2)).toEqual({ start: 2, end: 2 });
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('lineRangesInSelection', () => {
|
|
62
|
-
test('covers every line the selection touches', () => {
|
|
63
|
-
const text = 'one\ntwo\nthree';
|
|
64
|
-
expect(lineRangesInSelection(text, { start: 4, end: 7 })).toEqual([{ start: 4, end: 8 }]);
|
|
65
|
-
expect(lineRangesInSelection(text, { start: 0, end: 7 })).toEqual([
|
|
66
|
-
{ start: 0, end: 4 },
|
|
67
|
-
{ start: 4, end: 8 },
|
|
68
|
-
]);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('a selection ending exactly at a line start does not touch that line', () => {
|
|
72
|
-
// The rule VS Code applies, and the one that keeps a whole-line selection
|
|
73
|
-
// from splitting off an empty trailing entry.
|
|
74
|
-
const text = 'one\ntwo';
|
|
75
|
-
expect(lineRangesInSelection(text, { start: 0, end: 4 })).toEqual([{ start: 0, end: 4 }]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('an empty selection still names the line the caret is on', () => {
|
|
79
|
-
expect(lineRangesInSelection('one\ntwo', { start: 5, end: 5 })).toEqual([{ start: 4, end: 7 }]);
|
|
80
|
-
});
|
|
81
33
|
});
|