From 8e62b382fd1ac325fe7d4bc1777330ccb0e705e8 Mon Sep 17 00:00:00 2001 From: Benedikt Terhechte Date: Sat, 19 Feb 2022 10:42:43 +0100 Subject: [PATCH] Add some macOS emacs keybindings (#1243) Move cursor left: ^B Move cursor right: ^F Beginning of line: ^A End of line: ^E Line up: ^P Line down: ^N --- CHANGELOG.md | 1 + egui/src/widgets/text_edit/builder.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 636c3886a..fa7b174b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w ## Unreleased ### Added ⭐ +* Support a subset of macOS' emacs input field keybindings in `TextEdit` ([#1243](https://github.com/emilk/egui/pull/1243). * Much improved font selection ([#1154](https://github.com/emilk/egui/pull/1154)): * You can now select any font size and family using `RichText::size` amd `RichText::family` and the new `FontId`. * Easily change text styles with `Style::text_styles`. diff --git a/egui/src/widgets/text_edit/builder.rs b/egui/src/widgets/text_edit/builder.rs index 6dd52896f..8d6b6fb98 100644 --- a/egui/src/widgets/text_edit/builder.rs +++ b/egui/src/widgets/text_edit/builder.rs @@ -1092,11 +1092,31 @@ fn on_key_press( None } + Key::P | Key::N | Key::B | Key::F | Key::A | Key::E + if cfg!(target_os = "macos") && modifiers.ctrl && !modifiers.shift => + { + move_single_cursor(&mut cursor_range.primary, galley, key, modifiers); + cursor_range.secondary = cursor_range.primary; + None + } + _ => None, } } fn move_single_cursor(cursor: &mut Cursor, galley: &Galley, key: Key, modifiers: &Modifiers) { + if cfg!(target_os = "macos") && modifiers.ctrl && !modifiers.shift { + match key { + Key::A => *cursor = galley.cursor_begin_of_row(cursor), + Key::E => *cursor = galley.cursor_end_of_row(cursor), + Key::P => *cursor = galley.cursor_up_one_row(cursor), + Key::N => *cursor = galley.cursor_down_one_row(cursor), + Key::B => *cursor = galley.cursor_left_one_character(cursor), + Key::F => *cursor = galley.cursor_right_one_character(cursor), + _ => (), + } + return; + } match key { Key::ArrowLeft => { if modifiers.alt || modifiers.ctrl {