From f9afdfa1431420ddabae5247f2ff4ab970eb05a2 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 5 Sep 2021 11:11:31 +0200 Subject: [PATCH] TextEdit: left/right arrows move cursor to start/end of selection Closes https://github.com/emilk/egui/issues/611 --- egui/src/widgets/text_edit.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index da8e6e5c..6f00003f 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -1135,6 +1135,15 @@ fn on_key_press( Some(CCursorPair::one(ccursor)) } + Key::ArrowLeft | Key::ArrowRight if modifiers.is_none() && !cursorp.is_empty() => { + if key == Key::ArrowLeft { + *cursorp = CursorPair::one(cursorp.sorted()[0]); + } else { + *cursorp = CursorPair::one(cursorp.sorted()[1]); + } + None + } + Key::ArrowLeft | Key::ArrowRight | Key::ArrowUp | Key::ArrowDown | Key::Home | Key::End => { move_single_cursor(&mut cursorp.primary, galley, key, modifiers); if !modifiers.shift {