crash fix: sync stale editor cursors through document updates#1061
Open
Third-Thing wants to merge 2 commits intolapce:mainfrom
Open
crash fix: sync stale editor cursors through document updates#1061Third-Thing wants to merge 2 commits intolapce:mainfrom
Third-Thing wants to merge 2 commits intolapce:mainfrom
Conversation
This is the smallest change that fixes the crash using existing document-delta plumbing, without taking on the larger API remodel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: When multiple editors share a
TextDocument, or when a document is edited programmatically, only the initiating editor updates its cursor. Other editors keep stale byte offsets. That can leave a cursor past the end of the buffer or inside a multibyte character, which then panics on the next keypress. In practice this affects both shared editors and single editors after rawDocument::edit/edit_singlecalls.Solution: Register a
TextDocumentupdate listener for eachEditorand remap non-originating cursors through incomingRopeDeltas withCursor::apply_delta. The originating editor is skipped to avoid double-transforming its cursor. The listener is registered when the editor is created and when its document changes, and it usestry_updateplus a document identity check so disposed editors or stale listeners fail closed instead of panicking.Reasoning: This is the smallest change that restores cursor validity using floem’s existing document update flow and eliminates the crashes mentioned in #934 & #693.
TextDocumentalready emits deltas for every edit, andCursoralready knows how to transform itself through those deltas. Hooking editors into that path keeps cursor synchronization reactive and document-driven, without introducing new edit APIs or a larger coordination layer. The document identity guard is necessary becauseadd_on_updateis currently append-only, so old listeners cannot yet be removed when an editor switches documents.Associated with issue #1058