diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5fbf6c..8b579d80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - ⚡ **页签内容不再因无关重渲染而重读整份文件**:页签 body 拿到的 `scope` 对象此前每次渲染都新建,而编辑器、差异预览、侧聊都拿它当记忆化/副作用的依赖;只要某个**被比较的字段**变了(在文件树里展开目录走 `expanded`,以及 `revealed`、语言切换、页签注册表更新),差异预览就会重跑全文改写、「内容」页重新读取整份文件并闪一下加载态。现在 `scope` 由 `useSessionScope` 按会话与 cwd 缓存,页签内容、差异页签、以及徽标 / 右侧动作区 / `+` 菜单的注册表接口共用同一份稳定对象(后三者是对外部插件公开的接口,插件对 `scope` 做记忆化不再逐渲染失效)。差异预览「内容」页的刷新改由表头刷新按钮驱动——它此前只靠这种副作用顺带刷新,改稳之后会失去刷新路径。 - **Markdown 链接里的 Windows 反斜杠**:`[x](C:\ws\_analysis\r.md)` 的 `\_` 被 Markdown 当作转义,路径少一个分隔符(变成 `C:\ws_analysis\r.md`),点击后 `ENOENT`。源代码改写现在把本地 destination 的反斜杠统一成正斜杠(Windows 两种写法都接受),UNC 前缀保持 `\\`,避免被解析成协议相对的 `//host/share`。修复 #1037。 +- **右栏展开时仍可开关底部工作台**:会话头的底部工作台开关此前在宿主右侧面板展开时整枚隐藏,导致「先开右栏就再也打不开工作台」,必须先收起右栏。现在照常显示(它在会话头 utilities,与右栏那簇控件分属两列,不会重叠)。空白会话的 fixed 兜底入口保持原行为:那个入口锚在右栏控件左侧,展开时锚点落在面板内部。`tests/bottom-toggle.spec.tsx` 守护。 - ⚡ **卡顿扫描与一轮低风险收敛**(前端页面 + 宿主 `/sidebar/*` 请求;逐条取证与误报核实见[扫描记录](docs/plans/2026-10-24-perf-scan.md)): - **文件树在隐藏页签里不再干活**:宿主把访问过的页签 body 常驻挂载,此前每个隐藏的文件树仍会在窗口获得焦点、刷新 tick 或另一个树展开目录时发 `fs.trees` 并重渲染整棵树;现在停靠树在隐藏时不加载(含折叠链预加载:隐藏后才返回的在飞层不会再拉下一节)、不监听焦点刷新,重新可见时由目录 watcher 对整套被 watch 的目录发一次批量 `fs.trees`(此前是每目录一次 POST;隐藏期间恰好没有缓存且展开集身份同时变化时最多两批,超过宿主 64 条路径上限仍按上限拆批)。 - **任务图滚轮缩放改为每帧一次提交**:高回报率滚轮/触控板此前每个 wheel 事件都重绘整张图,且每帧只保住一步缩放;现在与平移共用 `frame batcher`,同一帧的缩放量按步夹紧后完整复合、只提交一次(与逐帧应用等价);背景拖拽期间滚轮让位给拖拽,避免两种手势互相覆盖。 diff --git a/src/client/Sidebar.tsx b/src/client/Sidebar.tsx index 7a6a0827..9f45b894 100644 --- a/src/client/Sidebar.tsx +++ b/src/client/Sidebar.tsx @@ -48,7 +48,6 @@ import { createOpenInApp } from './open-in-app.ts' import { useCenterColumn } from './sidebar/use-center-column.ts' import { useHostFeeds } from './sidebar/use-host-feeds.ts' import { mountedSessions } from './native/surface.ts' -import { useRightPanelOpen } from './sidebar/right-panel-open.ts' import type { TabDragPayload } from './TabBar.tsx' import { t } from './locales.ts' import { useSessionRoot } from './use-session-root.ts' @@ -790,9 +789,9 @@ export function BottomDockToggle(props: { store: SidebarStore }) { useCallback((callback: () => void) => store.subscribe(callback), [store]), useCallback(() => store.getSnapshot(), [store]), ) - // 宿主右侧面板展开时不出现:那个状态下它右上角是一簇自己的控件 - // (Split / Fullscreen / Collapse right sidebar),入口挤进去只会跟它们打架。 - if (useRightPanelOpen()) return null + // 宿主右侧面板展开时**照常渲染**:本入口在会话头 utilities,位于右栏控件簇 + // (Split / Fullscreen / Collapse right sidebar)左侧的独立一列,不会被它们盖住。 + // 早先这里在右栏展开时早退,结果「先开右栏就再也打不开工作台」。 const open = snapshot.state?.bottomOpen === true const label = open ? t('collapseBottomPanel') : t('expandBottomPanel') return ( diff --git a/src/client/sidebar/dock-fallback.tsx b/src/client/sidebar/dock-fallback.tsx index 1009b994..1363f003 100644 --- a/src/client/sidebar/dock-fallback.tsx +++ b/src/client/sidebar/dock-fallback.tsx @@ -197,8 +197,9 @@ export function DockFallback({ store }: { store: SidebarStore }): ReactNode { if (phase === undefined || !phase.blank) return null // 兜底:相位说 blank、但会话头的入口确实在 DOM 里 —— 让位,绝不叠出第二套。 if (headerEntry) return null - // 宿主右侧面板展开时不渲染(里面那个按钮本身也会返回 null,这里连空壳一起省掉): - // 那个状态下右上角是宿主自己的一簇控件,没有本入口的容身之处。 + // 宿主右侧面板展开时不渲染:兜底入口是 fixed 定位、锚在那簇控件左侧,展开时锚点 + // 落在面板内部,放过去会盖住面板内容。正常会话的顶部入口不受此限(见 Sidebar.tsx + // 的 BottomDockToggle:它在会话头 utilities 里,与旧栏控件分属两列)。 if (rightOpen) return null // portal 到 body:面板宿主(z 20-30)的层叠上下文压不过会话头,按钮会被 titleRow // 拦截点击。40 高于 AppFrame(20) 与会话头、低于 DSH 浮层(100+)。 diff --git a/tests/bottom-toggle.spec.tsx b/tests/bottom-toggle.spec.tsx new file mode 100644 index 00000000..668ffa34 --- /dev/null +++ b/tests/bottom-toggle.spec.tsx @@ -0,0 +1,69 @@ +/** + * 会话头里的底部工作台开关(`Sidebar.tsx` 的 `BottomDockToggle`)。 + * + * 钉住一条行为:**宿主右侧面板展开时入口照常渲染**。早先这里在 `useRightPanelOpen()` + * 为真时早退,结果「先开右栏就再也打不开工作台」——右栏那簇控件 + * (Split / Fullscreen / Collapse right sidebar)在右栏列内,本入口在会话头 utilities + * (中间列),两列不重叠,没有隐藏的理由。 + * + * 空白会话的 fixed 兜底入口是另一件事(见 `dock-fallback.spec.tsx`),它在右栏展开时 + * 仍然不渲染:那个入口锚在右栏控件左侧,展开时锚点落在面板内部。 + */ +// @vitest-environment jsdom +import { afterEach, describe, expect, it } from 'vitest' +import { createElement } from 'react' +import { act } from 'react-dom/test-utils' +// First import: browser globals before the primitive-carrying sidebar graph loads. +import './browser-globals.ts' +import { renderRoot, setupReactAct } from './test-utils.ts' +import { BottomDockToggle } from '../src/client/Sidebar.tsx' +import { createSidebarStore } from '../src/client/state.ts' + +setupReactAct() + +function renderToggle(): { unmount: () => void; store: ReturnType } { + const store = createSidebarStore() + store.setSession('s1') + const view = renderRoot(createElement(BottomDockToggle, { store })) + return { unmount: view.unmount, store } +} + +/** 宿主右侧面板**展开**态的控件:可见的 `[data-sidebar-right-toggle]`。 */ +function appendExpandedRightPanelControl(): void { + const element = document.createElement('button') + element.setAttribute('data-sidebar-right-toggle', 'true') + element.getBoundingClientRect = () => ({ + x: 900, y: 10, left: 900, top: 10, width: 28, height: 28, right: 928, bottom: 38, + toJSON: () => ({}), + }) as DOMRect + document.body.append(element) +} + +afterEach(() => { + for (const element of document.querySelectorAll('[data-sidebar-right-toggle]')) element.remove() +}) + +describe('会话头底部开关', () => { + it('宿主右侧面板展开时仍然渲染入口', () => { + appendExpandedRightPanelControl() + const { unmount } = renderToggle() + try { + expect(document.querySelector('[data-dsh-bottom-toggle]'), '右栏展开也要有底部入口').not.toBeNull() + } finally { + unmount() + } + }) + + it('点击翻转 store 的 bottomOpen', () => { + const { unmount, store } = renderToggle() + try { + const element = document.querySelector('[data-dsh-bottom-toggle]') + if (element === null) throw new Error('missing element: bottom toggle') + expect(store.getSnapshot().state?.bottomOpen).toBe(false) + act(() => { element.dispatchEvent(new MouseEvent('click', { bubbles: true })) }) + expect(store.getSnapshot().state?.bottomOpen).toBe(true) + } finally { + unmount() + } + }) +})