Skip to content

Remember scroll position per document across switches#70

Merged
luca-chen198 merged 2 commits into
mainfrom
feature/remember-scroll-on-switch
Jun 15, 2026
Merged

Remember scroll position per document across switches#70
luca-chen198 merged 2 commits into
mainfrom
feature/remember-scroll-on-switch

Conversation

@luca-chen198

Copy link
Copy Markdown
Member

What

The editor reset scroll to the top on every document switch. This adds per-document scroll memory: each document's vertical offset is captured when switching away and restored when it's shown again.

How

  • NativeTextViewCoordinator.scrollOffsets: [documentId: CGFloat] holds the offsets (survives switches — same coordinator instance).
  • On a document switch in updateNSView: capture the outgoing document's bounds.origin.y, park at the top during the content rebuild, then restore the incoming document's saved offset once its height is measured. clampToInsets() keeps it in range, so a shorter document never lands in empty space.
  • New optional retainedScrollDocumentIds: Set<String>? lets embedders scope retention — offsets for documents not in the set are forgotten (default nil keeps all). The Nodes app uses it to forget a node's scroll once it leaves the open-items list.

Notes

  • Backward compatible: the new parameter defaults to nil.
  • No new layout passes — restoration hooks into the full-layout measure that already runs on switch.

🤖 Generated with Claude Code

luca-chen198 and others added 2 commits June 15, 2026 13:07
The editor reset scroll to the top on every document switch. Now each document's scroll offset (clip-view bounds.origin.y) is captured when switching away and restored when shown again, clamped to the new content height so a shorter document never lands in empty space.

Embedders can scope retention via the new optional 'retainedScrollDocumentIds': offsets for documents not in the set are forgotten (default nil keeps all).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
After a Writing Tools (Proofread/Rewrite/Compose) session, didEnd pre-set lastSyncedText == text, so updateNSView early-returned and never re-styled or re-measured the accepted result — it stayed unstyled, and a taller result overflowed the stale frame and wasn't visible. Don't pre-set lastSyncedText; let the normal updateNSView rebuild handle it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luca-chen198 luca-chen198 merged commit 85143d3 into main Jun 15, 2026
1 check passed
luca-chen198 added a commit that referenced this pull request Jun 20, 2026
fitsContent height behavior (#75), BlockquoteStyle.extraLineHeight (#76), and fixes (#69/#70/#71/#73).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant