Change summary
crates/project/src/search_history.rs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
Detailed changes
@@ -45,12 +45,6 @@ impl SearchHistory {
}
pub fn add(&mut self, cursor: &mut SearchHistoryCursor, search_string: String) {
- if let Some(selected_ix) = cursor.selection {
- if self.history.get(selected_ix) == Some(&search_string) {
- return;
- }
- }
-
if self.insertion_behavior == QueryInsertionBehavior::ReplacePreviousIfContains {
if let Some(previously_searched) = self.history.back_mut() {
if search_string.contains(previously_searched.as_str()) {
@@ -144,6 +138,14 @@ mod tests {
);
assert_eq!(search_history.current(&cursor), Some("rustlang"));
+ // add item when it equals to current item if it's not the last one
+ search_history.add(&mut cursor, "php".to_string());
+ search_history.previous(&mut cursor);
+ assert_eq!(search_history.current(&cursor), Some("rustlang"));
+ search_history.add(&mut cursor, "rustlang".to_string());
+ assert_eq!(search_history.history.len(), 3, "Should add item");
+ assert_eq!(search_history.current(&cursor), Some("rustlang"));
+
// push enough items to test SEARCH_HISTORY_LIMIT
for i in 0..MAX_HISTORY_LEN * 2 {
search_history.add(&mut cursor, format!("item{i}"));