Skip to content

Scroll position is lost or jumps when switching between Editor and Preview #104

@threatner

Description

@threatner

What happened?

Two related issues when switching between Editor (⌘1) and Preview (⌘2):

  1. Editor → Preview:
    Scrolling to the middle in Editor opens Preview at the top.

  2. Preview → Editor:
    Scrolling in Preview and switching back makes the Editor jump to the bottom.

Expected:
Scroll position should be preserved in both directions (as intended by ScrollBridge in PositionSync.swift).

Root cause:

computeScrollFraction uses:

clipView.bounds.origin.y / maxScroll

With flipped NSTextView coordinates, this becomes negative when scrolled:

ScrollBridge.set[...] = -0.5863

Preview assumes a 0–1 positive fraction and calls:

scrollTo(0, fraction × maxScroll)

So:

  • Negative fraction → clamped to top (Editor → Preview)
  • Positive fraction from preview → misapplied by editor → clamps to bottom (Preview → Editor)

This is a coordinate convention mismatch between editor and preview.

Steps to reproduce

Symptom 1 (Editor → Preview):

  1. Open any .md file long enough to need scrolling.
  2. In Editor mode (⌘1), scroll to roughly the middle.
  3. Press ⌘2 to switch to Preview.
  4. Preview opens at the top instead of the middle.

Symptom 2 (Preview → Editor):

  1. From the previous state, scroll the preview to any position.
  2. Press ⌘1 to switch back to Editor.
  3. Editor jumps to the bottom instead of matching the preview position.

App version

1.13.0

macOS version

26.4

Screenshots

Screen.Recording.2026-04-10.at.12.08.17.AM.mov

Problematic file

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions