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

Select text across widgets #3816

Closed
emilk opened this issue Jan 14, 2024 · 3 comments · Fixed by #3870
Closed

Select text across widgets #3816

emilk opened this issue Jan 14, 2024 · 3 comments · Fixed by #3870
Assignees
Labels
egui rerun Desired for Rerun.io text Problems related to text

Comments

@emilk
Copy link
Owner

emilk commented Jan 14, 2024

Since #3814 we can now select text within a single Label. However, if you put several widgets in a layout, you cannot select all the text across them at once. This gif showcases this shortcoming, here mixing Label with Hyperlink:

select-shortcoming

In order to support this we need to keep track of the first and last widget of the selection. During layout, egui needs to track wether or not we are hitting one of these "edge" widgets, and then automatically mark all widgets in between as selected.
When hitting the "copy" button, the text of all widgets needs to be copied.

We should probably only allow drag-to-select a range within the same layer (i.e. Window/Area).

Copying text

When hitting Cmd C, each fully or partially selected widget needs to append their text to the clipboard, and probably insert an extra space between (unless there already is one).

Handling this in the general case of right-to-left layouts will be difficult, so let's start with simple left-to-rigth/top-down layouts first.

@emilk emilk added text Problems related to text egui rerun Desired for Rerun.io labels Jan 14, 2024
@juancampa
Copy link
Contributor

juancampa commented Jan 14, 2024

@emilk this is amazing, I have a lot of TextEdit in my code and string concatenation just to get selection. Very happy that you're working on this.

I figured that since you're actively working on this you might wanna tackle this inconsistency with the cursor to bring it closer to how the browser does it.

Screen.Recording.2024-01-14.at.12.56.07.PM.mov

Basically, the cursor should become CursorIcon::Text while hovering actual text, not the bounding box. Hopefully this can be implemented with Galley::cursor_from_pos but I'm not sure.

@emilk
Copy link
Owner Author

emilk commented Jan 15, 2024

@juancampa if you want that, make a PR. I'll likely won't be working on this for at least another few weeks, if then.

@emilk emilk added this to the Next Major Release milestone Jan 19, 2024
emilk added a commit that referenced this issue Jan 19, 2024
This is a follow-up to #3804 and a
pre-requisite for #3816
@emilk emilk self-assigned this Jan 22, 2024
emilk added a commit that referenced this issue Jan 22, 2024
… to begin/end (#3858)

This also adds a `Galley::begin` method to match `Galley::end` (both
returning cursor positions).

* Part of #3816
emilk added a commit that referenced this issue Jan 24, 2024
* Closes #3816


![cross-widget-text-selection](https://github.com/emilk/egui/assets/1148717/5582b9d2-8b04-47b7-9637-f48e44064a70)

Turn off with `style.interaction.multi_widget_text_select`.

There is an API for this in `LabelSelectionState`, but it's pretty
bare-bones.

This became really hairy implementation-wise, but it works decently
well.

# Limitations
* Drag-select to scroll doesn't work
* A selection disappears if you scroll past one of its end-points
* Only the text of labels and links are selectable
 
## TODO
* [x] An option to turn it off
* [x] An API for querying about the selected text, and to deselect it.
* [x] Scrolling past selection behaves weird
* [x] Shift-click to select a range
@juancampa
Copy link
Contributor

cursor should become CursorIcon::Text while hovering actual text, not the bounding box

Awesome! Seems like this was indeed fixed in this PR 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui rerun Desired for Rerun.io text Problems related to text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants