X Tutup
Skip to content

Add auto-scroll behavior when selecting text outside the visible area in RichTextLabel#104715

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Andrewyuan34:add-auto-scroll
Oct 3, 2025
Merged

Add auto-scroll behavior when selecting text outside the visible area in RichTextLabel#104715
Repiteo merged 1 commit intogodotengine:masterfrom
Andrewyuan34:add-auto-scroll

Conversation

@Andrewyuan34
Copy link
Contributor

Summary

This PR improves the text selection experience by ensuring that when the user drags the mouse outside the visible text area, the content scrolls automatically in the appropriate direction.

Changes

  • Implemented smooth auto-scrolling when the cursor moves above or below the text area.
  • Adjusted scroll speed dynamically based on the cursor's distance from the text area.
  • Ensured that the selection properly updates to the last visible item when scrolling occurs.

Why this is needed

Previously, when selecting text beyond the visible bounds, the scroll behavior was either inconsistent or non-existent, making text selection difficult for larger documents. This PR enhances usability by ensuring a fluid scrolling experience.

Testing

  • Verified that scrolling works both upwards and downwards when dragging outside the visible text area.
  • Ensured that selection updates correctly to the boundary item when scrolling.
  • Tested with different text lengths and scroll speeds to maintain a smooth experience.

GIF 3-28-2025 3-59-06 AM

@Andrewyuan34 Andrewyuan34 requested a review from a team as a code owner March 28, 2025 08:00
@AThousandShips AThousandShips added this to the 4.x milestone Mar 28, 2025
@KoBeWi
Copy link
Member

KoBeWi commented Apr 5, 2025

Does not work correctly when the RichTextLabel is rotated.
TextEdit handles it properly.

@Andrewyuan34 Andrewyuan34 force-pushed the add-auto-scroll branch 3 times, most recently from 73dde51 to 90c8483 Compare April 19, 2025 06:06
@Andrewyuan34
Copy link
Contributor Author

@KoBeWi Thanks for the review! Already solved that problem. Here's the demo video.
GIF 4-19-2025 2-18-15 AM

@KoBeWi
Copy link
Member

KoBeWi commented Apr 26, 2025

The dragging works correctly now, though another problem is that the scrolling happens on mouse events. So if you drag out of view, you can't scroll automatically, you need to keep moving the cursor. It's not very convenient.

Also the implementation feels over-engineered. You added 3 methods, but each is used only once. At least one of them is redundant and their names could be better.

@Andrewyuan34 Andrewyuan34 force-pushed the add-auto-scroll branch 2 times, most recently from c46200d to 7b3d1a5 Compare April 29, 2025 02:06
@Andrewyuan34
Copy link
Contributor Author

@KoBeWi Thanks for the suggestions, already applied those changes. and I'm trying to mimic TextEdit's approach to handle automatic scrolling during text selection. seems that the gif tool would automatically filter out mouse... , but the functionality is working smoothly now.
GIF4-28-202510-09-34PM-ezgif com-optimize

@Andrewyuan34
Copy link
Contributor Author

@AThousandShips Is this a problem that from my changes? error messages from CI:

Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
libxml2-utils
0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded.
Need to get 39.4 kB of archives.
After this operation, 188 kB of additional disk space will be used.
Ign:1 http://azure.archive.ubuntu.com/ubuntu noble-updates/main amd64 libxml2-utils amd64 2.9.14+dfsg-1.3ubuntu3.2
Err:1 http://azure.archive.ubuntu.com/ubuntu noble-updates/main amd64 libxml2-utils amd64 2.9.14+dfsg-1.3ubuntu3.2
404 Not Found [IP: 40.81.13.82 80]
E: Failed to fetch http://azure.archive.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2-utils_2.9.[14](https://github.com/godotengine/godot/actions/runs/14721800559/job/41417478289?pr=104715#step:6:15)%2bdfsg-1.3ubuntu3.2_amd64.deb 404 Not Found [IP: 40.81.13.82 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Error: Process completed with exit code 100.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

I see you used a Timer for scrolling 🤔
Seems to work fine now, but someone should test it with higher refresh rate.

@KoBeWi KoBeWi modified the milestones: 4.x, 4.5 May 13, 2025
@Andrewyuan34 Andrewyuan34 force-pushed the add-auto-scroll branch 2 times, most recently from f6b46da to de21330 Compare May 14, 2025 01:43
@Andrewyuan34
Copy link
Contributor Author

I see you used a Timer for scrolling 🤔 Seems to work fine now, but someone should test it with higher refresh rate.

already tested 30, 60, 120, 240 refresh rate with Engine.max_fps. All working fine

@Andrewyuan34
Copy link
Contributor Author

@KoBeWi May I ask what the process is for getting this PR reviewed and merged?

@KoBeWi KoBeWi requested a review from Calinou May 25, 2025 19:51
@KoBeWi
Copy link
Member

KoBeWi commented May 28, 2025

already tested 30, 60, 120, 240 refresh rate with Engine.max_fps

Does your screen have 240Hz refresh rate though?

@Andrewyuan34
Copy link
Contributor Author

Andrewyuan34 commented May 28, 2025

already tested 30, 60, 120, 240 refresh rate with Engine.max_fps

Does your screen have 240Hz refresh rate though?

yes... just bought one few month ago. It's a ROG STRIX G16 GeForce RTX 4060 version

@KoBeWi
Copy link
Member

KoBeWi commented May 28, 2025

I requested extra review, but it might be not necessary.
The PR is in merge queue, so it will be merged for 4.5. For now you just have to wait.

@Andrewyuan34
Copy link
Contributor Author

I requested extra review, but it might be not necessary. The PR is in merge queue, so it will be merged for 4.5. For now you just have to wait.

nice! Thanks a lot for the review.

@Repiteo Repiteo modified the milestones: 4.5, 4.6 Jun 19, 2025
@Repiteo Repiteo merged commit 71a485a into godotengine:master Oct 3, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 3, 2025

Thanks! Congratulations on your first merged contribution! 🎉

uno1982 added a commit to uno1982/godot that referenced this pull request Mar 8, 2026
Start the selection timer after a double-click so that dragging to
extend a word selection works correctly.

Regression introduced in godotengine#104715 which moved selection updates into a
timer callback (click_select_held) but did not start the timer in
the double-click handler, only in the single-click handler.

Fixes godotengine#116860.
uno1982 added a commit to uno1982/godot that referenced this pull request Mar 9, 2026
Start the selection timer after a double-click so that dragging to
extend a word selection works correctly.

Regression introduced in godotengine#104715 which moved selection updates into a
timer callback (click_select_held) but did not start the timer in
the double-click handler, only in the single-click handler.

Fixes godotengine#116860.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

X Tutup