Commit Graph
6 Commits
Author SHA1 Message Date
Menghuan1918 04c6cb8a10 merge review/mermaid-frame: #1040 sandbox-iframe mermaid layout isolation 2026-10-29 23:43:11 +08:00
OCILY aa198d7921 perf(mermaid): keep scrolling and hidden tabs off the render queue
Follow-up to the iframe isolation: after that fix a 31-diagram document
still felt janky while scrolling. The remaining cost was work competing
with the scroll gesture:
- background diagram renders kept running during scroll (each one injects
  an SVG, runs DOM passes and lays out);
- hidden native tabs kept warming diagrams (tab bodies are keepMounted);
- the inline-HTML and heading-anchor MutationObservers ran a full-document
  scan per mutation (measured 8-15 ms per pass, dozens of passes when a
  document swaps its diagrams in);
- initial near-viewport detection read one rect per diagram between DOM
  writes, forcing a layout per diagram;
- off-screen rendered SVGs still participated in layout and paint.

The queue now pauses background work for 350 ms after the last captured
scroll event, and only schedules renders whose preview is visible
(IntersectionObserver gate per preview; hidden tabs keep placeholders and
wake the queue when shown again, and unmounting a preview drops its queued
tasks). The two mutation passes coalesce bursts into one 80 ms pass.
Initial priorities come from one batched rect read before the swap writes.
.mermaidWrap gains content-visibility:auto + contain-intrinsic-size +
contain:layout paint style, so off-screen diagrams leave layout and paint.

Visible diagrams still render on demand, every diagram is still eventually
rendered, and nothing falls back to a code block.
2026-10-28 20:20:49 +08:00
CCColastic cff738b23b fix(sidechat): render and open local source file links 2026-10-28 11:14:56 +08:00
ymac 6f2054a56c fix(sidebar): 会话地址的基准统一到会话 header cwd(#947 / #950)
会话地址 `dsh-resource://file/session/<sid>/<path>` 的相对路径,宿主构造端
(ui-chat 的 openFile)与解析端(api-workspace-files)都取会话存储的 header cwd;
插件自 #802 起让 fs 路由与原生 tab 体跟随活动 worktree 根,于是地址里的相对拼写
被活动根再拼一次:worktree 嵌在 header cwd 之下时路径翻倍(ENOENT,聊天链接与
改动页都中招),两个检出都有同名文件时静默读到另一份(可保存写回)。

规则:构造端与消费端共用同一个基准,并在地址被读到的边界把它解析成绝对路径——
绝对路径在任何基准下都一样,下游再无可重定基的余地。

- 新增 src/client/address-base.ts 的 addressBaseOf(ctx, sessionId):会话列表里的
  header cwd(宿主地址契约的基准),取不到返回 undefined 让调用方回退。
- 消费边界:fileParamsOf(info, base?) 在切 `path:line` 规格之前把地址路径解析成
  绝对路径;native/index.ts 的 editor 类型注入
  paramsOf: (info) => fileParamsOf(info, addressBaseOf(ctx, fileSessionIdOf(info)))。
- 构造边界:native/surface.ts 的 fileAddress 与 sidebar-file.ts 的
  openClaimedNativeFile 都以 addressBaseOf 优先,调用方 cwd 只作回退——同一文件
  只有一个地址(与宿主聊天路径的地址一致,页签照旧合并)。
- 意图侧:openSidebarFile(ctx, sessionId, path, { line?, cwd? }) 的 cwd 是调用方
  手上的活根(EditorHost / 改动页 / markdown 面板传 useSessionRoot 的结果),
  相对路径按它解析,缺省才回退 header cwd——同一相对路径在各入口不再落到不同检出。
- 测试:新增 tests/worktree-address.spec.ts(基准三态 / 绝对路径不可重定基 /
  构造端基准 / 相对路径按活根解析),真 git worktree 夹具;file-open-claim 的
  `line` 位置参数随之改为 `{ line }`(唯一签名变更点)。
2026-10-14 23:18:08 +08:00
ymac 68d6c33025 fix(markdown): 预览里的 #L131 链接也带上行号(#826 收尾之二)
插件自绘的 markdown 预览(编辑器预览 / 侧边对话转录 / 变更阅读窗 / 任务窗口)
里点 `./other.md#L42`,文件打开了却不跳行——而且停在预览态,源码被当成段落
渲染成一坨。聊天正文里同一个链接能跳:那一侧的 `navigation.params.line` 由宿主
解析后落进记录,而插件这一侧的 delegate `openFile(path, { line })` 收到的行号
只被当成「这是行号不是标题锚点」的判据,随后 `openSidebarFile` 就把它丢了
(种子没有 line 字段,原生分支的 `surface.openResource` 也没传——末跳本身是
支持的)。

补齐三跳:`use-markdown-surface` 把 `options.line` 传下去(拿不到时按宿主语法
自己解析片段,新增 `lineOfHostFragment`,区间取起始行),`openSidebarFile` 与
`OpenTabSeed` 各带一个可选 `line`,`openTab` 的原生分支转发给
`surface.openResource`、底部工作台的 mint 落进 tab。落地后的行为与聊天正文那条
一致:跳到那一行,markdown/html 离开预览(预览里没有源码行号),并且——承上一条
提交——读者随时能点回预览。

测试:markdown-surface.spec.tsx 走真实宿主 MarkdownText 点链接,钉住 `#L42` 与
`#L20-L25` 进记录、标题锚点仍然只走 parked 片段;markdown-navigation.spec.ts 钉
新解析器;file-open-claim.spec.ts 钉种子透传与「不传就不带这个键」。
2026-10-11 12:02:55 +08:00
Menghuan1918 cfe84c99b3 feat(markdown): claim local .md links and navigate headings across files (#363)
Markdown surfaces the plugin draws (editor preview, side-chat transcript,
changes reading pane, task note) now open local markdown links in the sidebar
and follow same-page / cross-file heading anchors.

The host renderer decides what a local destination even is: without a
`MarkdownDelegateProvider.openFile` a local link renders as plain text (there is
no `a[href]` to intercept), and `parseFileLink` accepts a fragment only in the
line grammar (`#L24`), so a heading fragment makes the whole destination
unparseable. So the claim is scoped by the provider (one per surface) and a
SOURCE pass carries a heading fragment past the parser as `%23` — the same shape
markdown-images.ts already uses for relative image destinations. Destinations
the plugin does not claim (non-markdown, remote, queried) keep rendering exactly
as they do today.

- `markdown-navigation.ts`: pure link judge + GitHub heading slugs (Chinese kept,
  duplicates `-1`, authored ids reserved first), collapsed-anchor hiding, the
  source rewrite, the jump that scrolls the surface's OWN scroller (never
  `window`/`scrollIntoView`), and the session+path keyed pending fragment table.
- `use-markdown-surface.ts`: one hook per surface — the container callback ref
  (DOM pass + mutation re-runs + pending fragment) and the delegate's `openFile`.
2026-10-05 23:43:14 +08:00