From 2687b8fb3b3391b6104815afca47704187f22cb8 Mon Sep 17 00:00:00 2001 From: unrelentingtech Date: Sat, 30 Apr 2022 03:46:51 +0300 Subject: [PATCH] feat(ui): treat slashes as word separators in prompt (#2315) When fiddling with paths in a :o prompt, one usually would want Ctrl-W to erase a path segment rather than the whole path. This is how Ctrl-W works in e.g. (neo)vim out of the box. --- helix-term/src/ui/prompt.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index bd78ba632..165d87c79 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -56,6 +56,10 @@ pub enum Movement { None, } +fn is_word_sep(c: char) -> bool { + c == std::path::MAIN_SEPARATOR || c.is_whitespace() +} + impl Prompt { pub fn new( prompt: Cow<'static, str>, @@ -118,7 +122,7 @@ impl Prompt { let mut found = None; for prev in (0..char_position - 1).rev() { - if char_indices[prev].1.is_whitespace() { + if is_word_sep(char_indices[prev].1) { found = Some(prev + 1); break; } @@ -141,14 +145,14 @@ impl Prompt { for _ in 0..rep { // Skip any non-whitespace characters while char_position < char_indices.len() - && !char_indices[char_position].1.is_whitespace() + && !is_word_sep(char_indices[char_position].1) { char_position += 1; } // Skip any whitespace characters while char_position < char_indices.len() - && char_indices[char_position].1.is_whitespace() + && is_word_sep(char_indices[char_position].1) { char_position += 1; }