on master help sign in
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.

commit2687b8fb3b3391b6104815afca47704187f22cb8 authorunrelentingtech <greg@unrelenting.technology> dateSat 30 Apr 2022, 03:46 (5 years ago) parent0106173
1 file changed+7−3
helix-term/src/ui/prompt.rs+7−3
helix-term/src/ui/prompt.rs+7−3
@@ -56,6 +56,10 @@ pub enum Movement {
5656 None,
5757}
5858
59+fn is_word_sep(c: char) -> bool {
60+ c == std::path::MAIN_SEPARATOR || c.is_whitespace()
61+}
62+
5963impl Prompt {
6064 pub fn new(
6165 prompt: Cow<'static, str>,
@@ -118,7 +122,7 @@ impl Prompt {
118122
119123 let mut found = None;
120124 for prev in (0..char_position - 1).rev() {
121− if char_indices[prev].1.is_whitespace() {
125+ if is_word_sep(char_indices[prev].1) {
122126 found = Some(prev + 1);
123127 break;
124128 }
@@ -141,14 +145,14 @@ impl Prompt {
141145 for _ in 0..rep {
142146 // Skip any non-whitespace characters
143147 while char_position < char_indices.len()
144− && !char_indices[char_position].1.is_whitespace()
148+ && !is_word_sep(char_indices[char_position].1)
145149 {
146150 char_position += 1;
147151 }
148152
149153 // Skip any whitespace characters
150154 while char_position < char_indices.len()
151− && char_indices[char_position].1.is_whitespace()
155+ && is_word_sep(char_indices[char_position].1)
152156 {
153157 char_position += 1;
154158 }