Skip to content

Commit

Permalink
Ignore duplicate search results for PrefixReverseSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
oberien committed Oct 31, 2020
1 parent 9df4d3c commit 9b558c8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> {
) {
self.ctx.history_index = history_index;
let buf = history.get(history_index).unwrap();

// if the history search results in the same command we found last, continue searching
// for a different command
if buf == self.line.as_str() {
return self.edit_history_search(dir, keep_cursor_pos);
}

let pos = if keep_cursor_pos {
self.line.pos()
} else {
Expand Down Expand Up @@ -781,6 +788,8 @@ mod test {
history.add("bar");
history.add("cd abcdef");
history.add("ls");
history.add("cd abcdef");
history.add("ls");
history.add("cd ab123");
history.add("ls");
let line = "cd abxyz";
Expand All @@ -791,12 +800,12 @@ mod test {

s.edit_history_next(true).unwrap();
assert_eq!(line, s.saved_line_for_history.as_str());
assert_eq!(4, s.ctx.history_index);
assert_eq!(6, s.ctx.history_index);
assert_eq!("cd ab123", s.line.as_str());

s.edit_history_next(true).unwrap();
assert_eq!(line, s.saved_line_for_history.as_str());
assert_eq!(2, s.ctx.history_index);
assert_eq!(4, s.ctx.history_index);
assert_eq!("cd abcdef", s.line.as_str());

s.edit_history_next(true).unwrap();
Expand All @@ -811,12 +820,12 @@ mod test {

s.edit_history_next(false).unwrap();
assert_eq!(line, s.saved_line_for_history.as_str());
assert_eq!(4, s.ctx.history_index);
assert_eq!(6, s.ctx.history_index);
assert_eq!("cd ab123", s.line.as_str());

s.edit_history_next(false).unwrap();
// assert_eq!(line, s.saved_line_for_history.as_str());
assert_eq!(6, s.ctx.history.len());
assert_eq!(8, s.ctx.history.len());
assert_eq!(line, s.line.as_str());
}
}

0 comments on commit 9b558c8

Please sign in to comment.