Skip to content

Commit 0a2a4f8

Browse files
committed
fix: page by a full viewport
1 parent 0676315 commit 0a2a4f8

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

src/ui/App.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ export function App({ bootstrap, onQuit = () => process.exit(0) }: { bootstrap:
509509
}
510510

511511
if (pageDownKey) {
512-
scrollDiff(1 / 2, "viewport");
512+
scrollDiff(1, "viewport");
513513
return;
514514
}
515515

516516
if (pageUpKey) {
517-
scrollDiff(-1 / 2, "viewport");
517+
scrollDiff(-1, "viewport");
518518
return;
519519
}
520520

@@ -625,12 +625,12 @@ export function App({ bootstrap, onQuit = () => process.exit(0) }: { bootstrap:
625625
}
626626

627627
if (pageDownKey) {
628-
scrollDiff(1 / 2, "viewport");
628+
scrollDiff(1, "viewport");
629629
return;
630630
}
631631

632632
if (pageUpKey) {
633-
scrollDiff(-1 / 2, "viewport");
633+
scrollDiff(-1, "viewport");
634634
return;
635635
}
636636

test/tty-render-smoke.test.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function stripTerminalControl(text: string) {
3333
.replace(/\x1b[@-_]/g, "");
3434
}
3535

36-
function createFixtureFiles() {
36+
function createFixtureFiles(lines = 1) {
3737
const dir = mkdtempSync(join(tmpdir(), "hunk-tty-smoke-"));
3838
tempDirs.push(dir);
3939

@@ -43,8 +43,21 @@ function createFixtureFiles() {
4343
const patch = join(dir, "input.patch");
4444
const coloredPatch = join(dir, "input-colored.patch");
4545

46-
writeFileSync(before, "export const answer = 41;\n");
47-
writeFileSync(after, "export const answer = 42;\nexport const added = true;\n");
46+
if (lines <= 1) {
47+
writeFileSync(before, "export const answer = 41;\n");
48+
writeFileSync(after, "export const answer = 42;\nexport const added = true;\n");
49+
} else {
50+
writeFileSync(
51+
before,
52+
Array.from({ length: lines }, (_, index) => `export const before_${String(index + 1).padStart(2, "0")} = ${index + 1};`).join("\n") +
53+
"\n",
54+
);
55+
writeFileSync(
56+
after,
57+
Array.from({ length: lines }, (_, index) => `export const after_${String(index + 1).padStart(2, "0")} = ${index + 101};`).join("\n") +
58+
"\n",
59+
);
60+
}
4861
writeFileSync(
4962
agent,
5063
JSON.stringify({
@@ -124,12 +137,13 @@ async function runTtySmoke(options: { mode?: "split" | "stack"; pager?: boolean;
124137
return stripTerminalControl(await Bun.file(transcript).text());
125138
}
126139

127-
async function runStdinPagerSmoke() {
128-
const fixture = createFixtureFiles();
140+
async function runStdinPagerSmoke(options?: { input?: string; inputCommand?: string; lines?: number }) {
141+
const fixture = createFixtureFiles(options?.lines ?? 1);
129142
const transcript = join(fixture.dir, "stdin-pager-transcript.txt");
130143
const patchCommand = `cat ${shellQuote(fixture.coloredPatch)} | bun run src/main.tsx patch -`;
131144
const scriptCommand = `timeout 5 script -q -f -e -c ${shellQuote(patchCommand)} ${shellQuote(transcript)}`;
132-
const proc = Bun.spawnSync(["bash", "-lc", `(sleep 1; printf q) | ${scriptCommand}`], {
145+
const inputCommand = options?.inputCommand ?? `(sleep 1; printf ${shellQuote(options?.input ?? "q")})`;
146+
const proc = Bun.spawnSync(["bash", "-lc", `${inputCommand} | ${scriptCommand}`], {
133147
cwd: process.cwd(),
134148
stdin: "ignore",
135149
stdout: "pipe",
@@ -207,4 +221,18 @@ describe("TTY render smoke", () => {
207221
expect(output).toContain("@@ -1 +1,2 @@");
208222
expect(output).toContain("export const answer = 42;");
209223
});
224+
225+
test("stdin pager mode pages forward by a full viewport on space", async () => {
226+
if (!ttyToolsAvailable) {
227+
return;
228+
}
229+
230+
const output = await runStdinPagerSmoke({
231+
lines: 40,
232+
inputCommand: `(sleep 1; printf ' '; sleep 1; printf q)`,
233+
});
234+
235+
expect(output).toContain("before_23");
236+
expect(output).toContain("after_06");
237+
});
210238
});

0 commit comments

Comments
 (0)