Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let scrolling follow the text cursor in a multiline text edit widget #165

Closed
the-drunk-coder opened this issue Feb 7, 2021 · 6 comments · Fixed by #1252
Closed

Let scrolling follow the text cursor in a multiline text edit widget #165

the-drunk-coder opened this issue Feb 7, 2021 · 6 comments · Fixed by #1252
Labels
feature New feature or request text Problems related to text

Comments

@the-drunk-coder
Copy link

Is your feature request related to a problem? Please describe.
Problem: When editing longer text snippets in a multi-line text edit widget, the cursor just leaves the scroll area, and you have to follow it manually with the mouse.

Describe the solution you'd like
Have the scrolling follow the cursor automatically, without having to switch to the mouse.

I've made some experiments with the customized text edit widget I keep in a fork, but when trying to scroll to a certain position the results are somewhat unpredictable ...

@the-drunk-coder the-drunk-coder added the feature New feature or request label Feb 7, 2021
@emilk emilk added the text Problems related to text label Feb 11, 2021
@emilk
Copy link
Owner

emilk commented Feb 11, 2021

This has not yet been implemented, so thanks for opening an issue on it!

This might be pretty easy to implement by following the bread-crumbs of the implementation of https://docs.rs/egui/0.9.0/egui/struct.Response.html#method.scroll_to_me and https://docs.rs/egui/0.9.0/egui/struct.Ui.html#method.scroll_to_cursor

@emilk emilk changed the title Is it possible to let scrolling follow the text cursor in a multiline text edit widget? Let scrolling follow the text cursor in a multiline text edit widget Feb 11, 2021
@the-drunk-coder
Copy link
Author

Hmm I tried several variants of that but the results were a little unpredictable ... like, scrolling to a certain y-position never really scrolled to where I needed it ...

But I guess I should give it another look ...

@UE2020
Copy link

UE2020 commented Jan 13, 2022

Is there a solution for this yet?

@the-drunk-coder
Copy link
Author

Haven't worked on this either for a while ...

One problem I've frequently run into is that it seems hard to apply the abovementioned scroll_to_cursor and scroll_to_me methods selectively when the cursor leaves the visible part of the text field.

I think one thing that would be helpful is to have some method to detect whether the cursor moved out of the visible part of the text field, and in which direction ...

@robo-corg
Copy link

Is there a way to use to use this with ScrollArea::show_rows? Trying to get this working with that but I am not certain what a rect for this would be if the location is not on screen.

Looking at things in the debugger and it seems the clip area never really changes and seems to be the screen coordinates of the ScrollArea.

@robo-corg
Copy link

Ahh I think I figured it out. You need to calculate the position relative to row_range passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request text Problems related to text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants