diff options
author | unrelentingtech | 2022-04-30 00:46:51 +0000 |
---|---|---|
committer | GitHub | 2022-04-30 00:46:51 +0000 |
commit | 2687b8fb3b3391b6104815afca47704187f22cb8 (patch) | |
tree | c0071be9361974d239601efa01009d2c72576e02 /helix-term/src/ui | |
parent | 010617337556d5f6ea93e42eff5f716215018231 (diff) |
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.
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/prompt.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index bd78ba63..165d87c7 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; } |