Skip to content

Vendor explicit file-focus navigation + viewed/collapse shortcuts#64

Open
dastratakos wants to merge 1 commit into
dastratakos/cli-shared-file-treefrom
dastratakos/cli-file-focus-nav
Open

Vendor explicit file-focus navigation + viewed/collapse shortcuts#64
dastratakos wants to merge 1 commit into
dastratakos/cli-shared-file-treefrom
dastratakos/cli-file-focus-nav

Conversation

@dastratakos
Copy link
Copy Markdown
Contributor

@dastratakos dastratakos commented Jun 2, 2026

Summary

Syncs the CLI with the monorepo's keyboard-navigation overhaul that landed after the fork. Replaces the CLI's scroll-derived "active file" model with an explicit focused-file state machine and adds the file-level keyboard shortcuts.

Stacked on #63 (shared file tree). Review/merge that first — this PR is based on dastratakos/cli-shared-file-tree, and its focusedFilePath wiring depends on the tree consumers introduced there. Rebases onto main once #63 lands.

Ports two monorepo PRs:

  • #943 — explicit file focus navigation. New useCurrentFile tracks currentFilePath + isFileKeyboardMode; a shared useFileDiffNavigation orchestrator owns the diff-viewer ref and wires every shortcut. Keyboard focus shows an outline ring (keyboardFocusedFilePath); click/scroll selection only highlights the picker row (currentFilePath).
  • #975 / #910v (mark file viewed + advance focus, pinning the marked file to the top), ; / Shift+; (collapse file / all files), Esc (exit keyboard mode), and re-bind chapter-viewed from vShift+V. file-header gains ShortcutTooltip hints on the viewed + collapse controls.

Changes

  • New hooks (vendored, imports adapted to @/lib/*): use-current-file, use-file-viewed-key, use-file-collapse-keys, use-file-keyboard-mode-exit-key, use-file-diff-navigation. use-file-navigation-keys rewritten to the focus signature (files, currentFilePath, onFocusFile, enabled).
  • Deleted: use-active-file-on-scroll.ts (the old scroll heuristic).
  • Registry: added MARK_FILE_AS_VIEWED, EXIT_FILE_KEYBOARD_MODE, TOGGLE_FILE_COLLAPSED, TOGGLE_ALL_FILES_COLLAPSED; re-bound MARK_CHAPTER_AS_VIEWED to Shift+V.
  • Routes: both files-page and chapter-detail-page delegate to useFileDiffNavigation; the chapter page's key-change focus now uses the orchestrator's scrollToLine/cancelScrollToLine. FileDiffList gains a focusedFilePath outline.
  • CLI simplification: the orchestrator's canToggleViewed gate stays at its default true — the CLI's viewed state is client-side and always writable (no server node-id gate).
  • Tests: ported the monorepo's file-focus-shortcuts test (16 cases).

Testing

  • pnpm typecheck
  • pnpm lint
  • pnpm test ✅ (web 105, incl. 16 new; the only red was pre-existing flaky-under-load timeouts in cli/git.test.ts, which pass 12/12 in isolation)
  • pnpm build

Open in Stage

Summary by cubic

Switches the CLI to explicit file focus navigation and adds file-level shortcuts for viewed and collapse. Files and chapter pages now share one navigator and show a focused-file outline.

  • New Features

    • Explicit focus via useCurrentFile, with a “file keyboard mode” that outlines the focused diff.
    • Shared useFileDiffNavigation wires j/k, v, ;, Shift+;, Esc and owns scroll-to-file/line for both files-page and chapter-detail-page.
    • v toggles file viewed and advances focus; chapter viewed is now Shift+V. file-header shows ShortcutTooltip and a collapse shortcut label.
    • FileDiffList accepts focusedFilePath and outlines the active diff.
  • Refactors

    • Removed use-active-file-on-scroll; rewrote use-file-navigation-keys to the focus signature (files, currentFilePath, onFocusFile, enabled).
    • Added hooks: use-file-viewed-key, use-file-collapse-keys, use-file-keyboard-mode-exit-key; updated keyboard-shortcuts with file/escape bindings.
    • Routes delegate to useFileDiffNavigation; chapter scrolling uses scrollToLine/cancelScrollToLine. CLI keeps viewed state writable, so v is always enabled.
    • Added file-focus-shortcuts test (16 cases). Typecheck, lint, tests, and build pass.

Written for commit 20c4ba6. Summary will update on new commits.

Review in cubic

…ortcuts

Syncs the CLI with the monorepo's keyboard-navigation overhaul that
landed after the fork:

- #943: replace scroll-derived "active file" with an explicit focused-file
  state machine (useCurrentFile) + a shared orchestrator (useFileDiffNavigation)
  that owns the diff-viewer ref and wires every file shortcut. Adds a
  "file keyboard mode" so keyboard focus shows an outline ring while
  click/scroll selection only highlights the picker row.
- #975: add v (mark file viewed + advance, pinning the marked file to top),
  ; / Shift+; (collapse file / all files), Esc (exit keyboard mode), and
  re-bind chapter-viewed from v to Shift+V (#910). file-header gains
  ShortcutTooltip hints on the viewed + collapse controls.

New hooks (vendored, imports adapted to @/lib/*): use-current-file,
use-file-viewed-key, use-file-collapse-keys, use-file-keyboard-mode-exit-key,
use-file-diff-navigation; use-file-navigation-keys rewritten to the focus
signature. The old scroll heuristic use-active-file-on-scroll is deleted.
Both routes now delegate to useFileDiffNavigation; FileDiffList gains a
focusedFilePath outline. Ported the monorepo's file-focus-shortcuts test
(16 cases).

CLI simplification: the canToggleViewed gate stays at its default (the CLI's
viewed state is client-side and always writable).

Typecheck, lint, web tests (105), and build all pass.
@stage-review
Copy link
Copy Markdown

stage-review Bot commented Jun 2, 2026

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Define new keyboard shortcut constants
2 Implement explicit file focus and navigation hooks
3 Orchestrate file diff navigation logic
4 Add unit tests for focus shortcuts
5 Update UI components for focus visualization
6 Integrate navigation into Chapter and Files pages
Open in Stage

Chapters generated by Stage for commit 20c4ba6 on Jun 2, 2026 4:53am UTC.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20c4ba6dfa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 60 to 61
if (scrollTo && !isLoading) {
diffListRef.current?.scrollToFile(scrollTo);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Synchronize focus when honoring scrollTo

When a user follows a prologue focus-area link into the Files tab (search.scrollTo), this effect only scrolls the diff list and never updates the new currentFilePath state. Because this commit removed scroll-derived active-file tracking, subsequent v/;/j/k shortcuts start from undefined and act on the first file instead of the file the route just brought into view. Select or focus scrollTo as part of handling this route-driven scroll.

Useful? React with 👍 / 👎.

Comment on lines +178 to +179
if (target) {
scrollToLine(target.filePath, target.side, target.startLine);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update current file for key-change jumps

Selecting a key change in the chapter side panel scrolls to target.filePath, but it does not update the explicit file-focus state introduced here. After that jump, the sidebar highlight and file shortcuts still refer to the previous file (or default to the first file), so pressing v or ; can toggle the wrong file even though the user is looking at the key-change target. The key-change scroll should also select/focus target.filePath.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 20c4ba6. Configure here.

diffListRef,
currentFilePath,
keyboardFocusedFilePath,
selectFile,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused selectFile returned from orchestrator hook

Low Severity

selectFile is returned from useFileDiffNavigation but no consumer ever destructures or uses it. Both files-page.tsx and chapter-detail-page.tsx only use handleSelectFile (which wraps selectFile internally). The raw selectFile export is dead code at the hook's public API boundary.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 20c4ba6. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant