From cdce33b479688dd24b9416a507276ae587492091 Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Sat, 29 Aug 2026 09:39:31 +0800 Subject: [PATCH] Allow focused file navigation --- README.md | 2 +- src/review/component.ts | 9 +++++++-- test/review/component.test.ts | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 41df8a9..a3872c0 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Open one or more files or folders with `/view`: - `j/k` or arrow keys to move - `g/G` to jump to the top or bottom of the diff - `[/]` to jump to the previous or next file -- `f` to focus the current file, or clear file focus +- `f` to focus the current file, or clear file focus; use `[/]` to switch files while focused - `t` toggles the left file sidebar - `ctrl-u` / `ctrl-d` to move up/down by half a page - `s` toggles inline comments/explanations diff --git a/src/review/component.ts b/src/review/component.ts index 9f4ac97..2db325b 100644 --- a/src/review/component.ts +++ b/src/review/component.ts @@ -72,7 +72,7 @@ const HELP_COMMANDS = [ ["ctrl-u / ctrl-d", "move up or down half a page"], ["g / G", "jump to top or bottom"], ["[ / ]", "jump to previous or next file"], - ["f", "focus or unfocus the current file"], + ["f", "focus or unfocus the current file ([ / ] switches focus)"], ["n / p", "jump to next or previous hunk"], ["/", "search diff lines"], ["n / N", "jump between search matches"], @@ -1524,7 +1524,7 @@ export class ReviewComponent { } private jumpFile(direction: 1 | -1): void { - const files = this.getVisibleFileSections(); + const files = this.fileIndex.sections; if (files.length === 0) return; const current = this.getCurrentFileSection(); const currentIndex = current @@ -1538,6 +1538,11 @@ export class ReviewComponent { : files.length - 1; const next = files[nextIndex]; if (!next) return; + if (this.focusedFilePath && this.focusedFilePath !== next.filePath) { + this.focusedFilePath = next.filePath; + this.highlightedLineCache.clear(); + this.invalidateAnnotatedRows(); + } this.navigation.jumpToIndex(next.firstCommentableLineIndex); this.tui.requestRender(true); } diff --git a/test/review/component.test.ts b/test/review/component.test.ts index 57d1584..97d22cc 100644 --- a/test/review/component.test.ts +++ b/test/review/component.test.ts @@ -452,6 +452,27 @@ describe("ReviewComponent", () => { assert.equal((component as any).selected, 2); }); + it("switches the focused file with bracket keys", () => { + const component = createComponent(buildMultiFileLines()); + + (component as any).selected = 2; + component.handleInput("f"); + component.handleInput("t"); + component.handleInput("]"); + + assert.equal((component as any).selected, 5); + let output = component.render(100).join("\n"); + assert.doesNotMatch(output, /src\/a\.ts/); + assert.match(output, /src\/b\.ts/); + assert.match(output, /\[focused\]/); + + component.handleInput("["); + assert.equal((component as any).selected, 2); + output = component.render(100).join("\n"); + assert.match(output, /src\/a\.ts/); + assert.doesNotMatch(output, /src\/b\.ts/); + }); + it("renders a toggleable file sidebar with the current file highlighted", () => { const component = createComponent(buildMultiFileLines(), { theme: {