mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Press enter in single line TextEdit to surrender keyboard focus
This commit is contained in:
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed 🔧
|
||||||
|
|
||||||
|
* Pressing enter in a single-line `TextEdit` will now surrender keyboard focus for it
|
||||||
|
|
||||||
### Fixed 🐛
|
### Fixed 🐛
|
||||||
|
|
||||||
* Fixed bug where a lost widget could still retain keyboard focus.
|
* Fixed bug where a lost widget could still retain keyboard focus.
|
||||||
|
|||||||
@@ -169,6 +169,10 @@ impl<'t> Widget for TextEdit<'t> {
|
|||||||
} => {
|
} => {
|
||||||
if multiline {
|
if multiline {
|
||||||
insert_text(&mut cursor, text, "\n");
|
insert_text(&mut cursor, text, "\n");
|
||||||
|
} else {
|
||||||
|
// Common to end input with enter
|
||||||
|
ui.memory().surrender_kb_focus(id);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Key {
|
Event::Key {
|
||||||
@@ -176,6 +180,7 @@ impl<'t> Widget for TextEdit<'t> {
|
|||||||
pressed: true,
|
pressed: true,
|
||||||
} => {
|
} => {
|
||||||
ui.memory().surrender_kb_focus(id);
|
ui.memory().surrender_kb_focus(id);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Event::Key { key, pressed: true } => {
|
Event::Key { key, pressed: true } => {
|
||||||
on_key_press(&mut cursor, text, *key);
|
on_key_press(&mut cursor, text, *key);
|
||||||
|
|||||||
Reference in New Issue
Block a user