egui icon indicating copy to clipboard operation
egui copied to clipboard

`Ctrl+Shift+Z` should restore data to the state that was before like `Ctrl+Y` does

Open AngelicosPhosphoros opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe.

Well, I often use keybinding Ctrl+Shift+Z to restore text state after I accidentally undid too much changes using Ctrl+Z. In egui controls, e.g. text edit, Ctrl+Shift+Z doesn't behave like rest of such inputs in my system (Windows 10).

Describe the solution you'd like Ctrl+Shift+Z keybinding should do redo operation, like Ctrl+Y does.

Describe alternatives you've considered Do nothing and tell users to use Ctrl+Y. It works on egui controls.

Additional context Well, I use computers the biggest part of my life and always used Ctrl+Shift+Z to cancel Ctrl+Z. Only when opening this issue, I checked if this is actually standardized and found that there exists a Ctrl+Y keybinding. I think, it is common for users to be like me so supporting both Ctrl+Y and Ctrl+Shift+Z would be convenient for them.

Maybe, it is a wrong repository to report this and I should report it to winit, I don't really know.

AngelicosPhosphoros avatar Oct 12 '24 23:10 AngelicosPhosphoros

No, this has nothing to do with winit, and it's actually a bug in egui. The Ctrl+Shift+Z shortcut is supposed to work as redo as well:

https://github.com/emilk/egui/blob/23728e145ec52bd1193f6f0123973763de4dbb3d/crates/egui/src/widgets/text_edit/builder.rs#L997-L1015

But it doesn't, because the previous match arm (undo) is also triggered by this same key combination:

https://github.com/emilk/egui/blob/23728e145ec52bd1193f6f0123973763de4dbb3d/crates/egui/src/widgets/text_edit/builder.rs#L980-L996

This matches_logically method is supposed to work like this, at least according to its doctests:

https://github.com/emilk/egui/blob/23728e145ec52bd1193f6f0123973763de4dbb3d/crates/egui/src/data/input.rs#L769-L786

But it is being used incorrectly here, causing both Ctrl+Z and Ctrl+Shift+Z to work as undo.

YgorSouza avatar Oct 13 '24 09:10 YgorSouza

This code looks awful https://github.com/emilk/egui/blob/23728e145ec52bd1193f6f0123973763de4dbb3d/crates/egui/src/widgets/text_edit/builder.rs#L1002-L1004 I would be better introduce a Shortcut struct which will incapsulate keys and modifiers. QShortcut is a good inspiration.

Mingun avatar Oct 13 '24 13:10 Mingun

There is https://docs.rs/egui/0.29.1/egui/struct.KeyboardShortcut.html. Not sure why it isn't being used here. Maybe it was introduced later and this code was never refactored. But that is a separate issue.

YgorSouza avatar Oct 13 '24 13:10 YgorSouza