Skip to content

Commit

Permalink
Fix Hinter implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Aug 3, 2021
1 parent 6e5a7c6 commit dbf7fd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/diy_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Hinter for DIYHinter {
type Hint = CommandHint;

fn hint(&self, line: &str, pos: usize, _ctx: &Context<'_>) -> Option<CommandHint> {
if pos < line.len() {
if line.is_empty() || pos < line.len() {
return None;
}

Expand All @@ -61,7 +61,7 @@ impl Hinter for DIYHinter {
.filter_map(|hint| {
// expect hint after word complete, like redis cli, add condition:
// line.ends_with(" ")
if pos > 0 && hint.display.starts_with(&line[..pos]) {
if hint.display.starts_with(line) {
Some(hint.suffix(pos))
} else {
None
Expand Down
6 changes: 3 additions & 3 deletions src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Hinter for HistoryHinter {
type Hint = String;

fn hint(&self, line: &str, pos: usize, ctx: &Context<'_>) -> Option<String> {
if pos < line.len() {
if line.is_empty() || pos < line.len() {
return None;
}
let start = if ctx.history_index() == ctx.history().len() {
Expand All @@ -66,9 +66,9 @@ impl Hinter for HistoryHinter {
};
if let Some(sr) = ctx
.history
.starts_with(&line[..pos], start, SearchDirection::Reverse)
.starts_with(line, start, SearchDirection::Reverse)
{
if sr.entry == line || sr.entry == &line[..pos] {
if sr.entry == line {
return None;
}
return Some(sr.entry[pos..].to_owned());
Expand Down

0 comments on commit dbf7fd0

Please sign in to comment.