Skip to content

Commit 90d08b7

Browse files
committed
Use escape key to exit editing
The escape key can now be used to exit edit mode. In writing a todo, this will also cancel the new todo.
1 parent 557de9d commit 90d08b7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,14 @@ fn main() {
410410
if editing {
411411
ui.edit_field(todo, &mut editing_cursor, x / 2);
412412

413-
if let Some('\n') = ui.key.take().map(|x| x as u8 as char) {
414-
editing = false;
413+
match ui.key.take().map(|x| x as u8 as char) {
414+
Some('\n') => editing = false,
415+
Some('\u{1b}') => {
416+
editing = false;
417+
list_delete(&mut todos, &mut todo_curr);
418+
break;
419+
}
420+
_ => {}
415421
}
416422
} else {
417423
ui.label_fixed_width(
@@ -483,7 +489,9 @@ fn main() {
483489
if editing {
484490
ui.edit_field(done, &mut editing_cursor, x / 2);
485491

486-
if let Some('\n') = ui.key.take().map(|x| x as u8 as char) {
492+
if let Some('\n') | Some('\u{1b}') =
493+
ui.key.take().map(|x| x as u8 as char)
494+
{
487495
editing = false;
488496
}
489497
} else {

0 commit comments

Comments
 (0)