Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/frontend/terminal/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,12 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
}
return false;
}
if (wheelHasNothingToScroll(terminal.buffer.active)) {
if (
wheelHasNothingToScroll(
terminal.buffer.active,
terminal.modes.mouseTrackingMode,
)
) {
ev.preventDefault();
return false;
}
Expand Down
13 changes: 11 additions & 2 deletions src/frontend/terminal/terminal-wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ type WheelBuffer = { type: "normal" | "alternate"; baseY: number };
* A plain wheel on a normal buffer with nothing scrolled off yet. xterm turns
* that into an arrow key, which walks shell history, so it is dropped. The
* alternate screen keeps the arrow keys: that is how less and vim scroll.
* When the app has mouse reporting on, xterm sends the wheel to the app
* instead (tmux attached on the normal screen does this), so it is kept.
*/
export function wheelHasNothingToScroll(buffer: WheelBuffer): boolean {
return buffer.type === "normal" && buffer.baseY === 0;
export function wheelHasNothingToScroll(
buffer: WheelBuffer,
mouseTrackingMode: string,
): boolean {
return (
mouseTrackingMode === "none" &&
buffer.type === "normal" &&
buffer.baseY === 0
);
}

/** Pixels per scrolled line, the same step xterm uses for one wheel line. */
Expand Down
22 changes: 17 additions & 5 deletions tests/frontend/terminal/terminal-wheel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@ describe("terminalWheelAction", () => {

describe("wheelHasNothingToScroll", () => {
it("drops the wheel on a normal buffer with no scrollback yet", () => {
expect(wheelHasNothingToScroll({ type: "normal", baseY: 0 })).toBe(true);
expect(wheelHasNothingToScroll({ type: "normal", baseY: 12 })).toBe(false);
expect(wheelHasNothingToScroll({ type: "normal", baseY: 0 }, "none")).toBe(
true,
);
expect(wheelHasNothingToScroll({ type: "normal", baseY: 12 }, "none")).toBe(
false,
);
});

it("leaves the alternate screen alone so less and vim still scroll", () => {
expect(wheelHasNothingToScroll({ type: "alternate", baseY: 0 })).toBe(
false,
);
expect(
wheelHasNothingToScroll({ type: "alternate", baseY: 0 }, "none"),
).toBe(false);
});

it("keeps the wheel when the app reports the mouse (tmux on the normal screen)", () => {
for (const mode of ["x10", "vt200", "drag", "any"]) {
expect(wheelHasNothingToScroll({ type: "normal", baseY: 0 }, mode)).toBe(
false,
);
}
});
});

Expand Down