From 4adcbf6784745774fb52919c97e67716e92670aa Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 20 Oct 2023 10:25:46 -0600 Subject: [PATCH] Editor: add SoftHome action to skip blank space --- src/edit/editor.rs | 11 +++++++++++ src/edit/mod.rs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/edit/editor.rs b/src/edit/editor.rs index 274e05b..1e8d325 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -426,6 +426,17 @@ impl Edit for Editor { self.set_layout_cursor(font_system, cursor); self.cursor_x_opt = None; } + Action::SoftHome => { + let line: &mut BufferLine = &mut self.buffer.lines[self.cursor.line]; + self.cursor.index = line + .text() + .unicode_word_indices() + .map(|(i, _)| i) + .next() + .unwrap_or(0); + self.buffer.set_redraw(true); + self.cursor_x_opt = None; + } Action::End => { let mut cursor = self.buffer.layout_cursor(&self.cursor); cursor.glyph = usize::max_value(); diff --git a/src/edit/mod.rs b/src/edit/mod.rs index 1c16746..a3173a7 100644 --- a/src/edit/mod.rs +++ b/src/edit/mod.rs @@ -35,6 +35,8 @@ pub enum Action { Down, /// Move cursor to start of line Home, + /// Move cursor to start of line, skipping whitespace + SoftHome, /// Move cursor to end of line End, /// Move cursor to start of paragraph