Fix TextArea scrollbar position not updated after paste #6218
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.
PR Description: Fix TextArea scrollbar position not updated after paste
Description
Fixes #4852
When pasting text into a
TextArea, the vertical scrollbar position was not updated to show the cursor position after the pasted text. Users had to manually scroll to see where their cursor ended up—a classic UX frustration that's been plaguing text editors since the days of vi vs emacs debates.The Problem
The
TextAreawidget has two methods for handling paste operations:_on_paste()- handles paste events (programmatic or external)action_paste()- handles keyboard shortcuts (Ctrl+V, Cmd+V)Both methods correctly insert the text and move the cursor to the end of the pasted content, but neither was calling
scroll_cursor_visible()to ensure the scrollbar updated to show the new cursor position.The Solution
Added
scroll_cursor_visible()calls in both methods aftermove_cursor(). This ensures that:Changes
scroll_cursor_visible()call in_on_paste()method (line ~1853)scroll_cursor_visible()call inaction_paste()method (line ~2534)Testing
Added comprehensive regression tests:
test_paste_scrollbar_position_updated()- Tests paste via action (Ctrl+V)test_paste_event_scrollbar_position_updated()- Tests paste via eventtest_paste_scrollbar_with_wide_text()- Tests with wide text requiring both scrollbars (addresses comment from TomJGooding)All tests pass ✅, and existing tests continue to pass ✅.
Checklist
CHANGELOG.mdmake format)make test)TextAreascrollbar position is not updated after paste #4852)Please review the following checklist.
Docstrings on all new or modified functions / classes
_on_paste()method already had docstring (no changes needed)action_paste()method already had docstring (no changes needed)Updated documentation
Updated CHANGELOG.md (where appropriate)
TextAreascrollbar position not updated after pasteTextAreascrollbar position is not updated after paste #4852"