fix: clamp preview scroll so over-scrolling doesn't dead-zone scroll-up#11
Merged
Conversation
renderPreview clamped previewScroll on a value receiver, so the write was discarded and the model's previewScroll grew unbounded on pgdown / wheel-down past the content. The render survived (it re-clamped a local copy each frame), but after over-scrolling, scrolling back up was dead for many keypresses while previewScroll unwound from a huge value. Extract the preview line builder (buildPreviewLines) so Update can bound the scroll against the real line count via maxPreviewScroll, where the mutation actually persists. renderPreview now clamps a local var only, making the value-receiver constraint explicit.
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.
What
The last finding from the codebase review (Yoda lens).
renderPreviewclampedpreviewScrollwithm.previewScroll = max(0, len(msgLines)-1)- butrenderPreviewhas a value receiver, so that write hits a copy and is discarded. The model'spreviewScrolltherefore grew unbounded on pgdown / wheel-down past the content. The render itself never panicked (it re-clamps a local copy each frame before slicing), but after over-scrolling, scrolling back up was dead for many keypresses whilepreviewScrollunwound from a huge value.Fix
buildPreviewLines(conv, query), shared byrenderPreviewand a newmaxPreviewScroll().Update(pgdown/ctrl+j and wheel-down) viamin(previewScroll+n, maxPreviewScroll())- where the mutation actually persists.renderPreviewnow clamps a local var only, making the value-receiver constraint explicit instead of silently discarding the write.Tests
TestPreviewScrollClampedToContent- hammers pgdown 100× and assertspreviewScrollnever exceedsmaxPreviewScroll, settles at it, and that a single pgup from the bottom visibly moves (no dead zone). Fails under the old discarded-clamp code.TestUpdateMouseScrollfixtures given real messages (an empty conversation now correctly can't scroll).TestRenderPreviewunchanged and passing - confirms the extraction preserved rendering. Coverage up to 70.9%.