Skip to content

Commit 40684b7

Browse files
StiensWoutclaude
andcommitted
fix(web): resume the cursor blink when reduced motion is turned off
A steady reduced-motion cursor leaves no blink timer running, so reading the media query at render time never saw the preference being dropped until unrelated output or a focus change forced a render. Watch the query and request a render on change, and drop the listener in dispose. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 98280a8 commit 40684b7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎apps/web/src/terminal/ghostty/surface.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ export class GhosttyTerminalSurface {
396396
private pasteShortcutToken = 0;
397397
private wheelRemainder = 0;
398398
private dprMedia: MediaQueryList | null = null;
399-
// Read live on every blink decision, so a preference change during a session
400-
// takes effect without a listener.
399+
// Read live on every blink decision, and watched so that dropping the
400+
// preference restarts a blink cycle that has no timer left to notice it.
401401
private readonly reducedMotionMedia = window.matchMedia?.("(prefers-reduced-motion: reduce)");
402402
private inputLeft = -1;
403403
private inputTop = -1;
@@ -428,6 +428,7 @@ export class GhosttyTerminalSurface {
428428
this.resizeObserver = new ResizeObserver(() => this.fit());
429429
this.installEvents();
430430
this.watchDevicePixelRatio();
431+
this.reducedMotionMedia?.addEventListener("change", this.onReducedMotionChange);
431432
document.fonts.addEventListener("loadingdone", this.onFontsLoaded);
432433
this.resizeObserver.observe(mount);
433434
}
@@ -556,6 +557,14 @@ export class GhosttyTerminalSurface {
556557
this.requestRender();
557558
}
558559

560+
private readonly onReducedMotionChange = () => {
561+
if (this.disposed) return;
562+
// Nothing else wakes an idle steady cursor: the blink timer only reschedules
563+
// from a render, and reduced motion is exactly the state that stopped it.
564+
this.cursorOn = true;
565+
this.requestRender();
566+
};
567+
559568
private readonly onFontsLoaded = () => {
560569
if (this.disposed) return;
561570
// A face that finished loading after the initial measurement changes glyph
@@ -698,6 +707,7 @@ export class GhosttyTerminalSurface {
698707
document.fonts.removeEventListener("loadingdone", this.onFontsLoaded);
699708
this.dprMedia?.removeEventListener("change", this.onDevicePixelRatioChange);
700709
this.dprMedia = null;
710+
this.reducedMotionMedia?.removeEventListener("change", this.onReducedMotionChange);
701711
if (this.selectionScrollTimer !== null) window.clearInterval(this.selectionScrollTimer);
702712
if (this.resizeNotifyTimer !== null) {
703713
window.clearTimeout(this.resizeNotifyTimer);

0 commit comments

Comments
 (0)