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:
parent
c0f75e1a17
commit
446d333515
1 changed files with 8 additions and 6 deletions
|
@ -45,12 +45,6 @@ impl SearchHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, cursor: &mut SearchHistoryCursor, search_string: String) {
|
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 self.insertion_behavior == QueryInsertionBehavior::ReplacePreviousIfContains {
|
||||||
if let Some(previously_searched) = self.history.back_mut() {
|
if let Some(previously_searched) = self.history.back_mut() {
|
||||||
if search_string.contains(previously_searched.as_str()) {
|
if search_string.contains(previously_searched.as_str()) {
|
||||||
|
@ -144,6 +138,14 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(search_history.current(&cursor), Some("rustlang"));
|
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
|
// push enough items to test SEARCH_HISTORY_LIMIT
|
||||||
for i in 0..MAX_HISTORY_LEN * 2 {
|
for i in 0..MAX_HISTORY_LEN * 2 {
|
||||||
search_history.add(&mut cursor, format!("item{i}"));
|
search_history.add(&mut cursor, format!("item{i}"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue