Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions apps/web/src/terminal/ghostty/surface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isTerminalPasteShortcut,
loadTerminalFontFamily,
primeTerminalCopyInput,
resolveTerminalMouseData,
shouldBlinkTerminalCursor,
shouldReportTerminalMouse,
shouldShowTerminalLinkHover,
Expand Down Expand Up @@ -402,6 +403,22 @@ describe("application mouse reporting", () => {
expect([0, 1, 2, 3, 4, 5].map(ghosttyMouseButton)).toEqual([1, 3, 2, 4, 5, null]);
});

it("drops repeated motion reports until another mouse action resets the cell", () => {
const first = resolveTerminalMouseData("motion", "\u001b[<35;8;4M", "");
expect(first).toEqual({ send: true, nextMotionData: "\u001b[<35;8;4M" });

const duplicate = resolveTerminalMouseData("motion", "\u001b[<35;8;4M", first.nextMotionData);
expect(duplicate).toEqual({ send: false, nextMotionData: "\u001b[<35;8;4M" });

const press = resolveTerminalMouseData("press", "\u001b[<0;8;4M", duplicate.nextMotionData);
expect(press).toEqual({ send: true, nextMotionData: "" });

expect(resolveTerminalMouseData("motion", "\u001b[<35;8;4M", press.nextMotionData)).toEqual({
send: true,
nextMotionData: "\u001b[<35;8;4M",
});
});

it("only shows link hover during mouse tracking when the link modifier is held", () => {
expect(shouldShowTerminalLinkHover(false, false)).toBe(true);
expect(shouldShowTerminalLinkHover(false, true)).toBe(true);
Expand Down
26 changes: 20 additions & 6 deletions apps/web/src/terminal/ghostty/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ export function shouldReportTerminalMouse(
return tracking && !event.shiftKey && !event.ctrlKey && !event.metaKey;
}

type TerminalMouseAction = "press" | "release" | "motion";

export function resolveTerminalMouseData(
action: TerminalMouseAction,
data: string,
previousMotionData: string,
): { readonly send: boolean; readonly nextMotionData: string } {
const nextMotionData = action === "motion" ? data : "";
return {
send: data.length > 0 && (action !== "motion" || data !== previousMotionData),
nextMotionData,
};
}

export function terminalWheelDeltaRows(
event: Pick<WheelEvent, "deltaY" | "deltaMode">,
cellHeight: number,
Expand Down Expand Up @@ -593,6 +607,7 @@ export class GhosttyTerminalSurface {
private clearSelectionAfterCopy = false;
private primedCopySelection = "";
private wheelRemainder = 0;
private lastMouseMotionData = "";
Comment thread
cursor[bot] marked this conversation as resolved.
private dprMedia: MediaQueryList | null = null;
// Read live on every blink decision, and watched so that dropping the
// preference restarts a blink cycle that has no timer left to notice it.
Expand Down Expand Up @@ -1364,6 +1379,7 @@ export class GhosttyTerminalSurface {
}

private readonly onPointerLeave = () => {
this.lastMouseMotionData = "";
this.clearHoveredLink();
};

Expand Down Expand Up @@ -1822,11 +1838,7 @@ export class GhosttyTerminalSurface {
return terminalLinkAtPositionWithRange(this.snapshot.rowData, cell.y, cell.x);
}

private sendMouse(
action: "press" | "release" | "motion",
button: number | null,
event: MouseEvent,
): void {
private sendMouse(action: TerminalMouseAction, button: number | null, event: MouseEvent): void {
const bounds = this.canvas.getBoundingClientRect();
const data = this.core.encodeMouse({
action,
Expand All @@ -1848,7 +1860,9 @@ export class GhosttyTerminalSurface {
paddingBottom: Math.max(0, bounds.height - this.originY - this.rows * this.metrics.height),
anyButtonPressed: event.buttons !== 0,
});
if (data.length > 0) this.options.onData(data);
const resolution = resolveTerminalMouseData(action, data, this.lastMouseMotionData);
this.lastMouseMotionData = resolution.nextMotionData;
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
if (resolution.send) this.options.onData(data);
}

private buttonFromButtons(buttons: number): number | null {
Expand Down
Loading