mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor(history): use executor
This commit is contained in:
parent
8338ba2690
commit
ffd0d9b219
6 changed files with 24 additions and 9 deletions
17
yazi-actor/src/input/history.rs
Normal file
17
yazi-actor/src/input/history.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use yazi_shared::data::Data;
|
||||||
|
use yazi_widgets::input::parser::HistoryOpt;
|
||||||
|
|
||||||
|
use crate::{Actor, Ctx};
|
||||||
|
|
||||||
|
pub struct History;
|
||||||
|
|
||||||
|
impl Actor for History {
|
||||||
|
type Form = HistoryOpt;
|
||||||
|
|
||||||
|
const NAME: &str = "history";
|
||||||
|
|
||||||
|
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
|
||||||
|
cx.input.navigate_history(form)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1 +1 @@
|
||||||
yazi_macro::mod_flat!(close complete escape show);
|
yazi_macro::mod_flat!(close complete escape history show);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::ops::{Deref, DerefMut};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use yazi_config::popup::Position;
|
use yazi_config::popup::Position;
|
||||||
use yazi_macro::{render, succ};
|
use yazi_macro::{render, succ};
|
||||||
use yazi_shared::{data::Data, event::ActionCow, SStr};
|
use yazi_shared::{data::Data, SStr};
|
||||||
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -17,13 +17,6 @@ pub struct Input {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
|
|
||||||
if action.name == "history" {
|
|
||||||
return self.navigate_history(action.into());
|
|
||||||
}
|
|
||||||
self.inner.execute(action)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn history(&mut self) -> &mut yazi_widgets::input::InputHistory {
|
pub fn history(&mut self) -> &mut yazi_widgets::input::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(), yazi_widgets::input::InputHistory::new());
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,7 @@ impl<'a> Executor<'a> {
|
||||||
on!(escape);
|
on!(escape);
|
||||||
on!(show);
|
on!(show);
|
||||||
on!(close);
|
on!(close);
|
||||||
|
on!(history);
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
InputMode::Normal => {
|
InputMode::Normal => {
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ pub enum Spark<'a> {
|
||||||
InputEscape(crate::VoidForm),
|
InputEscape(crate::VoidForm),
|
||||||
InputForward(yazi_widgets::input::parser::ForwardOpt),
|
InputForward(yazi_widgets::input::parser::ForwardOpt),
|
||||||
InputInsert(yazi_widgets::input::parser::InsertOpt),
|
InputInsert(yazi_widgets::input::parser::InsertOpt),
|
||||||
|
InputHistory(yazi_widgets::input::parser::HistoryOpt),
|
||||||
InputKill(yazi_widgets::input::parser::KillOpt),
|
InputKill(yazi_widgets::input::parser::KillOpt),
|
||||||
InputMove(yazi_widgets::input::parser::MoveOpt),
|
InputMove(yazi_widgets::input::parser::MoveOpt),
|
||||||
InputPaste(yazi_widgets::input::parser::PasteOpt),
|
InputPaste(yazi_widgets::input::parser::PasteOpt),
|
||||||
|
|
@ -310,6 +311,7 @@ impl<'a> IntoLua for Spark<'a> {
|
||||||
Self::InputEscape(b) => b.into_lua(lua),
|
Self::InputEscape(b) => b.into_lua(lua),
|
||||||
Self::InputForward(b) => b.into_lua(lua),
|
Self::InputForward(b) => b.into_lua(lua),
|
||||||
Self::InputInsert(b) => b.into_lua(lua),
|
Self::InputInsert(b) => b.into_lua(lua),
|
||||||
|
Self::InputHistory(b) => b.into_lua(lua),
|
||||||
Self::InputKill(b) => b.into_lua(lua),
|
Self::InputKill(b) => b.into_lua(lua),
|
||||||
Self::InputMove(b) => b.into_lua(lua),
|
Self::InputMove(b) => b.into_lua(lua),
|
||||||
Self::InputPaste(b) => b.into_lua(lua),
|
Self::InputPaste(b) => b.into_lua(lua),
|
||||||
|
|
@ -448,6 +450,7 @@ try_from_spark!(crate::which::ActivateForm, which:activate);
|
||||||
try_from_spark!(yazi_dds::Payload<'a>, app:accept_payload);
|
try_from_spark!(yazi_dds::Payload<'a>, app:accept_payload);
|
||||||
try_from_spark!(yazi_widgets::input::InputOpt, input:show);
|
try_from_spark!(yazi_widgets::input::InputOpt, input:show);
|
||||||
try_from_spark!(yazi_widgets::input::parser::BackspaceOpt, input:backspace);
|
try_from_spark!(yazi_widgets::input::parser::BackspaceOpt, input:backspace);
|
||||||
|
try_from_spark!(yazi_widgets::input::parser::HistoryOpt, input:history);
|
||||||
try_from_spark!(yazi_widgets::input::parser::BackwardOpt, input:backward);
|
try_from_spark!(yazi_widgets::input::parser::BackwardOpt, input:backward);
|
||||||
try_from_spark!(yazi_widgets::input::parser::CompleteOpt, input:complete);
|
try_from_spark!(yazi_widgets::input::parser::CompleteOpt, input:complete);
|
||||||
try_from_spark!(yazi_widgets::input::parser::DeleteOpt, input:delete);
|
try_from_spark!(yazi_widgets::input::parser::DeleteOpt, input:delete);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
use crate::input::InputMode;
|
||||||
use super::InputSnap;
|
use super::InputSnap;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue