debugger: Fix debug console persist to history when reusing a previous item (#34893)

Closes #34887

Release Notes:

- Debugger: Fix debug console persist to history when reusing a previous
item
This commit is contained in:
Remco Smits 2025-07-22 21:40:11 +02:00 committed by GitHub
parent c0f75e1a17
commit 446d333515
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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}"));