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

Split hinter tokens at Unicode word boundaries #650

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
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
Next Next commit
Split hinter tokens at Unicode word boundaries
Partial completion behaves now like usual word movements by C-Left and C-Right.
stfacc committed Oct 28, 2023
commit 80f07daf5174252bd13620a93de9d697cd5cd4f4
16 changes: 11 additions & 5 deletions src/hinter/cwd_aware.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@
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

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
///
@@ -66,17 +71,18 @@
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

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

Codecov / codecov/patch

src/hinter/cwd_aware.rs#L83-L85

Added lines #L83 - L85 were not covered by tests
result
}
}
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

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 {
@@ -50,17 +55,18 @@
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

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

Codecov / codecov/patch

src/hinter/default.rs#L67-L69

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