mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
chore(history): move to core
also adds a new InputSnaps method to circumvent private methods
This commit is contained in:
parent
5526da0970
commit
6e1bc299f0
5 changed files with 20 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{collections::VecDeque, mem};
|
use std::{collections::VecDeque, mem};
|
||||||
|
|
||||||
use super::InputSnaps;
|
use yazi_widgets::input::InputSnaps;
|
||||||
|
|
||||||
// TODO: make configurable?
|
// TODO: make configurable?
|
||||||
const MAX_LENGTH: usize = 20;
|
const MAX_LENGTH: usize = 20;
|
||||||
|
|
@ -83,10 +83,7 @@ impl InputHistory {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Preserve mode and cursor position from before navigation
|
// Preserve mode and cursor position from before navigation
|
||||||
let snap = snaps.current_mut();
|
snaps.update_current(mode, cursor, limit);
|
||||||
snap.mode = mode;
|
|
||||||
snap.cursor = cursor.min(snap.count().saturating_sub(mode.delta()));
|
|
||||||
snap.resize(limit);
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -5,11 +5,12 @@ use yazi_config::popup::Position;
|
||||||
use yazi_macro::{render, succ};
|
use yazi_macro::{render, succ};
|
||||||
use yazi_shared::{data::Data, SStr};
|
use yazi_shared::{data::Data, SStr};
|
||||||
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
||||||
|
use crate::input::InputHistory;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
pub(super) inner: yazi_widgets::input::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 visible: bool,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
|
@ -17,9 +18,9 @@ pub struct Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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) {
|
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()
|
self.history.get_mut(&self.inner.id).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
yazi_macro::mod_flat!(input);
|
yazi_macro::mod_flat!(history input);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
yazi_macro::mod_pub!(actor parser);
|
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);
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,16 @@ impl InputSnaps {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn current_mut(&mut self) -> &mut InputSnap { &mut self.current }
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue