Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(settings): position search before paint and leave plugin pages
vastsa07b91749fc4e
diff --git a/apps/desktop/src/features/settings/SettingsPage.tsx b/apps/desktop/src/features/settings/SettingsPage.tsxindex 055ec8f8f..2c4257373 100644--- a/apps/desktop/src/features/settings/SettingsPage.tsx+++ b/apps/desktop/src/features/settings/SettingsPage.tsx@@ -79,6 +79,7 @@ export function SettingsPage() {const tab = useAppStore((s) => s.settingsTab);const setSettingsTab = useAppStore((s) => s.setSettingsTab);const settingsAnchor = useAppStore((s) => s.settingsAnchor);+ const settingsTabNonce = useAppStore((s) => s.settingsTabNonce);const setSettingsAnchor = useAppStore((s) => s.setSettingsAnchor);const setPage = useAppStore((s) => s.setPage);const settings = useAppStore((s) => s.settings);@@ -97,6 +98,17 @@ export function SettingsPage() {const [settingsRecoveryFailed, setSettingsRecoveryFailed] = useState(false);const [extensions, setExtensions] = useState<PluginScenicThemesDestinationMeta[]>([]);const [activeExtension, setActiveExtension] = useState<PluginScenicThemesDestinationMeta | null>(null);+ const seenSettingsTabNonce = useRef(settingsTabNonce);+ // setSettingsTab means "show this built-in category", even when the tab id+ // does not change. Dismiss a plugin page before paint; an anchor-only deep+ // link has to do the same or the row lookup hits the plugin instead.+ if (+ seenSettingsTabNonce.current !== settingsTabNonce ||+ (activeExtension && settingsAnchor)+ ) {+ seenSettingsTabNonce.current = settingsTabNonce;+ if (activeExtension) setActiveExtension(null);+ }const contentRef = useRef<HTMLDivElement>(null);const destination = activeExtension ? `extension:${activeExtension.ref}` : `builtin:${tab}`;@@ -145,10 +157,12 @@ export function SettingsPage() {}, [settings, recoverSettings]);// Arriving from the global search dialog: scroll to and flash the row- // whose title matches the pending anchor key. Rows are located by their- // translated title so async tab content (providers, import) needs no- // per-row wiring; a short retry window covers late mounts.- useEffect(() => {+ // whose title matches the pending anchor key. This runs after the+ // destination reset and before paint, so a category change does not flash+ // the top. Rows are located by their translated title so async tab content+ // (providers, import) needs no per-row wiring; a short retry window covers+ // late mounts.+ useLayoutEffect(() => {if (!settingsAnchor) return;const target = t(settingsAnchor).trim();let cancelled = false;diff --git a/apps/desktop/src/stores/app-state.ts b/apps/desktop/src/stores/app-state.tsindex 093175da1..3cf9e08e0 100644--- a/apps/desktop/src/stores/app-state.ts+++ b/apps/desktop/src/stores/app-state.ts@@ -175,6 +175,8 @@ export type AppState = {settingsTab: SettingsTabId;/** Pending row anchor (i18n key) to flash after landing on a settings tab. */settingsAnchor: string | null;+ /** Bumped by every setSettingsTab so a same-tab navigation is observable. */+ settingsTabNonce: number;navStack: Array<{ page: AppState["page"]; sessionId?: string }>;navIndex: number;error?: string | null;diff --git a/apps/desktop/src/stores/slices/initial-state.ts b/apps/desktop/src/stores/slices/initial-state.tsindex bd1f40d95..998f3eeb5 100644--- a/apps/desktop/src/stores/slices/initial-state.ts+++ b/apps/desktop/src/stores/slices/initial-state.ts@@ -75,6 +75,7 @@ export function createInitialState(): AppStateData {page: "chat",settingsTab: "general",settingsAnchor: null,+ settingsTabNonce: 0,navStack: [{ page: "chat" }],navIndex: 0,toasts: [],diff --git a/apps/desktop/src/stores/slices/interaction-slice.ts b/apps/desktop/src/stores/slices/interaction-slice.tsindex 20be24ac0..bf22605c4 100644--- a/apps/desktop/src/stores/slices/interaction-slice.ts+++ b/apps/desktop/src/stores/slices/interaction-slice.ts@@ -72,7 +72,10 @@ export function createInteractionSlice({setSettingsTab: (settingsTab) => {get().setPage("settings");- set({ settingsTab });+ set((state) => ({+ settingsTab,+ settingsTabNonce: state.settingsTabNonce + 1,+ }));},setSettingsAnchor: (settingsAnchor) => set({ settingsAnchor }),canNavBack: () => get().navIndex > 0,diff --git a/docs/spec/04-ux/06-settings-ia.md b/docs/spec/04-ux/06-settings-ia.mdindex 2998bfec0..1881f14ac 100644--- a/docs/spec/04-ux/06-settings-ia.md+++ b/docs/spec/04-ux/06-settings-ia.md@@ -7,8 +7,9 @@ Settings is a **full-window page** that replaces the app sidebar + main chrome (- Switching to a different Settings destination starts the content pane at thetop, including plugin destinations. Re-selecting the current destination orupdating settings in place preserves the current scroll position. Global- search deep links still scroll to their target row after the destination- changes; consuming the search anchor does not reset the pane again.+ search deep links leave an open plugin destination, then scroll to their+ target row before paint. Consuming the search anchor does not reset the pane+ again.- Settings remains usable when an unrelated startup read fails: a successfullyloaded settings snapshot is retained independently from the remainingbootstrap data. If the settings read itself is unavailable, the content panediff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 14708a93f..a0be2ab2b 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -14516,9 +14516,11 @@ the latest destination. These assertions measure work counts, not device FPS.the content keeps its scroll position.- Repeat for built-in → plugin, plugin → plugin, and plugin → the previouslyselected built-in destination. Re-selecting a plugin keeps its position.-- Follow a global search setting anchor into AI from another destination and- within AI: the target row is visible, and consuming the anchor keeps that- position.+- Follow a global search setting anchor into AI from another destination,+ from an open plugin destination, and within AI: the plugin page is gone and+ the target row is visible before the next paint. Consuming the anchor keeps+ that position. An external tab change with no anchor also leaves the plugin+ and starts at the top.- Run in light and dark themes.- Automated coverage: `pnpm test:e2e:settings-scroll` mounts the productionSettingsPage, store, translations, and built CSS in isolated Electron. Onlydiff --git a/docs/zh-CN/spec/04-ux/06-settings-ia.md b/docs/zh-CN/spec/04-ux/06-settings-ia.mdindex 4d526db58..7c90eb6fa 100644--- a/docs/zh-CN/spec/04-ux/06-settings-ia.md+++ b/docs/zh-CN/spec/04-ux/06-settings-ia.md@@ -8,8 +8,9 @@设置是一个**全窗口页面**,取代了应用程序侧边栏+主镶边(Codex 电子行为):- 切换到不同的设置分类时,内容区回到顶部,包括插件提供的分类。再次点击- 当前分类或在当前页更新设置时,保留滚动位置。通过全局搜索跳转时,仍在- 分类切换后定位到目标设置项;清除已消费的搜索锚点不会再次重置滚动位置。+ 当前分类或在当前页更新设置时,保留滚动位置。通过全局搜索跳转时,会离开+ 当前打开的插件分类,并在绘制前定位到目标设置项。清除已消费的搜索锚点+ 不会再次重置滚动位置。- 左侧设置导航宽 **275px**,与主侧栏共享 `sidebar-surface` 材质:macOS 使用原生vibrancy 加相同 tint/sheen,Windows/Linux 使用不透明 `--ds-bg-sidebar`,并共享可选背景图。macOS 下设置外壳透明,右侧内容区与顶部条仍不透明。只有内容区内部的入场包装播放路由入场(仅透明度,不位移),diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.mdindex e8d90c12b..130c5861d 100644--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md@@ -8620,8 +8620,9 @@ the latest destination. These assertions measure work counts, not device FPS.- 再次选择当前分类,或不离开当前页更新设置,保留内容区滚动位置。- 覆盖内置分类 → 插件、插件 → 插件、插件 → 先前选择的内置分类;再次选择当前插件分类时保留位置。-- 从其他分类及 AI 当前页通过全局搜索设置锚点进入 AI,目标项可见,消费- 锚点后保持定位。+- 从其他分类、当前打开的插件分类,以及 AI 当前页通过全局搜索设置锚点进入+ AI:插件页关闭,目标项在下一次绘制前可见,消费锚点后保持定位。没有锚点的+ 外部切页也会离开插件,并从顶部开始。- 在明暗两种主题下运行。- 自动化覆盖:`pnpm test:e2e:settings-scroll` 在隔离 Electron 中挂载真实SettingsPage、store、翻译和构建后的 CSS。仅 preload 数据使用 fixture;diff --git a/scripts/e2e/settings-scroll.jsx b/scripts/e2e/settings-scroll.jsxindex 25ba568e5..0abc181ee 100644--- a/scripts/e2e/settings-scroll.jsx+++ b/scripts/e2e/settings-scroll.jsx@@ -80,6 +80,25 @@ window.settingsScrollProbe = async () => {await scroll();await select("AI");assert(pane().scrollTop === 0, "Extension → unchanged built-in tab must start at top");+ await select("Themes A");+ await scroll();+ flushSync(() => useAppStore.getState().setSettingsTab("shortcuts"));+ assert(!document.querySelector(".plugin-scenic-theme-card"), "External tab change must leave the plugin");+ assert(document.querySelector(".settings-section-title")?.textContent?.includes("Shortcuts"), "Shortcuts must replace the plugin");+ assert(pane().scrollTop === 0, "External tab change must start at the top");+ await select("Themes A");+ await scroll();+ flushSync(() => {+ useAppStore.getState().setSettingsAnchor("settings.enterToSend");+ useAppStore.getState().setSettingsTab("ai");+ });+ assert(!document.querySelector(".plugin-scenic-theme-card"), "Search must leave the plugin destination");+ const fromPlugin = document.querySelector(".settings-anchor-flash");+ assert(fromPlugin && pane().scrollTop > 0, "Search from a plugin must be positioned before paint");+ const fromPluginBounds = fromPlugin.getBoundingClientRect();+ const fromPluginViewport = pane().getBoundingClientRect();+ assert(fromPluginBounds.top >= fromPluginViewport.top && fromPluginBounds.bottom <= fromPluginViewport.bottom,+ "Search from a plugin must show the target");// The same public store entry points used by SearchDialog.openSettingsHit.await select("Shortcuts");await scroll();@@ -87,9 +106,8 @@ window.settingsScrollProbe = async () => {useAppStore.getState().setSettingsAnchor("settings.enterToSend");useAppStore.getState().setSettingsTab("ai");});- await settle();const target = document.querySelector(".settings-anchor-flash");- assert(target && pane().scrollTop > 0, "Search anchor must win over destination reset");+ assert(target && pane().scrollTop > 0, "Search anchor must be positioned before paint");const bounds = target.getBoundingClientRect();const viewport = pane().getBoundingClientRect();assert(bounds.top >= viewport.top && bounds.bottom <= viewport.bottom,@@ -100,6 +118,8 @@ window.settingsScrollProbe = async () => {assert(pane().scrollTop === anchoredPosition, "Consuming anchor must not reset scroll");pane().scrollTop = 0;flushSync(() => useAppStore.getState().setSettingsAnchor("settings.enterToSend"));+ const withinTab = document.querySelector(".settings-anchor-flash");+ assert(withinTab && pane().scrollTop > 0, "Search within the active tab must be positioned before paint");await settle();assert(pane().scrollTop > 0, "Search within the active tab must still locate its row");checks.push({ theme, ok: true });