From 3f5b917c6ced370d940774b51ff89cec0d03c562 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 6 Apr 2021 09:03:37 +0530 Subject: draw grid and pixmap boundary separately --- src/command.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/command.rs') diff --git a/src/command.rs b/src/command.rs index f5a24c9..383389e 100644 --- a/src/command.rs +++ b/src/command.rs @@ -30,6 +30,32 @@ impl CommandBox { self.cursor = 0; } + pub fn cursor_back_word(&mut self) { + let mut prev_word_idx = 0; + { + let sl = &self.text[0..self.cursor]; + let idx = sl.rfind(|c: char| !c.is_alphanumeric() && c != '_'); + if let Some(i) = idx { + prev_word_idx = i; + } + } + self.cursor = prev_word_idx; + } + + pub fn cursor_forward_word(&mut self) { + let mut next_word_idx = self.cursor; + { + if self.cursor != self.text.len() { + let sl = &self.text[self.cursor..]; + let idx = sl.find(|c: char| !c.is_alphanumeric() && c != '_'); + if let Some(i) = idx { + next_word_idx = i; + } + } + } + self.cursor = next_word_idx; + } + pub fn backward(&mut self) { self.cursor = self.cursor.saturating_sub(1); } -- cgit v1.2.3