Skip to content

Commit

Permalink
feat(ui): treat slashes as word separators in prompt (#2315)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valpackett authored Apr 30, 2022
1 parent 0106173 commit 2687b8f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 2687b8f

Please sign in to comment.