дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
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
Цей коміт міститься в:
1 джерело
0d493fb515
коміт
baa0171d8a
21 files changed
+103
-6
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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<HTMLButtonElement>(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);
|
||||
|
||||
@@ -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<HTMLButtonElement>(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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Заблокувати користувача