Skip to content

Commit

Permalink
Cancel DragValue edit if Escape is pressed (emilk#4713)
Browse files Browse the repository at this point in the history
Since Escape takes focus away from the text field, it makes more sense
for it to cancel the change rather than confirm it.

This only matters if `update_while_editing` is set to false, of course.
  • Loading branch information
YgorSouza authored and hacknus committed Oct 30, 2024
1 parent b9094e1 commit bcfa166
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a> Widget for DragValue<'a> {

let text_style = ui.style().drag_value_text_style.clone();

if ui.memory(|mem| mem.lost_focus(id)) {
if ui.memory(|mem| mem.lost_focus(id)) && !ui.input(|i| i.key_pressed(Key::Escape)) {
let value_text = ui.data_mut(|data| data.remove_temp::<String>(id));
if let Some(value_text) = value_text {
// We were editing the value as text last frame, but lost focus.
Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a> Widget for DragValue<'a> {
response.changed()
} else {
// Update only when the edit has lost focus.
response.lost_focus()
response.lost_focus() && !ui.input(|i| i.key_pressed(Key::Escape))
};
if update {
let parsed_value = match &custom_parser {
Expand Down

0 comments on commit bcfa166

Please sign in to comment.