@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,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The outline hook's two bounds, which no component test can see:
|
|
8
|
+
*
|
|
9
|
+
* - **the scan is DEBOUNCED**, because it walks the whole buffer and the buffer
|
|
10
|
+
* changes on every keystroke (measured: 704 ms per keystroke at 10 MB with a
|
|
11
|
+
* live scan, 34 ms without). A declaration list does not change mid-word, so
|
|
12
|
+
* the rows are recomputed once typing stops;
|
|
13
|
+
* - **a different document scans IMMEDIATELY**, because rows from the previous
|
|
14
|
+
* file point at lines of a document that is gone;
|
|
15
|
+
* - **a buffer past the scan ceiling is never scanned**, and says why.
|
|
16
|
+
*
|
|
17
|
+
* Rendered with `h()` against happy-dom and driven with FAKE timers: the
|
|
18
|
+
* behaviour under test is a timer, so advancing the clock is the only way to
|
|
19
|
+
* assert it without paying the debounce in every run.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { afterAll, afterEach, beforeAll, describe, expect, jest, test } from 'bun:test';
|
|
23
|
+
import { Window } from 'happy-dom';
|
|
24
|
+
import { h, render } from 'preact';
|
|
25
|
+
import { act } from 'preact/test-utils';
|
|
26
|
+
import {
|
|
27
|
+
OUTLINE_SCAN_DELAY_MS,
|
|
28
|
+
useOutlineView,
|
|
29
|
+
type OutlineView,
|
|
30
|
+
} from '@/client/hooks/editor/use-outline-view';
|
|
31
|
+
import { MAX_OUTLINE_SCAN_CHARS } from '@/shared/lib/code/outline/rows';
|
|
32
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
33
|
+
|
|
34
|
+
let container: HTMLElement;
|
|
35
|
+
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
if (container) {
|
|
42
|
+
render(null, container);
|
|
43
|
+
container.remove();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
afterAll(() => {
|
|
48
|
+
restoreDomGlobals();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/** One declaration per `export function`, so a buffer's rows are countable. */
|
|
52
|
+
function source(count: number): string {
|
|
53
|
+
return Array.from({ length: count }, (_, i) => `export function fn${i}() {}`).join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ProbeProps {
|
|
57
|
+
content: string;
|
|
58
|
+
language?: string;
|
|
59
|
+
path?: string | null;
|
|
60
|
+
state?: 'ready' | 'loading';
|
|
61
|
+
note?: string | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let latest: OutlineView | null = null;
|
|
65
|
+
|
|
66
|
+
function Probe({ content, language = 'typescript', path = 'src/a.ts', state = 'ready', note = null }: ProbeProps) {
|
|
67
|
+
latest = useOutlineView({ content, language, path, state, note });
|
|
68
|
+
return h('div', {});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function mount(props: ProbeProps): Promise<void> {
|
|
72
|
+
latest = null;
|
|
73
|
+
container = document.createElement('div');
|
|
74
|
+
document.body.appendChild(container);
|
|
75
|
+
await act(async () => {
|
|
76
|
+
render(h(Probe, props), container);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Re-render with new props, then flush Preact's own scheduling. */
|
|
81
|
+
async function update(props: ProbeProps): Promise<void> {
|
|
82
|
+
await act(async () => {
|
|
83
|
+
render(h(Probe, props), container);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Let the debounce fire, plus a tick for the re-render it causes. */
|
|
88
|
+
async function settle(): Promise<void> {
|
|
89
|
+
jest.advanceTimersByTime(OUTLINE_SCAN_DELAY_MS);
|
|
90
|
+
await act(async () => {});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Run the body under fake timers, restoring real ones even on a throw. */
|
|
94
|
+
async function withFakeTimers(body: () => Promise<void>): Promise<void> {
|
|
95
|
+
jest.useFakeTimers();
|
|
96
|
+
try {
|
|
97
|
+
await body();
|
|
98
|
+
} finally {
|
|
99
|
+
jest.useRealTimers();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
describe('useOutlineView', () => {
|
|
104
|
+
test('the first document is outlined on the FIRST render, not one timer later', async () => {
|
|
105
|
+
await mount({ content: source(3) });
|
|
106
|
+
|
|
107
|
+
// No `settle()`: a freshly opened file's rows must not arrive late.
|
|
108
|
+
expect(latest?.symbols.map((symbol) => symbol.name)).toEqual(['fn0', 'fn1', 'fn2']);
|
|
109
|
+
expect(latest?.total).toBe(3);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('a keystroke does NOT rescan until the buffer goes quiet', async () => {
|
|
113
|
+
await withFakeTimers(async () => {
|
|
114
|
+
await mount({ content: source(2) });
|
|
115
|
+
expect(latest?.total).toBe(2);
|
|
116
|
+
|
|
117
|
+
// A new declaration typed in, but the debounce has not elapsed: the rows
|
|
118
|
+
// are still the previous scan's. This is the property that makes typing
|
|
119
|
+
// cheap on a large file.
|
|
120
|
+
await update({ content: source(3) });
|
|
121
|
+
expect(latest?.total).toBe(2);
|
|
122
|
+
|
|
123
|
+
await settle();
|
|
124
|
+
expect(latest?.total).toBe(3);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('a burst of edits coalesces into ONE scan of the final text', async () => {
|
|
129
|
+
await withFakeTimers(async () => {
|
|
130
|
+
await mount({ content: source(1) });
|
|
131
|
+
|
|
132
|
+
for (const count of [2, 3, 4, 5]) {
|
|
133
|
+
await update({ content: source(count) });
|
|
134
|
+
// Shorter than the debounce, so each edit re-arms it.
|
|
135
|
+
jest.advanceTimersByTime(20);
|
|
136
|
+
await act(async () => {});
|
|
137
|
+
}
|
|
138
|
+
// Nothing has landed yet: the last edit re-armed the timer.
|
|
139
|
+
expect(latest?.total).toBe(1);
|
|
140
|
+
|
|
141
|
+
await settle();
|
|
142
|
+
expect(latest?.total).toBe(5);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('a DIFFERENT document is scanned at once, never on the timer', async () => {
|
|
147
|
+
await mount({ content: source(2), path: 'src/a.ts' });
|
|
148
|
+
expect(latest?.total).toBe(2);
|
|
149
|
+
|
|
150
|
+
await update({ content: source(7), path: 'src/b.ts' });
|
|
151
|
+
// No settle: rows from the previous file must not survive a tab switch.
|
|
152
|
+
expect(latest?.total).toBe(7);
|
|
153
|
+
expect(latest?.symbols[0].name).toBe('fn0');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('a buffer past the scan ceiling is never scanned, and the notice says why', async () => {
|
|
157
|
+
await withFakeTimers(async () => {
|
|
158
|
+
// One character over the ceiling, without a megabyte of real text.
|
|
159
|
+
const padded = `${source(2)}\n${'x'.repeat(MAX_OUTLINE_SCAN_CHARS)}`;
|
|
160
|
+
await mount({ content: padded });
|
|
161
|
+
await settle();
|
|
162
|
+
|
|
163
|
+
expect(latest?.symbols).toEqual([]);
|
|
164
|
+
expect(latest?.total).toBe(0);
|
|
165
|
+
expect(latest?.notice).toContain('too large to outline');
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('a document that is not ready has no rows, and prints the state sentence', async () => {
|
|
170
|
+
await mount({ content: source(3), state: 'loading' });
|
|
171
|
+
|
|
172
|
+
expect(latest?.symbols).toEqual([]);
|
|
173
|
+
expect(latest?.notice).toBe('Reading the file…');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('the caller note wins over the state sentence', async () => {
|
|
177
|
+
await mount({ content: '', state: 'ready', note: 'This tab has no outline.' });
|
|
178
|
+
|
|
179
|
+
expect(latest?.symbols).toEqual([]);
|
|
180
|
+
expect(latest?.notice).toBe('This tab has no outline.');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -15,15 +15,44 @@
|
|
|
15
15
|
*
|
|
16
16
|
* The scan runs only in the `ready` state, so a half-read buffer never produces
|
|
17
17
|
* a list of rows that are about to move.
|
|
18
|
+
*
|
|
19
|
+
* Two bounds keep a large file from making the panel the most expensive thing in
|
|
20
|
+
* the editor, and each was measured rather than guessed (see `outline/rows.ts`):
|
|
21
|
+
*
|
|
22
|
+
* - **The scan is DEBOUNCED.** It walks the whole document — 366 ms on 10 MB in
|
|
23
|
+
* Bun — and the published buffer changes on every keystroke, so a live scan
|
|
24
|
+
* charged that to typing. Measured in the browser at 10 MB with the panel
|
|
25
|
+
* open: 704 ms per keystroke live, 34 ms without. A declaration list does not
|
|
26
|
+
* change mid-word, so the rows are recomputed once the buffer goes quiet.
|
|
27
|
+
* - **The scan is SKIPPED past `MAX_OUTLINE_SCAN_CHARS`**, and the panel says
|
|
28
|
+
* why instead of showing an empty list that reads as "no declarations here".
|
|
29
|
+
*
|
|
30
|
+
* A DIFFERENT DOCUMENT is scanned at once, never on the timer: rows from the
|
|
31
|
+
* previous file point at lines of a document that is gone.
|
|
18
32
|
*/
|
|
19
33
|
|
|
20
|
-
import { useMemo } from 'preact/hooks';
|
|
34
|
+
import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
21
35
|
import { extractOutline } from '@/shared/lib/code/outline/extract';
|
|
22
36
|
import type { OutlineSymbol } from '@/shared/lib/code/outline/types';
|
|
23
37
|
import { outlineEmptyNotice, type EditorDocumentState } from '@/shared/lib/code/outline/document';
|
|
38
|
+
import { MAX_OUTLINE_SCAN_CHARS, outlineTooLargeNotice, outlineWindow } from '@/shared/lib/code/outline/rows';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How long the buffer must be quiet before the outline is re-scanned.
|
|
42
|
+
*
|
|
43
|
+
* Long enough that typing never pays for it, short enough that the rows are
|
|
44
|
+
* back before the reader looks for them — and sooner than the 800 ms autosave,
|
|
45
|
+
* so the outline still describes the buffer before the file on disk does.
|
|
46
|
+
*/
|
|
47
|
+
export const OUTLINE_SCAN_DELAY_MS = 300;
|
|
24
48
|
|
|
25
49
|
export interface OutlineView {
|
|
50
|
+
/** The rows to render — bounded by `MAX_OUTLINE_ROWS`. */
|
|
26
51
|
symbols: OutlineSymbol[];
|
|
52
|
+
/** Every symbol the scan found, including the ones not rendered. */
|
|
53
|
+
total: number;
|
|
54
|
+
/** True when the panel is showing only the first `MAX_OUTLINE_ROWS`. */
|
|
55
|
+
truncated: boolean;
|
|
27
56
|
/** The sentence to print when `symbols` is empty. */
|
|
28
57
|
notice: string;
|
|
29
58
|
}
|
|
@@ -36,12 +65,70 @@ export interface OutlineSource {
|
|
|
36
65
|
/** The document's own state, so "still reading" is not "no symbols". */
|
|
37
66
|
state: EditorDocumentState;
|
|
38
67
|
note: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* Identity of the document being drawn. A change here scans IMMEDIATELY
|
|
70
|
+
* instead of on the timer — see the module note.
|
|
71
|
+
*/
|
|
72
|
+
path: string | null;
|
|
39
73
|
}
|
|
40
74
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
75
|
+
interface ScanInput {
|
|
76
|
+
content: string;
|
|
77
|
+
language: string;
|
|
78
|
+
path: string | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Too large to outline: no scan, and a sentence that names the reason. */
|
|
82
|
+
function tooLarge(content: string): boolean {
|
|
83
|
+
return content.length > MAX_OUTLINE_SCAN_CHARS;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function useOutlineView({ content, language, state, note, path }: OutlineSource): OutlineView {
|
|
87
|
+
// Seeded from the mount values, so the first document's outline is ready on
|
|
88
|
+
// the first render rather than one timer later.
|
|
89
|
+
const [scan, setScan] = useState<ScanInput>({ content, language, path });
|
|
90
|
+
const pathRef = useRef(path);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const documentChanged = path !== pathRef.current;
|
|
94
|
+
pathRef.current = path;
|
|
95
|
+
// A document past the ceiling is never scanned, so there is nothing to
|
|
96
|
+
// schedule — and re-arming a timer per keystroke on a file the panel will
|
|
97
|
+
// not describe is work for a sentence that never changes.
|
|
98
|
+
if (documentChanged || tooLarge(content)) {
|
|
99
|
+
setScan((prev) =>
|
|
100
|
+
prev.content === content && prev.language === language ? prev : { content, language, path },
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Trailing debounce: every keystroke re-arms it, so the scan runs once the
|
|
105
|
+
// buffer goes quiet. The updater returns `prev` when nothing moved, which
|
|
106
|
+
// makes the mount's own timer a no-op instead of a second scan of the same
|
|
107
|
+
// text.
|
|
108
|
+
const timer = window.setTimeout(() => {
|
|
109
|
+
setScan((prev) =>
|
|
110
|
+
prev.content === content && prev.language === language ? prev : { content, language, path },
|
|
111
|
+
);
|
|
112
|
+
}, OUTLINE_SCAN_DELAY_MS);
|
|
113
|
+
return () => window.clearTimeout(timer);
|
|
114
|
+
}, [path, content, language]);
|
|
115
|
+
|
|
116
|
+
const symbols = useMemo(() => {
|
|
117
|
+
if (state !== 'ready' || tooLarge(scan.content)) return [];
|
|
118
|
+
return extractOutline(scan.content, scan.language);
|
|
119
|
+
}, [state, scan]);
|
|
120
|
+
|
|
121
|
+
const visible = useMemo(() => outlineWindow(symbols), [symbols]);
|
|
122
|
+
// The LIVE length, not the scanned one: the sentence names the file's size as
|
|
123
|
+
// it is now, and reading it off `scan` would make it lag a debounce behind.
|
|
124
|
+
const tooLargeNotice = state === 'ready' ? outlineTooLargeNotice(content.length) : null;
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
symbols: visible.rows,
|
|
128
|
+
total: visible.total,
|
|
129
|
+
truncated: visible.truncated,
|
|
130
|
+
// The size refusal wins over the empty-state sentence: "too large to
|
|
131
|
+
// outline" is the reason, and the generic one would hide it.
|
|
132
|
+
notice: tooLargeNotice ?? outlineEmptyNotice(state, note),
|
|
133
|
+
};
|
|
47
134
|
}
|
|
@@ -161,6 +161,19 @@ function storedOffsets(): ScrollPositions | undefined {
|
|
|
161
161
|
return getSessionValue<ScrollPositions>(SESSION, SCROLL_POSITIONS_KEY);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* A READER's scroll: the input that causes it, then the movement.
|
|
166
|
+
*
|
|
167
|
+
* The hook distinguishes the two, and it has to: a `scroll` with no input behind
|
|
168
|
+
* it is the browser re-anchoring the document as its real height lands, which
|
|
169
|
+
* must NOT be read as the reader moving. `wheel` is the simplest input a code
|
|
170
|
+
* surface sees.
|
|
171
|
+
*/
|
|
172
|
+
function readerScroll(probe: ProbeHandle, top: number): void {
|
|
173
|
+
probe.el.dispatchEvent(new Event('wheel', { bubbles: true }));
|
|
174
|
+
probe.el.scrollTop = top;
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
describe('useScrollRestore', () => {
|
|
165
178
|
test('restores the stored offset for the tab and surface', async () => {
|
|
166
179
|
const probe = await mount('7', 'code', { '7': { code: 900 } });
|
|
@@ -181,7 +194,47 @@ describe('useScrollRestore', () => {
|
|
|
181
194
|
|
|
182
195
|
test("a reader's own scroll wins over a pending restore", async () => {
|
|
183
196
|
const probe = await mount('7', 'code', { '7': { code: 900 } });
|
|
184
|
-
probe
|
|
197
|
+
readerScroll(probe, 120);
|
|
198
|
+
await act(async () => {
|
|
199
|
+
StubResizeObserver.latest()?.fire();
|
|
200
|
+
});
|
|
201
|
+
expect(probe.el.scrollTop).toBe(120);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('the document re-anchoring is not the reader, and the restore re-applies', async () => {
|
|
205
|
+
// The bug the e2e spec found: the restore writes 900, the document's real
|
|
206
|
+
// height lands a frame later, and CodeMirror re-anchors to keep the visible
|
|
207
|
+
// content stable — `scrollTop` moves to 420 with nobody assigning. Reading
|
|
208
|
+
// that as the reader's own scroll dropped the pending restore, so the
|
|
209
|
+
// anchored value became where the reader stayed (measured: opening a tab
|
|
210
|
+
// moved them 29 lines) and the wrong offset was persisted.
|
|
211
|
+
const probe = await mount('7', 'code', { '7': { code: 900 } }, 600);
|
|
212
|
+
expect(probe.el.scrollTop).toBe(100);
|
|
213
|
+
|
|
214
|
+
// The browser's own correction: no input event behind it.
|
|
215
|
+
probe.el.scrollTop = 420;
|
|
216
|
+
probe.setHeight(5000);
|
|
217
|
+
await act(async () => {
|
|
218
|
+
StubResizeObserver.latest()?.fire();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// The restore is still in charge, so the reader lands where the session
|
|
222
|
+
// recorded — not where the anchoring put them.
|
|
223
|
+
expect(probe.el.scrollTop).toBe(900);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('a reader’s scroll is still theirs after an anchoring correction', async () => {
|
|
227
|
+
// The discriminator must not swallow the NEXT real scroll: the input that
|
|
228
|
+
// explains a movement is consumed by it, so a reader who scrolls after the
|
|
229
|
+
// document settles keeps their own position.
|
|
230
|
+
const probe = await mount('7', 'code', { '7': { code: 900 } });
|
|
231
|
+
probe.el.scrollTop = 420; // anchoring, no input
|
|
232
|
+
await act(async () => {
|
|
233
|
+
StubResizeObserver.latest()?.fire();
|
|
234
|
+
});
|
|
235
|
+
expect(probe.el.scrollTop).toBe(900);
|
|
236
|
+
|
|
237
|
+
readerScroll(probe, 120);
|
|
185
238
|
await act(async () => {
|
|
186
239
|
StubResizeObserver.latest()?.fire();
|
|
187
240
|
});
|
|
@@ -192,7 +245,7 @@ describe('useScrollRestore', () => {
|
|
|
192
245
|
const probe = await mount('7', 'code', {});
|
|
193
246
|
jest.useFakeTimers();
|
|
194
247
|
try {
|
|
195
|
-
probe
|
|
248
|
+
readerScroll(probe, 350);
|
|
196
249
|
jest.advanceTimersByTime(200);
|
|
197
250
|
await act(async () => {});
|
|
198
251
|
} finally {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
* overwrite the position this hook exists to keep.
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
import { useCallback, useContext, useLayoutEffect, useRef } from 'preact/hooks';
|
|
35
|
+
import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from 'preact/hooks';
|
|
36
36
|
import { SessionStateContext } from '@/client/hooks/workspace/session-state/context';
|
|
37
37
|
import { getSessionValue, setSessionKey } from '@/shared/lib/workspace/session-state/store';
|
|
38
38
|
import {
|
|
@@ -52,6 +52,29 @@ const SAVE_DEBOUNCE_MS = 150;
|
|
|
52
52
|
/** Scroll deltas below this are rounding, not a move. */
|
|
53
53
|
const NOISE_PX = 1;
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The cancel hook of every restore currently armed, by scroller.
|
|
57
|
+
*
|
|
58
|
+
* A pending restore REPLAYS while the document settles, and it re-applies
|
|
59
|
+
* through a `ResizeObserver` — which can fire BEFORE the scroll event a
|
|
60
|
+
* programmatic reveal causes. Measured: an outline jump scrolled a 2 520-line
|
|
61
|
+
* file to 34 695 px and the observer wrote the stored 0 back 375 ms later, so
|
|
62
|
+
* the caret moved and the view stayed at the top.
|
|
63
|
+
*
|
|
64
|
+
* An explicit reveal therefore has to CANCEL the restore rather than race it,
|
|
65
|
+
* and the surface that scrolls is the one that knows. This registry is that
|
|
66
|
+
* hand-off: keyed by the element, so a caller needs no reference to the hook
|
|
67
|
+
* instance that armed it (the surface owns the scroller; the panel owns the
|
|
68
|
+
* hook).
|
|
69
|
+
*/
|
|
70
|
+
const armedRestores = new Map<HTMLElement, () => void>();
|
|
71
|
+
|
|
72
|
+
/** Stop a pending restore of `element` — a reveal wins over a remembered offset. */
|
|
73
|
+
export function cancelScrollRestore(element: HTMLElement | null): void {
|
|
74
|
+
if (!element) return;
|
|
75
|
+
armedRestores.get(element)?.();
|
|
76
|
+
}
|
|
77
|
+
|
|
55
78
|
/** What a caller attaches to its scroll container. */
|
|
56
79
|
export interface ScrollRestoreBinding {
|
|
57
80
|
ref: (element: HTMLElement | null) => void;
|
|
@@ -67,6 +90,16 @@ export interface UseScrollRestoreOptions {
|
|
|
67
90
|
ready?: boolean;
|
|
68
91
|
/** The session-state slot to read/write; the editor column's by default. */
|
|
69
92
|
slot?: string;
|
|
93
|
+
/**
|
|
94
|
+
* The element to restore, for a caller that does not own a `ref` on it.
|
|
95
|
+
*
|
|
96
|
+
* The code surface's scroller belongs to CodeMirror (`view.scrollDOM`) and
|
|
97
|
+
* exists only after the view mounts, so the surface reports it through
|
|
98
|
+
* `onScroller` and the caller passes it here. `undefined` means "this caller
|
|
99
|
+
* uses `ref`"; `null` means "the element is not there yet", which re-arms the
|
|
100
|
+
* restore on the next render that has one.
|
|
101
|
+
*/
|
|
102
|
+
element?: HTMLElement | null;
|
|
70
103
|
}
|
|
71
104
|
|
|
72
105
|
export function useScrollRestore({
|
|
@@ -74,6 +107,7 @@ export function useScrollRestore({
|
|
|
74
107
|
surface,
|
|
75
108
|
ready = true,
|
|
76
109
|
slot = SCROLL_POSITIONS_KEY,
|
|
110
|
+
element: providedElement,
|
|
77
111
|
}: UseScrollRestoreOptions): ScrollRestoreBinding {
|
|
78
112
|
// Read OPTIONALLY: the shared diff views also draw a chat tool card, and a
|
|
79
113
|
// caller may mount one without the provider. A null context makes the whole
|
|
@@ -100,6 +134,37 @@ export function useScrollRestore({
|
|
|
100
134
|
* whose height is still growing then stayed where the clamp left it.
|
|
101
135
|
*/
|
|
102
136
|
const writingRef = useRef(false);
|
|
137
|
+
/**
|
|
138
|
+
* What the element's `scrollTop` was at the last observation, so a scroll
|
|
139
|
+
* event that moves it WITHOUT anyone assigning can be recognised as the
|
|
140
|
+
* browser's own anchoring rather than the reader's.
|
|
141
|
+
*
|
|
142
|
+
* This is the bug the e2e spec found on CI and could not explain: returning to
|
|
143
|
+
* a long file landed the reader on line 99 instead of line 70, and the wrong
|
|
144
|
+
* offset was then persisted. Measured in the browser: the restore wrote 1255,
|
|
145
|
+
* the document's real height arrived a frame later (5796 → 7232), and
|
|
146
|
+
* CodeMirror re-anchored — `scrollTop` became 1777 with no assignment from
|
|
147
|
+
* this hook. That produced a `scroll` event, the handler below compared it
|
|
148
|
+
* against `restoredTopRef` (1255), read a 522px delta, and treated it as the
|
|
149
|
+
* reader's own scroll: the pending restore was dropped, and the anchored
|
|
150
|
+
* value became what got stored. The reader moved 29 lines for opening a tab.
|
|
151
|
+
*
|
|
152
|
+
* An anchoring correction is not a reader. It is re-applied like any other
|
|
153
|
+
* height change, because the target offset is the one the session recorded.
|
|
154
|
+
*/
|
|
155
|
+
const observedTopRef = useRef(0);
|
|
156
|
+
/**
|
|
157
|
+
* Whether the reader has DONE something since the last scroll event — the
|
|
158
|
+
* only thing that separates their scroll from the browser's own.
|
|
159
|
+
*
|
|
160
|
+
* Every way a reader scrolls a code surface starts with an input event: a
|
|
161
|
+
* wheel, a key (arrows, PageDown, Home/End), a pointer press on the scrollbar
|
|
162
|
+
* or a drag-select, a touch. CodeMirror re-anchoring starts with none, so a
|
|
163
|
+
* `scroll` with no input behind it is the document settling. The flag is
|
|
164
|
+
* cleared by the scroll it explains, so the next unattributed move is read as
|
|
165
|
+
* anchoring again.
|
|
166
|
+
*/
|
|
167
|
+
const readerIntentRef = useRef(false);
|
|
103
168
|
/** The last offset the READER produced, persisted on the way out. */
|
|
104
169
|
const lastTopRef = useRef<number | null>(null);
|
|
105
170
|
const saveTimerRef = useRef<ReturnType<typeof setTimeout>>();
|
|
@@ -113,13 +178,17 @@ export function useScrollRestore({
|
|
|
113
178
|
pendingRef.current = null;
|
|
114
179
|
return;
|
|
115
180
|
}
|
|
116
|
-
if (Math.abs(element.scrollTop - pending.top) < NOISE_PX)
|
|
181
|
+
if (Math.abs(element.scrollTop - pending.top) < NOISE_PX) {
|
|
182
|
+
observedTopRef.current = element.scrollTop;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
117
185
|
writingRef.current = true;
|
|
118
186
|
element.scrollTop = pending.top;
|
|
119
187
|
writingRef.current = false;
|
|
120
188
|
// Read back: the document may be shorter than the target, and the clamped
|
|
121
189
|
// value is what an asynchronous scroll event will report.
|
|
122
190
|
restoredTopRef.current = element.scrollTop;
|
|
191
|
+
observedTopRef.current = element.scrollTop;
|
|
123
192
|
}, []);
|
|
124
193
|
|
|
125
194
|
const attach = useCallback(
|
|
@@ -152,9 +221,23 @@ export function useScrollRestore({
|
|
|
152
221
|
// because the event may arrive synchronously (during the assignment) or
|
|
153
222
|
// on a later frame (against the value the write landed on).
|
|
154
223
|
if (writingRef.current) return;
|
|
224
|
+
// Moved with nobody assigning AND no reader input behind it: CodeMirror
|
|
225
|
+
// re-anchoring after the document's real height landed. NOT the reader —
|
|
226
|
+
// re-applying the recorded offset is what keeps them where they were. See
|
|
227
|
+
// `observedTopRef` for the measurement.
|
|
228
|
+
const moved = Math.abs(top - observedTopRef.current) >= NOISE_PX;
|
|
229
|
+
observedTopRef.current = top;
|
|
230
|
+
if (moved && !readerIntentRef.current) {
|
|
231
|
+
applyPending();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
155
234
|
if (Math.abs(top - restoredTopRef.current) < NOISE_PX * 2) return;
|
|
156
235
|
pendingRef.current = null;
|
|
157
236
|
}
|
|
237
|
+
observedTopRef.current = top;
|
|
238
|
+
// The input this scroll belongs to has now been accounted for; the next
|
|
239
|
+
// unattributed move is anchoring again.
|
|
240
|
+
readerIntentRef.current = false;
|
|
158
241
|
lastTopRef.current = top;
|
|
159
242
|
clearTimeout(saveTimerRef.current);
|
|
160
243
|
saveTimerRef.current = setTimeout(() => {
|
|
@@ -162,14 +245,47 @@ export function useScrollRestore({
|
|
|
162
245
|
const value = lastTopRef.current;
|
|
163
246
|
if (value !== null) persist(value);
|
|
164
247
|
}, SAVE_DEBOUNCE_MS);
|
|
165
|
-
}, [persist, tabKey]);
|
|
248
|
+
}, [applyPending, persist, tabKey]);
|
|
249
|
+
|
|
250
|
+
// A provided element is not a React-rendered node, so its scroll events have
|
|
251
|
+
// to be wired here: the caller has no `onScroll` prop to hang them on. The
|
|
252
|
+
// ref path keeps the caller's own `onScroll`.
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
if (!providedElement) return;
|
|
255
|
+
const listener = () => onScroll();
|
|
256
|
+
providedElement.addEventListener('scroll', listener, { passive: true });
|
|
257
|
+
return () => providedElement.removeEventListener('scroll', listener);
|
|
258
|
+
}, [providedElement, onScroll]);
|
|
259
|
+
|
|
260
|
+
// What counts as the reader having scrolled, for `readerIntentRef`. Wired on
|
|
261
|
+
// the element AND the window, because a keydown goes to the focused editor
|
|
262
|
+
// while a wheel over the gutter goes to the window's capture phase.
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
const element = providedElement ?? elementRef.current;
|
|
265
|
+
if (!element) return;
|
|
266
|
+
const note = () => {
|
|
267
|
+
readerIntentRef.current = true;
|
|
268
|
+
};
|
|
269
|
+
const types = ['wheel', 'keydown', 'pointerdown', 'touchstart'] as const;
|
|
270
|
+
for (const type of types) element.addEventListener(type, note, { passive: true });
|
|
271
|
+
window.addEventListener('keydown', note, { passive: true });
|
|
272
|
+
return () => {
|
|
273
|
+
for (const type of types) element.removeEventListener(type, note);
|
|
274
|
+
window.removeEventListener('keydown', note);
|
|
275
|
+
};
|
|
276
|
+
}, [providedElement]);
|
|
166
277
|
|
|
167
278
|
// A layout effect so the restore lands in the same frame the tab paints — a
|
|
168
279
|
// passive effect would show the document's head for one frame first.
|
|
169
280
|
useLayoutEffect(() => {
|
|
170
281
|
pendingRef.current = null;
|
|
171
282
|
lastTopRef.current = null;
|
|
283
|
+
readerIntentRef.current = false;
|
|
172
284
|
let observer: ResizeObserver | null = null;
|
|
285
|
+
// A provided element WINS over the ref: the caller handed us the element it
|
|
286
|
+
// wants restored, and a stale ref from the other surface of the same tab
|
|
287
|
+
// must not be restored instead.
|
|
288
|
+
if (providedElement !== undefined) elementRef.current = providedElement;
|
|
173
289
|
const element = elementRef.current;
|
|
174
290
|
|
|
175
291
|
if (ready && storeReady && tabKey && element) {
|
|
@@ -179,6 +295,9 @@ export function useScrollRestore({
|
|
|
179
295
|
// of it. "No stored offset" means the top, and the top is where they go.
|
|
180
296
|
const top = readScrollTop(getSessionValue<ScrollPositions>(sessionId, slot), tabKey, surface);
|
|
181
297
|
pendingRef.current = { top, until: performance.now() + RESTORE_WINDOW_MS };
|
|
298
|
+
armedRestores.set(element, () => {
|
|
299
|
+
pendingRef.current = null;
|
|
300
|
+
});
|
|
182
301
|
applyPending();
|
|
183
302
|
// The document's own height is what moves after this commit (measurement,
|
|
184
303
|
// a width animation, spacers landing), so its growth is what re-applies.
|
|
@@ -190,6 +309,7 @@ export function useScrollRestore({
|
|
|
190
309
|
}
|
|
191
310
|
|
|
192
311
|
return () => {
|
|
312
|
+
if (element) armedRestores.delete(element);
|
|
193
313
|
observer?.disconnect();
|
|
194
314
|
clearTimeout(saveTimerRef.current);
|
|
195
315
|
saveTimerRef.current = undefined;
|
|
@@ -203,7 +323,7 @@ export function useScrollRestore({
|
|
|
203
323
|
};
|
|
204
324
|
// `applyPending`/`persist` are stable, and re-running this effect restarts
|
|
205
325
|
// the restore — which is exactly what a tab or surface change needs.
|
|
206
|
-
}, [ready, storeReady, tabKey, surface, sessionId, slot, applyPending, persist]);
|
|
326
|
+
}, [ready, storeReady, tabKey, surface, sessionId, slot, applyPending, persist, providedElement]);
|
|
207
327
|
|
|
208
328
|
return { ref: attach, onScroll };
|
|
209
329
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Landing a search row's hit in the editor.
|
|
8
|
+
*
|
|
9
|
+
* The hand-off has one subtle rule and it is the whole reason this is a hook: the
|
|
10
|
+
* resolved target is RECOMPUTED on every edit (its marks track the live buffer),
|
|
11
|
+
* but the JUMP must fire once per request. Keying an effect on the target itself
|
|
12
|
+
* would drag the view back to the match after every keystroke — the user types one
|
|
13
|
+
* character and the caret jumps away.
|
|
14
|
+
*
|
|
15
|
+
* The request object is the identity: `useSearchRevealTarget` hands back the same
|
|
16
|
+
* object for the same request and a new one for a new hit, so comparing it is both
|
|
17
|
+
* necessary and sufficient.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
21
|
+
|
|
22
|
+
import type { FindOptions } from '@/shared/lib/code/editor/find-scan';
|
|
23
|
+
|
|
24
|
+
/** What `useSearchRevealTarget` answers, as this hook needs it. */
|
|
25
|
+
export interface SearchRevealTarget {
|
|
26
|
+
request: {
|
|
27
|
+
query: string;
|
|
28
|
+
options: FindOptions;
|
|
29
|
+
line: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface UseSearchRevealJumpOptions {
|
|
34
|
+
/** The resolved target, or null while the buffer is not trustworthy. */
|
|
35
|
+
searchReveal: SearchRevealTarget | null;
|
|
36
|
+
revealMatch: (request: { query: string; options: FindOptions; line: number }) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useSearchRevealJump({ searchReveal, revealMatch }: UseSearchRevealJumpOptions): void {
|
|
40
|
+
// The callback is rebuilt whenever the find state moves, so it is read through a
|
|
41
|
+
// ref: putting it in the dependency list would re-run the jump on every keystroke
|
|
42
|
+
// in the query field.
|
|
43
|
+
const revealRef = useRef(revealMatch);
|
|
44
|
+
revealRef.current = revealMatch;
|
|
45
|
+
/** The request already served, so a re-render cannot re-fire it. */
|
|
46
|
+
const firedRef = useRef<unknown>(null);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!searchReveal || firedRef.current === searchReveal.request) return;
|
|
50
|
+
firedRef.current = searchReveal.request;
|
|
51
|
+
revealRef.current({
|
|
52
|
+
query: searchReveal.request.query,
|
|
53
|
+
options: searchReveal.request.options,
|
|
54
|
+
line: searchReveal.request.line,
|
|
55
|
+
});
|
|
56
|
+
}, [searchReveal]);
|
|
57
|
+
}
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
import { useEffect, useMemo, useState } from 'preact/hooks';
|
|
30
30
|
import { useSyncExternalStore } from 'preact/compat';
|
|
31
31
|
|
|
32
|
-
import { findMatches, lineStartOffset, matchIndexAtOrAfter } from '@/shared/lib/code/editor/find';
|
|
32
|
+
import { findMatches, lineStartOffset, matchIndexAtOrAfter } from '@/shared/lib/code/editor/find-scan';
|
|
33
33
|
import {
|
|
34
34
|
getSearchReveal,
|
|
35
35
|
setSearchReveal,
|