mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix(history): bounded size
(scope): title
This commit is contained in:
parent
c5658c40c9
commit
34c6ec887d
1 changed files with 18 additions and 6 deletions
|
|
@ -2,26 +2,38 @@ use std::mem;
|
||||||
|
|
||||||
use super::InputSnaps;
|
use super::InputSnaps;
|
||||||
|
|
||||||
|
// TODO: make configurable?
|
||||||
|
const MAX_LENGTH: usize = 20;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct InputHistory {
|
pub struct InputHistory {
|
||||||
entries: Vec<String>,
|
entries: std::collections::VecDeque<String>,
|
||||||
entry_snaps: Vec<Option<InputSnaps>>,
|
entry_snaps: std::collections::VecDeque<Option<InputSnaps>>,
|
||||||
idx: Option<usize>,
|
idx: Option<usize>,
|
||||||
draft: Option<InputSnaps>,
|
draft: Option<InputSnaps>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputHistory {
|
impl InputHistory {
|
||||||
pub const fn new() -> Self {
|
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) {
|
pub fn push(&mut self, value: String) {
|
||||||
if value.is_empty() {
|
if value.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if self.entries.last().map(String::as_str) != Some(&value) {
|
if self.entries.back().map(String::as_str) != Some(&value) {
|
||||||
self.entries.push(value);
|
if self.entries.len() >= MAX_LENGTH {
|
||||||
self.entry_snaps.push(None);
|
self.entries.pop_front();
|
||||||
|
self.entry_snaps.pop_front();
|
||||||
|
}
|
||||||
|
self.entries.push_back(value);
|
||||||
|
self.entry_snaps.push_back(None);
|
||||||
}
|
}
|
||||||
self.reset();
|
self.reset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue