mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat(history): separate history by input id
This commit is contained in:
parent
7b6fca136f
commit
473415300d
5 changed files with 28 additions and 6 deletions
|
|
@ -22,7 +22,7 @@ impl Actor for Close {
|
|||
let value = input.snap().value.clone();
|
||||
if form.submit {
|
||||
if !input.obscure {
|
||||
input.history.push(value.clone());
|
||||
input.history().push(value.clone());
|
||||
}
|
||||
_ = tx.send(InputEvent::Submit(value));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ pub struct InputCfg {
|
|||
pub position: Position,
|
||||
pub realtime: bool,
|
||||
pub completion: bool,
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
|
@ -37,6 +38,7 @@ impl InputCfg {
|
|||
value: if cwd.kind().is_local() { String::new() } else { EncodeScheme(cwd).to_string() },
|
||||
position: Position::new(YAZI.input.cd_origin, YAZI.input.cd_offset),
|
||||
completion: true,
|
||||
id: "cd".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +47,7 @@ impl InputCfg {
|
|||
Self {
|
||||
title: YAZI.input.create_title[dir as usize].clone(),
|
||||
position: Position::new(YAZI.input.create_origin, YAZI.input.create_offset),
|
||||
id: "create".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +56,7 @@ impl InputCfg {
|
|||
Self {
|
||||
title: YAZI.input.rename_title.clone(),
|
||||
position: Position::new(YAZI.input.rename_origin, YAZI.input.rename_offset),
|
||||
id: "rename".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +66,7 @@ impl InputCfg {
|
|||
title: YAZI.input.filter_title.clone(),
|
||||
position: Position::new(YAZI.input.filter_origin, YAZI.input.filter_offset),
|
||||
realtime: true,
|
||||
id: "filter".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -79,6 +84,7 @@ impl InputCfg {
|
|||
Self {
|
||||
title: YAZI.input.search_title.replace("{n}", name),
|
||||
position: Position::new(YAZI.input.search_origin, YAZI.input.search_offset),
|
||||
id: "search".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +93,7 @@ impl InputCfg {
|
|||
Self {
|
||||
title: YAZI.input.shell_title[block as usize].clone(),
|
||||
position: Position::new(YAZI.input.shell_origin, YAZI.input.shell_offset),
|
||||
id: "shell".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
@ -100,6 +107,7 @@ impl InputCfg {
|
|||
width: 50,
|
||||
height: 3,
|
||||
}),
|
||||
id: "tab_rename".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
|||
#[derive(Default)]
|
||||
pub struct Input {
|
||||
pub(super) inner: yazi_widgets::input::Input,
|
||||
pub history: yazi_widgets::input::InputHistory,
|
||||
pub history: std::collections::HashMap<String, yazi_widgets::input::InputHistory>,
|
||||
|
||||
pub visible: bool,
|
||||
pub title: String,
|
||||
|
|
@ -19,17 +19,28 @@ pub struct Input {
|
|||
impl Input {
|
||||
pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
|
||||
if action.name == "history" {
|
||||
return self.history(action.into());
|
||||
return self.navigate_history(action.into());
|
||||
}
|
||||
self.inner.execute(action)
|
||||
}
|
||||
|
||||
pub fn history(&mut self, opt: HistoryOpt) -> Result<Data> {
|
||||
pub fn history(&mut self) -> &mut yazi_widgets::input::InputHistory {
|
||||
if !self.history.contains_key(&self.inner.id) {
|
||||
self.history.insert(self.inner.id.clone(), yazi_widgets::input::InputHistory::new());
|
||||
}
|
||||
self.history.get_mut(&self.inner.id).unwrap()
|
||||
}
|
||||
pub fn navigate_history(&mut self, opt: HistoryOpt) -> Result<Data> {
|
||||
if self.inner.snap().op != InputOp::None || self.inner.obscure {
|
||||
succ!();
|
||||
}
|
||||
if !self.history.navigate(opt.offset, &mut self.inner.snaps, self.inner.limit) {
|
||||
succ!();
|
||||
match self.history.get_mut(&self.inner.id) {
|
||||
Some(history) => {
|
||||
if !history.navigate(opt.offset, &mut self.inner.snaps, self.inner.limit) {
|
||||
succ!();
|
||||
}
|
||||
}
|
||||
None => succ!(),
|
||||
}
|
||||
succ!(render!());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ impl Utils {
|
|||
position: t.raw_get::<Pos>("pos")?.with_height(3).into(),
|
||||
realtime,
|
||||
completion: false,
|
||||
id: t.raw_get("id").unwrap_or_default(),
|
||||
}));
|
||||
|
||||
if !realtime {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub struct Input {
|
|||
pub obscure: bool,
|
||||
pub realtime: bool,
|
||||
pub completion: bool,
|
||||
pub id: String,
|
||||
|
||||
pub tx: Option<mpsc::UnboundedSender<InputEvent>>,
|
||||
pub ticket: Ids,
|
||||
|
|
@ -32,6 +33,7 @@ impl Input {
|
|||
obscure: opt.cfg.obscure,
|
||||
realtime: opt.cfg.realtime,
|
||||
completion: opt.cfg.completion,
|
||||
id: opt.cfg.id,
|
||||
|
||||
tx: Some(opt.tx),
|
||||
..Default::default()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue