Skip to content

Commit

Permalink
Fix: last problems with FileBackedHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Dec 7, 2023
1 parent 9cc5d90 commit 6fe8ebe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/history/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ mod tests {
#[test]
fn prefix_search_ignores_consecutive_equivalent_entries_going_forwards() -> Result<()> {
let (mut hist, _) = create_history();

save_from_command_line(hist.as_mut(), "find me once")?;
save_from_command_line(hist.as_mut(), "test")?;
save_from_command_line(hist.as_mut(), "find me once")?;
Expand All @@ -331,21 +332,26 @@ mod tests {
HistoryNavigationQuery::PrefixSearch("find".to_string()),
None,
);

cursor.back(&*hist)?;
assert_eq!(
cursor.string_at_cursor(),
Some("find me as well".to_string())
);

cursor.back(&*hist)?;
cursor.back(&*hist)?;
assert_eq!(cursor.string_at_cursor(), Some("find me once".to_string()));

cursor.forward(&*hist)?;
assert_eq!(
cursor.string_at_cursor(),
Some("find me as well".to_string())
);

cursor.forward(&*hist)?;
assert_eq!(cursor.string_at_cursor(), None);

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/history/file_backed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl History for FileBackedHistory {
if self.entries.len() == self.capacity {
// History is "full", so we delete the oldest entry first,
// before adding a new one.
self.entries.remove(&HistoryItemId(0));
self.entries.shift_remove(&HistoryItemId(0));
}

self.entries.insert(h.id, entry.to_string());
Expand Down

0 comments on commit 6fe8ebe

Please sign in to comment.