chore(history): move to core

also adds a new InputSnaps method to circumvent private methods
This commit is contained in:
OliverGuy 2026-05-18 20:00:01 +02:00
parent 5526da0970
commit 6e1bc299f0
5 changed files with 20 additions and 10 deletions

View file

@ -1,6 +1,6 @@
use std::{collections::VecDeque, mem};
use super::InputSnaps;
use yazi_widgets::input::InputSnaps;
// TODO: make configurable?
const MAX_LENGTH: usize = 20;
@ -83,10 +83,7 @@ impl InputHistory {
};
// Preserve mode and cursor position from before navigation
let snap = snaps.current_mut();
snap.mode = mode;
snap.cursor = cursor.min(snap.count().saturating_sub(mode.delta()));
snap.resize(limit);
snaps.update_current(mode, cursor, limit);
true
}

View file

@ -5,11 +5,12 @@ use yazi_config::popup::Position;
use yazi_macro::{render, succ};
use yazi_shared::{data::Data, SStr};
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
use crate::input::InputHistory;
#[derive(Default)]
pub struct Input {
pub(super) inner: yazi_widgets::input::Input,
pub history: std::collections::HashMap<SStr, yazi_widgets::input::InputHistory>,
pub history: std::collections::HashMap<SStr, InputHistory>,
pub visible: bool,
pub title: String,
@ -17,9 +18,9 @@ pub struct Input {
}
impl Input {
pub fn history(&mut self) -> &mut yazi_widgets::input::InputHistory {
pub fn history(&mut self) -> &mut InputHistory {
if !self.history.contains_key(&self.inner.id) {
self.history.insert(self.inner.id.clone(), yazi_widgets::input::InputHistory::new());
self.history.insert(self.inner.id.clone(), InputHistory::new());
}
self.history.get_mut(&self.inner.id).unwrap()
}

View file

@ -1 +1 @@
yazi_macro::mod_flat!(input);
yazi_macro::mod_flat!(history input);

View file

@ -1,3 +1,3 @@
yazi_macro::mod_pub!(actor parser);
yazi_macro::mod_flat!(event history input mode op option snap snaps widget);
yazi_macro::mod_flat!(event input mode op option snap snaps widget);

View file

@ -77,4 +77,16 @@ impl InputSnaps {
#[inline]
pub(super) fn current_mut(&mut self) -> &mut InputSnap { &mut self.current }
/// Updates the current snap.
///
/// * `mode`: New mode to use.
/// * `cursor`: Cursor position.
/// * `limit`: New size of the snap.
pub fn update_current(&mut self, mode: InputMode, cursor: usize, limit: usize) {
let snap = self.current_mut();
snap.mode = mode;
snap.cursor = cursor.min(snap.count().saturating_sub(mode.delta()));
snap.resize(limit);
}
}