Skip to content

Commit

Permalink
Split hinter tokens at Unicode word boundaries
Browse files Browse the repository at this point in the history
Partial completion behaves now like usual word movements by C-Left and C-Right.
  • Loading branch information
stfacc committed Oct 28, 2023
1 parent 973dbb5 commit 80f07da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/hinter/cwd_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ use crate::{
Hinter, History,
};
use nu_ansi_term::{Color, Style};
use unicode_segmentation::UnicodeSegmentation;

pub fn is_whitespace_str(s: &str) -> bool {
s.chars().all(char::is_whitespace)
}

Check warning on line 11 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L9-L11

Added lines #L9 - L11 were not covered by tests

/// A hinter that uses the completions or the history to show a hint to the user
///
Expand Down Expand Up @@ -66,17 +71,18 @@ impl Hinter for CwdAwareHinter {
let mut reached_content = false;
let result: String = self
.current_hint
.chars()
.take_while(|c| match (c.is_whitespace(), reached_content) {
(true, true) => false,
.split_word_bounds()
.take_while(|word| match (is_whitespace_str(word), reached_content) {
(_, true) => false,

Check warning on line 76 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L74-L76

Added lines #L74 - L76 were not covered by tests
(true, false) => true,
(false, true) => true,
(false, false) => {
reached_content = true;
true
}
})
.collect();
.collect::<Vec<&str>>()
.join("")
.to_string();

Check warning on line 85 in src/hinter/cwd_aware.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L83-L85

Added lines #L83 - L85 were not covered by tests
result
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/hinter/default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use crate::{history::SearchQuery, Hinter, History};
use nu_ansi_term::{Color, Style};
use unicode_segmentation::UnicodeSegmentation;

pub fn is_whitespace_str(s: &str) -> bool {
s.chars().all(char::is_whitespace)
}

Check warning on line 7 in src/hinter/default.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/default.rs#L5-L7

Added lines #L5 - L7 were not covered by tests

/// A hinter that uses the completions or the history to show a hint to the user
pub struct DefaultHinter {
Expand Down Expand Up @@ -50,17 +55,18 @@ impl Hinter for DefaultHinter {
let mut reached_content = false;
let result: String = self
.current_hint
.chars()
.take_while(|c| match (c.is_whitespace(), reached_content) {
(true, true) => false,
.split_word_bounds()
.take_while(|word| match (is_whitespace_str(word), reached_content) {
(_, true) => false,

Check warning on line 60 in src/hinter/default.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/default.rs#L58-L60

Added lines #L58 - L60 were not covered by tests
(true, false) => true,
(false, true) => true,
(false, false) => {
reached_content = true;
true
}
})
.collect();
.collect::<Vec<&str>>()
.join("")
.to_string();

Check warning on line 69 in src/hinter/default.rs

View check run for this annotation

Codecov / codecov/patch

src/hinter/default.rs#L67-L69

Added lines #L67 - L69 were not covered by tests
result
}
}
Expand Down

0 comments on commit 80f07da

Please sign in to comment.