Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/review/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions test/review/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down