Commit Graph
3 Commits
Author SHA1 Message Date
ymac 776e777da7 fix(editor): 落地到行时把光标亮出来,并让引用赢过预览的阅读位置(#826 收尾之四)
第一次真机手测反馈:跳转确实进了编辑视图,但**看不到光标**,所以不知道落在哪一行。
两个原因:

1. **没给编辑器焦点**。落地只 `dispatch({ selection })`,而 CodeMirror 只在
   **获焦**的编辑器里画光标,且零长度选择本身不画任何东西——未获焦的落地读起来
   就是「文件打开了,停在某处」。现在只在**行号引用**这条路上 `view.focus()`
   (普通打开不动读者的焦点,读者可能是从聊天输入框点的链接)。

2. **预览的阅读位置会覆盖它**。进入编辑态时那条「按预览滚动位置恢复」的副作用
   声明在落地之后,两个 effect 在同一次提交里,它会把选择与滚动重新写回读者
   刚才预览的地方——读者先在预览里滚动过,再点带行号的引用,跳转就被静默抹掉。
   落地前清掉 `previewSyncRef`:引用要的是源码里的那一行,不是预览里那个位置。

测试:text-editor-line-jump.spec.tsx 加 3 例(落地后 focus 被调用、普通打开不抢焦点、
markdown 翻转后仍获焦)+ 1 例判别性用例(预览滚到 90% 后再跳第 3 行,最后一次
dispatch 必须是第 3 行的 offset 8 而不是按比例算出的 14;去掉清空那行即红)。
2026-10-11 16:06:42 +08:00
ymac 46a870a471 fix(editor): 引用行号不再永久占有 markdown 的模式(#826 收尾)
跳到 #L131 后回不到预览:TextEditor 收到行号会把 markdown/html 强制切到编辑态,
而「这条导航是否已经消费过」记在组件实例里(landedAtRef)。EditorHost 的每次
reload 都用 loading 行替换 viewer(页头刷新、「编辑 → 预览」边沿 #167 part B、
预览态保存后的刷新、#855 自动刷新),重建出的实例又是 preview 模式 + 空记忆,
于是同一个行号再次强制切编辑——读者点「预览」当场被切回去。

记忆改由宿主持有(它比 viewer 活得久):TextEditor 定位完成后回调
`onLineConsumed()`,EditorHost 记住已消费的 `${path}#${line}` 并停止再下发,
直到换文件(新的一次打开)或换行号(新引用)。公开面纯增量:
`FileViewerProps.onLineConsumed?: () => void`,不消费 `line` 的第三方 viewer
行为不变。

测试:tests/editor-line-nav-mode.spec.tsx(新,3 例,真 TextEditor 过 EditorHost:
落地后能回预览 / 刷新不回弹 / 同文件新行号仍落地),text-editor-line-jump.spec.tsx
补 2 例钉住消费契约(定位后恰好一次、普通打开不消费)。
2026-10-11 11:43:51 +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