Skip to content

Conversation

@fxd0h
Copy link

@fxd0h fxd0h commented Nov 10, 2025

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 TextArea widget has two methods for handling paste operations:

  1. _on_paste() - handles paste events (programmatic or external)
  2. 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 after move_cursor(). This ensures that:

  • The scrollbar automatically scrolls to show the cursor after pasting
  • Works correctly for both vertical and horizontal scrolling
  • Handles edge cases (gutters, viewport boundaries) automatically
  • Uses existing, well-tested code—no need to reinvent the wheel

Changes

  • Added scroll_cursor_visible() call in _on_paste() method (line ~1853)
  • Added scroll_cursor_visible() call in action_paste() method (line ~2534)
  • Added 3 regression tests to prevent this bug from returning
  • Updated CHANGELOG.md

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 event
  • test_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

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)
    • ✅ All 3 new test functions have comprehensive docstrings
  • Updated documentation

    • ✅ No public API changes - this is an internal fix
    • ✅ No documentation updates required (behavior change is self-explanatory)
  • Updated CHANGELOG.md (where appropriate)


- 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
@willmcgugan willmcgugan requested a review from Copilot November 10, 2025 16:06
@willmcgugan
Copy link
Member

Did you generate this PR with AI? Not a complaint: this looks like the right fix.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_paste and action_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.

@fxd0h
Copy link
Author

fxd0h commented Nov 10, 2025

Hey, AI was used to complying with the mandatory CONTRIBUTING.md guidelines.
However I'm still working on some issues regarding the scrollbars , quick fix on my side was to create a custom widget. I'm gonna try to find a creative way to include it as a feature request in the near future.

@willmcgugan
Copy link
Member

This didn't appear to fix anything. Thanks but no thanks.

@fxd0h fxd0h deleted the fix/4852-textarea-scrollbar-paste branch November 10, 2025 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TextArea scrollbar position is not updated after paste

2 participants