Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): treat slashes as word separators in prompt #2315

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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