Fix TextArea scrollbar position not updated after paste#6218
Conversation
- Added scroll_cursor_visible() call in _on_paste() method - Added scroll_cursor_visible() call in action_paste() method - Added regression tests for paste scrollbar behavior - Updated CHANGELOG.md Fixes Textualize#4852
|
Did you generate this PR with AI? Not a complaint: this looks like the right fix. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes issue #4852 where the TextArea scrollbar position was not being updated after paste operations, causing the cursor to move off-screen without the view automatically scrolling to follow it.
Key Changes:
- Added
scroll_cursor_visible()calls in both paste methods (_on_pasteandaction_paste) to ensure the cursor remains visible after pasting - Added comprehensive regression tests covering paste actions, paste events, and wide text scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/textual/widgets/_text_area.py | Added scroll_cursor_visible() calls after cursor movement in both _on_paste() and action_paste() methods to ensure cursor stays visible after paste operations |
| tests/text_area/test_textarea_cut_copy_paste.py | Added three regression tests verifying scrollbar updates correctly after paste: via action, via event, and with wide text requiring both horizontal and vertical scrolling |
| CHANGELOG.md | Added entry documenting the fix for TextArea scrollbar position not updating after paste |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey, AI was used to complying with the mandatory CONTRIBUTING.md guidelines. |
|
This didn't appear to fix anything. Thanks but no thanks. |
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"