From 6fe8ebe496520f0cadd1728051342aaf386b541a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nerma?= Date: Thu, 7 Dec 2023 17:31:15 +0100 Subject: [PATCH] Fix: last problems with `FileBackedHistory` --- src/history/cursor.rs | 6 ++++++ src/history/file_backed.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/history/cursor.rs b/src/history/cursor.rs index 43c68508..8cb7e0b3 100644 --- a/src/history/cursor.rs +++ b/src/history/cursor.rs @@ -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")?; @@ -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(()) } diff --git a/src/history/file_backed.rs b/src/history/file_backed.rs index 52bfc47b..72a0e4c6 100644 --- a/src/history/file_backed.rs +++ b/src/history/file_backed.rs @@ -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());