From baa0171d8a4950e0bc7fac93c0454a2c6bd5404b Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Thu, 26 Nov 2026 01:42:42 +0800 Subject: [PATCH] feat(appearance): add a Reduce motion setting (#5940) Adds Reduce motion under Appearance > Accessibility. When on, or when the system asks for reduced motion, CSS animations and transitions finish at once; script-driven motion reads the same preference. Fixes #5887 --- crates/ide-core/src/settings.rs | 3 +++ src/bindings.ts | 4 +++ src/features/agents/session/ContextMeter.tsx | 3 ++- src/features/agents/session/SessionStatus.tsx | 3 ++- src/features/settings/appearanceRuntime.ts | 1 + src/features/settings/model/behaviorSchema.ts | 3 +++ src/features/settings/pages/behavior.tsx | 6 +++++ src/features/vcs/DiffEditor.tsx | 3 ++- src/features/viewers/markdown/splitScroll.ts | 6 ++--- src/platform/locales/text/es.json | 2 ++ src/platform/locales/text/fr.json | 2 ++ src/platform/locales/text/ko.json | 2 ++ src/platform/locales/text/pl.json | 2 ++ src/platform/locales/text/pt.json | 2 ++ src/platform/locales/text/ru.json | 2 ++ src/platform/locales/text/tr.json | 2 ++ src/platform/locales/text/zh-TW.json | 2 ++ src/platform/locales/text/zh.json | 2 ++ src/platform/motion.test.ts | 23 ++++++++++++++++ src/platform/motion.ts | 9 +++++++ src/styles/global.css | 27 +++++++++++++++++++ 21 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 src/platform/motion.test.ts create mode 100644 src/platform/motion.ts diff --git a/crates/ide-core/src/settings.rs b/crates/ide-core/src/settings.rs index d887a09e84..633e854aff 100644 --- a/crates/ide-core/src/settings.rs +++ b/crates/ide-core/src/settings.rs @@ -823,6 +823,8 @@ pub struct AppearanceSettings { pub contrast_scrollbars: bool, /// Adjust colours for red-green vision deficiency. pub red_green_vision: bool, + /// Turn off animations and transitions (also on when the OS asks for reduced motion). + pub reduce_motion: bool, pub different_tool_window_background: bool, pub compact_mode: bool, /// IDEA "Use smaller indents in trees": tool window trees indent less per level. @@ -963,6 +965,7 @@ impl Default for AppearanceSettings { ui_font_fallback: String::new(), contrast_scrollbars: false, red_green_vision: false, + reduce_motion: false, different_tool_window_background: false, compact_mode: false, small_tree_indents: false, diff --git a/src/bindings.ts b/src/bindings.ts index 1758430c86..f728f26e6c 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -3508,6 +3508,8 @@ export type AppearanceSettings_Deserialize = { contrastScrollbars?: boolean, /** Adjust colours for red-green vision deficiency. */ redGreenVision?: boolean, + /** Turn off animations and transitions (also on when the OS asks for reduced motion). */ + reduceMotion?: boolean, differentToolWindowBackground?: boolean, compactMode?: boolean, /** IDEA "Use smaller indents in trees": tool window trees indent less per level. */ @@ -3583,6 +3585,8 @@ export type AppearanceSettings_Serialize = { contrastScrollbars: boolean, /** Adjust colours for red-green vision deficiency. */ redGreenVision: boolean, + /** Turn off animations and transitions (also on when the OS asks for reduced motion). */ + reduceMotion: boolean, differentToolWindowBackground: boolean, compactMode: boolean, /** IDEA "Use smaller indents in trees": tool window trees indent less per level. */ diff --git a/src/features/agents/session/ContextMeter.tsx b/src/features/agents/session/ContextMeter.tsx index 10d7e13842..8263099ef9 100644 --- a/src/features/agents/session/ContextMeter.tsx +++ b/src/features/agents/session/ContextMeter.tsx @@ -3,6 +3,7 @@ import clsx from "clsx"; import type { AgentContextUsage, AgentTask, AgentUsage } from "@/bindings"; import { call, commands } from "@/platform/ipc"; import { useTx } from "@/platform/i18n"; +import { reducedMotion } from "@/platform/motion"; import { Button, Popup, T, tooltipAttrs } from "@/ui"; import { meterTone, usageLabel } from "../composerModel"; import { isBusy } from "../model"; @@ -35,7 +36,7 @@ export function ContextMeter({ task, usage }: { task: AgentTask; usage: AgentUsa const anchor = useRef(null); const [phase, setPhase] = useState<"closed" | "open" | "closing">("closed"); const open = phase === "open"; - const close = () => setPhase(window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "closed" : "closing"); + const close = () => setPhase(reducedMotion() ? "closed" : "closing"); useEffect(() => { if (phase !== "closing") return; const timer = window.setTimeout(() => setPhase("closed"), 100); diff --git a/src/features/agents/session/SessionStatus.tsx b/src/features/agents/session/SessionStatus.tsx index 2e56ff5aa9..3145d01c37 100644 --- a/src/features/agents/session/SessionStatus.tsx +++ b/src/features/agents/session/SessionStatus.tsx @@ -2,6 +2,7 @@ import { Fragment, useEffect, useRef, useState, type ReactNode } from "react"; import type { AgentChange, AgentCommit, AgentLimit, AgentTask } from "@/bindings"; import { executeAction } from "@/platform/actions"; import { useTx } from "@/platform/i18n"; +import { reducedMotion } from "@/platform/motion"; import { basename, useProject } from "@/platform/project"; import clsx from "clsx"; import { Icon, IconButton, Popup, showContextMenu, T, tooltipAttrs } from "@/ui"; @@ -222,7 +223,7 @@ function LimitsMeter({ limits, now }: { limits: readonly AgentLimit[]; now: numb const anchor = useRef(null); const [phase, setPhase] = useState<"closed" | "open" | "closing">("closed"); const open = phase === "open"; - const close = () => setPhase(window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "closed" : "closing"); + const close = () => setPhase(reducedMotion() ? "closed" : "closing"); useEffect(() => { if (phase !== "closing") return; const timer = window.setTimeout(() => setPhase("closed"), 100); diff --git a/src/features/settings/appearanceRuntime.ts b/src/features/settings/appearanceRuntime.ts index 16d4497b0b..e8c03500f6 100644 --- a/src/features/settings/appearanceRuntime.ts +++ b/src/features/settings/appearanceRuntime.ts @@ -49,6 +49,7 @@ export function applyAppearanceOptions(s: ValidSettings, root: HTMLElement = doc setCompactMode(a.compactMode); flag(root, "contrastScrollbars", a.contrastScrollbars); flag(root, "redGreen", a.redGreenVision); + flag(root, "reduceMotion", a.reduceMotion); flag(root, "toolWindowBg", a.differentToolWindowBackground, "different"); flag(root, "projectColors", !a.projectColorsInToolbar, "off"); flag(root, "menuIcons", !a.menuIcons, "off"); diff --git a/src/features/settings/model/behaviorSchema.ts b/src/features/settings/model/behaviorSchema.ts index 8b28783258..1dc4cdec6f 100644 --- a/src/features/settings/model/behaviorSchema.ts +++ b/src/features/settings/model/behaviorSchema.ts @@ -72,6 +72,7 @@ export interface AppearanceExtras { uiFontFallback: string; contrastScrollbars: boolean; redGreenVision: boolean; + reduceMotion: boolean; differentToolWindowBackground: boolean; compactMode: boolean; /** IDEA "Use smaller indents in trees": tool window trees indent less per level. */ @@ -161,6 +162,7 @@ export const DEFAULT_APPEARANCE_EXTRAS: AppearanceExtras = { uiFontFallback: "", contrastScrollbars: false, redGreenVision: false, + reduceMotion: false, differentToolWindowBackground: false, compactMode: false, smallTreeIndents: false, @@ -246,6 +248,7 @@ export function validateAppearanceExtras(raw: unknown): AppearanceExtras { uiFontFallback: typeof a.uiFontFallback === "string" ? a.uiFontFallback.trim() : d.uiFontFallback, contrastScrollbars: b("contrastScrollbars"), redGreenVision: b("redGreenVision"), + reduceMotion: b("reduceMotion"), differentToolWindowBackground: b("differentToolWindowBackground"), compactMode: b("compactMode"), smallTreeIndents: b("smallTreeIndents"), diff --git a/src/features/settings/pages/behavior.tsx b/src/features/settings/pages/behavior.tsx index fec1e5b66a..658b68fcdf 100644 --- a/src/features/settings/pages/behavior.tsx +++ b/src/features/settings/pages/behavior.tsx @@ -964,6 +964,12 @@ export const BEHAVIOR_PAGES: PageSpec[] = [ label: "Adjust colors for red-green vision deficiency", hint: "For protanopia and deuteranopia.", }, + { + kind: "toggle", + key: "appearance.reduceMotion", + label: "Reduce motion", + hint: "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.", + }, ], }, { diff --git a/src/features/vcs/DiffEditor.tsx b/src/features/vcs/DiffEditor.tsx index 7c7a80cbab..d70bbf3ec3 100644 --- a/src/features/vcs/DiffEditor.tsx +++ b/src/features/vcs/DiffEditor.tsx @@ -39,6 +39,7 @@ import { auxiliaryWindow } from "@/platform/auxWindow"; import { getContext, setContext } from "@/platform/context"; import { editorPrefs } from "@/platform/editorSettings"; import { call, commands } from "@/platform/ipc"; +import { reducedMotion } from "@/platform/motion"; import { bindingsFor, normalizeBinding, shortcutLabel, strokeOf } from "@/platform/keymap"; import { tx } from "@/platform/i18n"; import { useProject } from "@/platform/project"; @@ -1278,7 +1279,7 @@ function TwoPaneDiff({ write: (top) => { const options: ScrollToOptions = { top: Math.max(0, top), - behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth", + behavior: reducedMotion() ? "instant" : "smooth", }; if (views.panes) views.panes.scrollTo(onA ? "a" : "b", options); else scroller.scrollTo(options); diff --git a/src/features/viewers/markdown/splitScroll.ts b/src/features/viewers/markdown/splitScroll.ts index 5933d7a72b..2f77b09a47 100644 --- a/src/features/viewers/markdown/splitScroll.ts +++ b/src/features/viewers/markdown/splitScroll.ts @@ -1,3 +1,4 @@ +import { reducedMotion } from "@/platform/motion"; import { useLiveMarkdown } from "./live"; /** Keep one follower per split. A new editor position retargets the frame already in flight. */ @@ -6,7 +7,6 @@ export function followMarkdownSource(path: string, root: HTMLElement, offsetForL let lastTime = 0; let position = root.scrollTop; let applied = position; - const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)"); const target = () => { const state = useLiveMarkdown.getState()[path]; const max = Math.max(0, root.scrollHeight - root.clientHeight); @@ -27,7 +27,7 @@ export function followMarkdownSource(path: string, root: HTMLElement, offsetForL const elapsed = Math.max(0, Math.min(time - lastTime, 100)); lastTime = time; position += (destination - position) * -Math.expm1(-elapsed / 40); - if (Math.abs(position - destination) < 0.5 || reducedMotion?.matches) { + if (Math.abs(position - destination) < 0.5 || reducedMotion()) { root.scrollTop = destination; return; } @@ -39,7 +39,7 @@ export function followMarkdownSource(path: string, root: HTMLElement, offsetForL const a = next[path], b = prev[path]; if (!a || (a.topLine === b?.topLine && a.scrollSeq === b?.scrollSeq && a.sourceAtEnd === b?.sourceAtEnd)) return; - if (reducedMotion?.matches) return align(); + if (reducedMotion()) return align(); if (frame) return; applied = position = root.scrollTop; lastTime = performance.now(); diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index 7ab5117ccc..8425d47798 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -904,6 +904,8 @@ "Font": "Fuente", "Font preview": "Vista previa de la fuente", "For protanopia and deuteranopia.": "Para protanopía y deuteranopía.", + "Reduce motion": "Reducir movimiento", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Desactiva animaciones y transiciones, como los indicadores giratorios y los fundidos de ventanas emergentes. Siempre activo cuando el sistema solicita reducir el movimiento.", "For symbols not supported by the main font": "Para símbolos no admitidos por la fuente principal", "Force": "Forzar", "Force (with lease)": "Forzar (con lease)", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index 98210a5c3a..157f394507 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -841,6 +841,8 @@ "Font": "Police", "Font preview": "Aperçu de la police", "For protanopia and deuteranopia.": "Pour la protanopie et la deutéranopie.", + "Reduce motion": "Réduire les animations", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Désactive les animations et transitions, comme les indicateurs de chargement et les fondus des fenêtres contextuelles. Toujours actif lorsque le système demande de réduire les animations.", "For symbols not supported by the main font": "Pour les symboles non pris en charge par la police principale", "Force": "Forcer", "Force (with lease)": "Forcer (with lease)", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index eacd6fed0c..06f5967d04 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -940,6 +940,8 @@ "Font": "글꼴", "Font preview": "글꼴 미리 보기", "For protanopia and deuteranopia.": "적색맹 및 녹색맹용입니다.", + "Reduce motion": "동작 줄이기", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "로딩 스피너와 팝업 페이드 같은 애니메이션과 전환 효과를 끕니다. 시스템에서 동작 줄이기를 요청하면 항상 켜집니다.", "For symbols not supported by the main font": "기본 글꼴에서 지원하지 않는 기호용", "Force": "강제 실행", "Force (with lease)": "강제(with lease)", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index 2ac8e4c7c4..2c7dc34847 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -896,6 +896,8 @@ "Font": "Czcionka", "Font preview": "Podgląd czcionki", "For protanopia and deuteranopia.": "Dla protanopii i deuteranopii.", + "Reduce motion": "Ogranicz ruch", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Wyłącza animacje i przejścia, takie jak wskaźniki ładowania i zanikanie okien podręcznych. Zawsze włączone, gdy system prosi o ograniczenie ruchu.", "For symbols not supported by the main font": "Dla symboli nieobsługiwanych przez czcionkę główną", "Force": "Wymuś", "Force (with lease)": "Wymuś (z ograniczeniem/with lease)", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index b7d57e0ee9..84eff208c5 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -896,6 +896,8 @@ "Font": "Fonte", "Font preview": "Pré-visualização da fonte", "For protanopia and deuteranopia.": "Para protanopia e deuteranopia.", + "Reduce motion": "Reduzir movimento", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Desativa animações e transições, como indicadores de carregamento e esmaecimento de pop-ups. Sempre ativo quando o sistema solicita movimento reduzido.", "For symbols not supported by the main font": "Para símbolos não suportados pela fonte principal", "Force": "Forçar", "Force (with lease)": "Forçar (com lease)", diff --git a/src/platform/locales/text/ru.json b/src/platform/locales/text/ru.json index d5937b523a..ef0c681581 100644 --- a/src/platform/locales/text/ru.json +++ b/src/platform/locales/text/ru.json @@ -1960,6 +1960,8 @@ "Font": "Шрифт", "Font preview": "Предпросмотр шрифта", "For protanopia and deuteranopia.": "Для протанопии и дейтеранопии.", + "Reduce motion": "Уменьшить движение", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Отключает анимации и переходы, например индикаторы загрузки и плавное появление всплывающих окон. Всегда включено, если система запрашивает уменьшение движения.", "For symbols not supported by the main font": "Для символов, не поддерживаемых основным шрифтом", "Force": "Принудительно", "Force (with lease)": "Принудительно (with lease)", diff --git a/src/platform/locales/text/tr.json b/src/platform/locales/text/tr.json index 7169870b73..19755d1d4b 100644 --- a/src/platform/locales/text/tr.json +++ b/src/platform/locales/text/tr.json @@ -3692,6 +3692,8 @@ "Font": "Yazı Tipi", "Font preview": "Yazı tipi önizlemesi", "For protanopia and deuteranopia.": "Protanopi ve döteranopi için.", + "Reduce motion": "Hareketi azalt", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "Yükleme göstergeleri ve açılır pencere geçişleri gibi animasyonları ve geçişleri kapatır. Sistem hareketin azaltılmasını istediğinde her zaman açıktır.", "For symbols not supported by the main font": "Ana yazı tipinin desteklemediği semboller için", "Force": "Zorla", "Force (with lease)": "Zorla (lease ile)", diff --git a/src/platform/locales/text/zh-TW.json b/src/platform/locales/text/zh-TW.json index dd66b604c6..d5dee0cc55 100644 --- a/src/platform/locales/text/zh-TW.json +++ b/src/platform/locales/text/zh-TW.json @@ -1573,6 +1573,8 @@ "Font": "字型", "Font preview": "字型預覽", "For protanopia and deuteranopia.": "適用於紅色盲和綠色盲。", + "Reduce motion": "減少動態效果", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "關閉動畫和轉場效果,例如載入旋轉圖示和彈出視窗淡入淡出。系統要求減少動態效果時一律開啟。", "For symbols not supported by the main font": "用於主字型不支援的符號", "Force": "強制", "Force (with lease)": "強制 (with lease)", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 89248dd45c..ff957519f5 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1985,6 +1985,8 @@ "Font": "字体", "Font preview": "字体预览", "For protanopia and deuteranopia.": "适用于红色盲和绿色盲。", + "Reduce motion": "减少动画", + "Turns off animations and transitions, such as spinners and popup fades. Always on when the system asks for reduced motion.": "关闭动画和过渡效果,例如加载旋转图标和弹出层淡入淡出。系统要求减少动态效果时始终开启。", "For symbols not supported by the main font": "用于主字体不支持的符号", "Force": "强制", "Force (with lease)": "强制 (with lease)", diff --git a/src/platform/motion.test.ts b/src/platform/motion.test.ts new file mode 100644 index 0000000000..5c3bf5a085 --- /dev/null +++ b/src/platform/motion.test.ts @@ -0,0 +1,23 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { reducedMotion } from "./motion"; + +describe("reducedMotion", () => { + afterEach(() => { + delete document.documentElement.dataset.reduceMotion; + vi.unstubAllGlobals(); + }); + const media = (matches: boolean) => + vi.stubGlobal("matchMedia", (query: string) => ({ matches: matches && query.includes("reduce") })); + + it("follows the Reduce motion setting", () => { + media(false); + expect(reducedMotion()).toBe(false); + document.documentElement.dataset.reduceMotion = ""; + expect(reducedMotion()).toBe(true); + }); + + it("follows the system preference when the setting is off", () => { + media(true); + expect(reducedMotion()).toBe(true); + }); +}); diff --git a/src/platform/motion.ts b/src/platform/motion.ts new file mode 100644 index 0000000000..050cf21589 --- /dev/null +++ b/src/platform/motion.ts @@ -0,0 +1,9 @@ +/** + * Whether motion should be reduced: Settings › Appearance › Reduce motion (the `data-reduce-motion` + * root attribute) or the system's reduced-motion preference. For script-driven animation; CSS + * reads the attribute and the media query itself. + */ +export function reducedMotion(): boolean { + if (typeof document !== "undefined" && document.documentElement.dataset.reduceMotion !== undefined) return true; + return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches; +} diff --git a/src/styles/global.css b/src/styles/global.css index 3965281b77..d254f07c3b 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -20,6 +20,33 @@ box-sizing: border-box; } +/* Appearance › Reduce motion, or the system's reduced-motion preference: animations jump to their + end state and transitions apply at once, so spinners stand still and popups appear without a + fade. Animation events still fire. */ +:root[data-reduce-motion] *, +:root[data-reduce-motion] *::before, +:root[data-reduce-motion] *::after { + animation-duration: 0.01ms !important; + animation-delay: 0s !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + transition-delay: 0s !important; + scroll-behavior: auto !important; +} + +@media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + animation-duration: 0.01ms !important; + animation-delay: 0s !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + transition-delay: 0s !important; + scroll-behavior: auto !important; + } +} + html, body, #root {