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

Ctrl+X, C, V events get cut out #4065

Open
mkrueger opened this issue Feb 18, 2024 · 8 comments · May be fixed by #5615
Open

Ctrl+X, C, V events get cut out #4065

mkrueger opened this issue Feb 18, 2024 · 8 comments · May be fixed by #5615
Labels
bug Something is broken

Comments

@mkrueger
Copy link
Contributor

mkrueger commented Feb 18, 2024

They're replaced by cut/copy/paste commands.

Egui is the wrong layer for that - this is clearly an application feature and not a UI library one. I've an application that needs ctrl+x/c for input. With an event chain both events could be included however I would recommend not providing cut/copy/paste events in the first place. Don't know of any UI library handling that on this level.

Esp. applications may remap key binds that may break it. Or give some options to specify the behavior there.

@YgorSouza
Copy link
Contributor

Maybe it could be an opt-in feature? Apparently these events are only used internally by the text widgets, but I'm guessing a lot of people would like to have them by default and not have to implement them manually.

There's also undo and redo, which are not events but have hardcoded shortcuts in the TextEdit:

Event::Key {
key: Key::Z,
pressed: true,
modifiers,
..
} if modifiers.matches_logically(Modifiers::COMMAND) => {
if let Some((undo_ccursor_range, undo_txt)) = state
.undoer
.lock()
.undo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned()))
{
text.replace_with(undo_txt);
Some(*undo_ccursor_range)
} else {
None
}
}
Event::Key {
key,
pressed: true,
modifiers,
..
} if (modifiers.matches_logically(Modifiers::COMMAND) && *key == Key::Y)
|| (modifiers.matches_logically(Modifiers::SHIFT | Modifiers::COMMAND)
&& *key == Key::Z) =>
{
if let Some((redo_ccursor_range, redo_txt)) = state
.undoer
.lock()
.redo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned()))
{
text.replace_with(redo_txt);
Some(*redo_ccursor_range)
} else {
None
}
}

Maybe Copy/Cut/Paste could be handled the same way? And eventually with modifiable shortcuts you can set in the Ui's style or something like that.

@mkrueger
Copy link
Contributor Author

It's just some sort of programs that want to implement that manually - as said UI libs don't do that for reasons. This is more limiting in big programs, where you can remap commands.

@crumblingstatue
Copy link
Contributor

Didn't know this was a thing until now.
One workaround is doing ui.input(|inp| inp.events.iter().any(|ev| matches!(ev, egui::Event::Copy))), if you're simply interested in ctrl + c that egui "stole".

@mkrueger
Copy link
Contributor Author

mkrueger commented May 5, 2024

I know what a workaround is - it's just an unexpected behavior for a UI lib IMO.
Ctrl+C is an application layer thing IMO. With egui it would be possible to have two events in the chain - may be the better solution for this case.

@wareya
Copy link

wareya commented Nov 21, 2024

I'm making an image editor and the above-described workaround doesn't work for me, the paste event doesn't fire at all if image data is on the clipboard. I'm using a separate library (arboard) for clipboard data access so I don't need the data, just the fact that a ctrl+v happened. I'm calling events.iter().any(|ev| matches!(ev, egui::Event::Paste(_))).

@mkrueger
Copy link
Contributor Author

mkrueger commented Jan 17, 2025

... still a thing.

It's really in the way of making a non trivial program with egui :(.

There is no cut/copy/paste system event - so this is pure nonsens IMO. I need to handle clipboard with another library because I need a custom clipboard format so egui messes up the "paste" event - no way to "replace" the events since it tempers witih the clipboard.

@YgorSouza
Copy link
Contributor

It seems that the Copy and Cut events can be removed quite easily, by handling them like Undo and Redo as I mentioned above, but the Paste event contains the clipboard string, so that has to reach the TextEdit widget in another way if the event is removed.

I guess one quick thing that could be done would be to add a default_shortcuts bool to the Options struct. It is more or less in line with the other options there, like zoom_with_keyboard.

@mkrueger
Copy link
Contributor Author

A possible solution may be as well:
#5618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants