Fix: alternate-screen scroll detaches buffer lines, breaking text selection - #240
Open
lordspace wants to merge 3 commits into
Open
Fix: alternate-screen scroll detaches buffer lines, breaking text selection#240lordspace wants to merge 3 commits into
lordspace wants to merge 3 commits into
Conversation
added 3 commits
August 13, 2026 01:11
It pins test_api versions that conflict with the current flutter_test, so flutter test could not resolve dependencies at all — no test in the package could run. The package was discontinued upstream, and its analyzer plugin plus config block go with it.
Buffer.scrollUp shifts lines with lines[i] = lines[i + n], leaving a stale duplicate reference in the source slot. _adoptChild detached whatever occupied the target slot unconditionally, so the next iteration detached the item just re-homed one index earlier — after a single alternate-screen scroll effectively every visible line ended up detached. A detached line makes CellAnchor.attached false, so TerminalController.selection returns null: selecting text silently stopped working inside any full-screen program (less, htop, editors) once it scrolled. Detach the previous occupant only when this slot is still its home, so an eviction still detaches while a re-homed item does not.
lints 3 -> 6 is the only constraint that needed raising; build_runner, mockito and test already resolve to their ceilings under the existing ones. The lock is refreshed within those constraints (46 transitive packages). Satisfies the new strict_top_level_inference rule: a return type on the IndexAwareCircularBuffer index setter and a parameter type on _onTapDown.
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.
Fixes #239.
The fix
Buffer.scrollUpshifts lines up a slot withlines[i] = lines[i + n], whichleaves a stale duplicate reference in the source slot.
_adoptChilddetachedwhatever occupied the target slot unconditionally, so the next iteration
detached the line just re-homed one index earlier — after a single
alternate-screen scroll effectively every visible line was detached, and a
selection anchored to a detached line reads back as null.
This detaches the previous occupant only when the slot is still its home.
_attachalready rewrites_absoluteIndex, so a re-homed item maps elsewhereand survives, while an eviction on a full list still detaches exactly as before.
Full diagnosis, reproduction and measurements are in the issue.
Tests
test/src/utils/circular_buffer_test.dart— shifting items up a slot keepsthem attached, and the evicted item still detaches.
test/src/core/buffer/alt_screen_selection_test.dart— scrolls the alternatescreen, then asserts a real selection resolves and yields the right text.
The existing
can track index of itemstest earned its keep here: a firstversion of this patch passed the new test but broke that one by sparing an item
that was genuinely being evicted. Both pass now.
The two dependency commits
Drop the discontinued dart_code_metrics dev dependencyis a prerequisite,not housekeeping. The package was discontinued, and it pins
test_apiversionsthat conflict with the current
flutter_test— soflutter testcannot resolvedependencies at all and no test in the package runs on a current Flutter
SDK. Its
analyzer.pluginsentry and config block go with it.Upgrade lints to 6.x and refresh the dependency lock—lints3 -> 6 wasthe only constraint needing a raise (
build_runner,mockitoandtestalready resolve to their ceilings under the existing ones). Two one-line changes
satisfy the new
strict_top_level_inferencerule: a return type on theIndexAwareCircularBufferindex setter, and a parameter type on_onTapDown.Happy to rebase down to the bug fix alone if you would rather take the
dependency work separately — the fix stands on its own.
Verification
flutter test— 115 passing.flutter analyzereports only pre-existingSDK deprecations (
withOpacity,OverlayPortal.targetsRootOverlay).