Skip to content

Commit 8126b12

Browse files
authored
Add navigation shortcuts from issue #101 (#102)
- d / u: scroll half page down / up (less/git diff convention) - f: alternative page down (less convention, like Space) - Shift+Space: page up (standard pager behavior) These shortcuts work in both normal and pager modes, matching muscle memory from less, git diff, man pages, and other pagers. Updated help dialog to document the new shortcuts. Fixes #101
1 parent e01d605 commit 8126b12

2 files changed

Lines changed: 55 additions & 5 deletions

File tree

src/ui/App.tsx

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,23 @@ function AppShell({
285285
};
286286

287287
/** Scroll the main review pane by line steps, viewport fractions, or whole-content jumps. */
288-
const scrollDiff = (delta: number, unit: "step" | "viewport" | "content" = "viewport") => {
288+
const scrollDiff = (
289+
delta: number,
290+
unit: "step" | "viewport" | "content" | "half" = "viewport",
291+
) => {
292+
if (unit === "half") {
293+
const scrollBox = diffScrollRef.current;
294+
if (!scrollBox) return;
295+
296+
// Calculate half the viewport height
297+
const viewportHeight = scrollBox.viewport?.height ?? 20;
298+
const scrollAmount = Math.floor(viewportHeight / 2);
299+
300+
// Use scrollTo with current position + delta * amount
301+
const currentScroll = scrollBox.scrollTop;
302+
scrollBox.scrollTo(currentScroll + delta * scrollAmount);
303+
return;
304+
}
289305
diffScrollRef.current?.scrollBy(delta, unit);
290306
};
291307

@@ -571,11 +587,22 @@ function AppShell({
571587

572588
useKeyboard((key: KeyEvent) => {
573589
const pageDownKey =
574-
key.name === "pagedown" || key.name === "space" || key.name === " " || key.sequence === " ";
590+
key.name === "pagedown" ||
591+
key.name === "space" ||
592+
key.name === " " ||
593+
key.sequence === " " ||
594+
key.name === "f" ||
595+
key.sequence === "f";
575596
const pageUpKey = key.name === "pageup" || key.name === "b" || key.sequence === "b";
576597
const stepDownKey = key.name === "down" || key.name === "j" || key.sequence === "j";
577598
const stepUpKey = key.name === "up" || key.name === "k" || key.sequence === "k";
578599

600+
// New shortcuts from issue #101 - using less/git diff conventions
601+
const halfPageDownKey = key.name === "d" || key.sequence === "d";
602+
const halfPageUpKey = key.name === "u" || key.sequence === "u";
603+
const shiftSpacePageUpKey =
604+
key.shift && (key.name === "space" || key.name === " " || key.sequence === " ");
605+
579606
if (key.name === "f10") {
580607
if (pagerMode) {
581608
return;
@@ -600,11 +627,21 @@ function AppShell({
600627
return;
601628
}
602629

603-
if (pageUpKey) {
630+
if (pageUpKey || shiftSpacePageUpKey) {
604631
scrollDiff(-1, "viewport");
605632
return;
606633
}
607634

635+
if (halfPageDownKey) {
636+
scrollDiff(1, "half");
637+
return;
638+
}
639+
640+
if (halfPageUpKey) {
641+
scrollDiff(-1, "half");
642+
return;
643+
}
644+
608645
if (stepDownKey) {
609646
scrollDiff(1, "step");
610647
return;
@@ -716,11 +753,21 @@ function AppShell({
716753
return;
717754
}
718755

719-
if (pageUpKey) {
756+
if (pageUpKey || shiftSpacePageUpKey) {
720757
scrollDiff(-1, "viewport");
721758
return;
722759
}
723760

761+
if (halfPageDownKey) {
762+
scrollDiff(1, "half");
763+
return;
764+
}
765+
766+
if (halfPageUpKey) {
767+
scrollDiff(-1, "half");
768+
return;
769+
}
770+
724771
if (key.name === "home") {
725772
scrollDiff(-1, "content");
726773
return;

src/ui/components/chrome/HelpDialog.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export function HelpDialog({
2121
title: "Navigation",
2222
items: [
2323
["↑ / ↓", "move line-by-line"],
24-
["Space / b", "page down / page up"],
24+
["Space / f", "page down (alt: f)"],
25+
["b", "page up"],
26+
["Shift+Space", "page up (alt)"],
27+
["d / u", "half page down / up"],
2528
["[ / ]", "previous / next hunk"],
2629
["Home / End", "jump to top / bottom"],
2730
],

0 commit comments

Comments
 (0)