Avoid scrolling whole selections to keep undo responsive#108
Open
brandonbloom wants to merge 1 commit intokrzyzanowskim:mainfrom
Open
Avoid scrolling whole selections to keep undo responsive#108brandonbloom wants to merge 1 commit intokrzyzanowskim:mainfrom
brandonbloom wants to merge 1 commit intokrzyzanowskim:mainfrom
Conversation
Undoing a delete after selecting a very large range can become slow on AppKit. The expensive work happens in STTextView.layout() when the view tries to make the restored selection visible. The existing code always asks TextKit for the frame of the entire current selection, so undoing Cmd+A/Delete effectively requests geometry for the whole document. Make the scroll-to-selection path target only the geometry that is needed: - if the selection already intersects the current viewport, do not scroll - if the selection is outside the viewport, scroll only the nearest selection edge instead of the entire selection range - share the same gutter-aware rect adjustment logic for range-based and location-based scrolling Add focused AppKit tests for the selection-to-scroll-target logic in UndoTests so this behavior is covered on the branch without depending on any other test harness changes. This keeps undo responsive for large selection restores while preserving the existing selection visibility behavior.
ruslanhirychau
added a commit
to ruslanhirychau/STTextView
that referenced
this pull request
Mar 16, 2026
Optimize scroll-to-selection logic in layout() to avoid unnecessary viewport jumps: - Skip scrolling if selection already intersects visible viewport - Scroll to nearest selection edge instead of entire range - Extract adjustedScrollRect() to deduplicate gutter-aware rect logic Based on PR krzyzanowskim#108 by brandonbloom. Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.
Undoing a delete after selecting a very large range can become slow on AppKit. The expensive work happens in STTextView.layout() when the view tries to make the restored selection visible. The existing code always asks TextKit for the frame of the entire current selection, so undoing Cmd+A/Delete effectively requests geometry for the whole document.
Make the scroll-to-selection path target only the geometry that is needed:
Add focused AppKit tests for the selection-to-scroll-target logic in UndoTests so this behavior is covered on the branch without depending on any other test harness changes.
This keeps undo responsive for large selection restores while preserving the existing selection visibility behavior.