Commit Graph
2 Commits
Author SHA1 Message Date
ymac 6dd0486f5c fix(editor): 换文件 / 重命名时丢掉继承来的 landing line(#826 收尾之三)
`updateTab` 的补丁只有 title/path/meta,所以两条「插件自己改路径」的路都把上一个
文件的行号留在了记录里:合并模式在页头路径框输另一个文件、以及文件树里重命名
打开的文件(`retargetPathTabs`)。后果与 reload 那条同症状——新文件跳到旧行号,
markdown 还被拉进编辑态。宿主导航那条路径本来就有清理规则
(`params.line !== existing.tab.line`),插件自己写的路径没有。

规则统一为「**改 path 就是一次新的打开**」,瞬态行号随之清掉,落在两个记录层:
`patchTab`(store 分支)与原生记录的 `update()`(`updateTab` 的 native 分支);
只改 title / meta 的补丁不动它(同一文件,行号仍属于当前这次导航)。

测试:native-tab-line.spec.ts 加两例(换 path 清掉、只改 title 保留),
editor-line-nav-mode.spec.tsx 的第四条从「模拟 updateTab 的结果」改成驱动真实
`service.updateTab` 并断言记录里 `line` 消失、编辑器留在预览态。
2026-10-11 15:56:49 +08:00
ymac 415d517fb0 fix(editor): make a file reference land on its line (#826 second half)
`fileParamsOf` already split the `path:line` spec off the address (#828)
but kept only `spec.path` — so both spellings opened the file and left the
reader on line 1: `path:131` dropped the parsed line, and the host's own
`#L131` fragment was already delivered as `navigation.params.line` and
dropped just the same.

Carry the line the rest of the way: address → `SidebarTab.line` →
`FileViewerProps.line` → one reveal in the text editor. Both spellings
land on the same row.

Three decisions:

- `line` is transient: `sanitizePersistedTab` copies a whitelist and this
  field is deliberately left out of it, so a reload does not yank the
  reader back to a line a link named days ago. Same treatment as
  `revealed`.
- markdown/html flip out of preview when a line is present: preview has no
  source lines to put a cursor on, and its own mount-time scroll restore
  would fight the jump (both write the same `scrollTop`). The reference
  asked for source, so the flip does not record the key and the re-run
  after the mode change does the jump — which also dissolves the conflict
  instead of arbitrating it.
- A range keeps only its first line and the column is dropped: the editor
  has exactly one cursor.

The record must also be able to DROP the line, not only set it — an
in-place switch from `a.ts:131` to a bare `a.ts` would otherwise leave 131
behind and the editor would bounce the reader back on every notification.
Comparing against the current value instead of "was one passed" also keeps
the synthetic record's identity when neither side has one, which matters
because the host keeps visited bodies mounted.
2026-10-05 22:17:44 +08:00