1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Split Event::Text into Text and Paste (#1058)

* Split `Event::Text` into `Text` and `Paste`

* Added explicit Event::Paste change

See #1043

* Link to PR in changelog (not the issue)

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Simon Werner
2022-01-11 11:12:30 +13:00
committed by GitHub
parent 650057dd4a
commit 225d2b506d
5 changed files with 15 additions and 3 deletions

View File

@@ -148,7 +148,9 @@ pub enum Event {
Copy,
/// The integration detected a "cut" event (e.g. Cmd+X).
Cut,
/// Text input, e.g. via keyboard or paste action.
/// The integration detected a "paste" event (e.g. Cmd+V).
Paste(String),
/// Text input, e.g. via keyboard.
///
/// When the user presses enter/return, do not send a `Text` (just [`Key::Enter`]).
Text(String),

View File

@@ -684,6 +684,15 @@ fn events(
Some(CCursorRange::one(delete_selected(text, &cursor_range)))
}
}
Event::Paste(text_to_insert) => {
if !text_to_insert.is_empty() {
let mut ccursor = delete_selected(text, &cursor_range);
insert_text(&mut ccursor, text, text_to_insert);
Some(CCursorRange::one(ccursor))
} else {
None
}
}
Event::Text(text_to_insert) => {
// Newlines are handled by `Key::Enter`.
if !text_to_insert.is_empty() && text_to_insert != "\n" && text_to_insert != "\r" {