diff --git a/src/hinter/cwd_aware.rs b/src/hinter/cwd_aware.rs index bed5f5d9..2777dfe9 100644 --- a/src/hinter/cwd_aware.rs +++ b/src/hinter/cwd_aware.rs @@ -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) +} /// A hinter that uses the completions or the history to show a hint to the user /// @@ -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, (true, false) => true, - (false, true) => true, (false, false) => { reached_content = true; true } }) - .collect(); + .collect::>() + .join("") + .to_string(); result } } diff --git a/src/hinter/default.rs b/src/hinter/default.rs index 87955198..12e9e3db 100644 --- a/src/hinter/default.rs +++ b/src/hinter/default.rs @@ -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) +} /// A hinter that uses the completions or the history to show a hint to the user pub struct DefaultHinter { @@ -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, (true, false) => true, - (false, true) => true, (false, false) => { reached_content = true; true } }) - .collect(); + .collect::>() + .join("") + .to_string(); result } }