From 34c6ec887dd165eeee60de344568080f6174a75a Mon Sep 17 00:00:00 2001 From: OliverGuy Date: Thu, 7 May 2026 23:56:41 +0200 Subject: [PATCH] fix(history): bounded size (scope): title --- yazi-widgets/src/input/history.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/yazi-widgets/src/input/history.rs b/yazi-widgets/src/input/history.rs index 48548c69..23259256 100644 --- a/yazi-widgets/src/input/history.rs +++ b/yazi-widgets/src/input/history.rs @@ -2,26 +2,38 @@ use std::mem; use super::InputSnaps; +// TODO: make configurable? +const MAX_LENGTH: usize = 20; + #[derive(Default)] pub struct InputHistory { - entries: Vec, - entry_snaps: Vec>, + entries: std::collections::VecDeque, + entry_snaps: std::collections::VecDeque>, idx: Option, draft: Option, } impl InputHistory { pub const fn new() -> Self { - Self { entries: Vec::new(), entry_snaps: Vec::new(), idx: None, draft: None } + Self { + entries: std::collections::VecDeque::new(), + entry_snaps: std::collections::VecDeque::new(), + idx: None, + draft: None, + } } pub fn push(&mut self, value: String) { if value.is_empty() { return; } - if self.entries.last().map(String::as_str) != Some(&value) { - self.entries.push(value); - self.entry_snaps.push(None); + if self.entries.back().map(String::as_str) != Some(&value) { + if self.entries.len() >= MAX_LENGTH { + self.entries.pop_front(); + self.entry_snaps.pop_front(); + } + self.entries.push_back(value); + self.entry_snaps.push_back(None); } self.reset(); }