Commit Graph
1 Commits
Author SHA1 Message Date
elysia395 6ca2364a12 fix(editor): keep reading position across preview/edit switches
The markdown preview container re-mounts on every mode flip (its scrollTop
lives on that DOM element), and the save-then-switch-to-preview reload
(#215) rebuilds the whole TextEditor instance - so after editing and
saving, the preview returned to the top, and entering edit mode opened the
editor at the top instead of where the reader was.

- Module-level per-file (session + path) preview scroll memory, seeded on
  component mount and re-applied in a before-paint layout effect on
  [mode, mdText]; a restoring guard keeps the collapsed-reload clamp from
  polluting the remembered position.
- Preview -> edit handoff: throttle-capture the block text at the preview
  viewport top, reverse-map it to a source line (linesOfSelection) and
  scroll the editor there, with a proportional fallback when the text match
  is ambiguous (ratio === 1, i.e. the reader is exactly at the bottom, also
  lands the editor at the bottom).
- The editor jump writes scrollDOM.scrollTop directly instead of using
  CodeMirror's scrollIntoView: that API walks every scrollable ancestor -
  and even the window when the browser is zoomed (visualViewport <
  innerHeight) - to reveal the target in the sidebar, which dragged the
  whole sidebar/page up when the reader was at the very end of the
  document. A plain scrollTop write on the editor scroller can never
  scroll anything outside the editor.

Closes #466
2026-09-03 09:59:11 +08:00