refactor(history): move actor to core

This commit is contained in:
OliverGuy 2026-05-07 19:50:34 +02:00
parent 5b5257034b
commit 7b6fca136f
4 changed files with 28 additions and 31 deletions

View file

@ -2,30 +2,49 @@ 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_shared::{data::Data, event::ActionCow}; use yazi_shared::{data::Data, event::ActionCow};
use yazi_widgets::input::{InputOp, parser::HistoryOpt};
#[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: yazi_widgets::input::InputHistory, pub history: yazi_widgets::input::InputHistory,
pub visible: bool, pub visible: bool,
pub title: String, pub title: String,
pub position: Position, pub position: Position,
} }
impl Input { impl Input {
pub fn execute(&mut self, action: ActionCow) -> Result<Data> { pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
self.inner.execute(action, &mut self.history) if action.name == "history" {
return self.history(action.into());
}
self.inner.execute(action)
}
pub fn 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!();
}
succ!(render!());
} }
} }
impl Deref for Input { impl Deref for Input {
type Target = yazi_widgets::input::Input; type Target = yazi_widgets::input::Input;
fn deref(&self) -> &Self::Target { &self.inner } fn deref(&self) -> &Self::Target {
&self.inner
}
} }
impl DerefMut for Input { impl DerefMut for Input {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
} }

View file

@ -2,10 +2,10 @@ use anyhow::Result;
use yazi_macro::{act, succ}; use yazi_macro::{act, succ};
use yazi_shared::{data::Data, event::ActionCow}; use yazi_shared::{data::Data, event::ActionCow};
use crate::input::{Input, InputHistory, InputMode}; use crate::input::{Input, InputMode};
impl Input { impl Input {
pub fn execute(&mut self, action: ActionCow, history: &mut InputHistory) -> Result<Data> { pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
macro_rules! on { macro_rules! on {
($name:ident) => { ($name:ident) => {
if action.name == stringify!($name) { if action.name == stringify!($name) {
@ -22,9 +22,6 @@ impl Input {
on!(r#move, "move"); on!(r#move, "move");
on!(backward); on!(backward);
on!(forward); on!(forward);
if action.name == "history" {
return self.history(action.into(), history);
}
match self.mode() { match self.mode() {
InputMode::Normal => { InputMode::Normal => {

View file

@ -1,19 +0,0 @@
use anyhow::Result;
use yazi_macro::{render, succ};
use yazi_shared::data::Data;
use crate::input::{Input, InputHistory, InputOp, parser::HistoryOpt};
impl Input {
pub fn history(&mut self, opt: HistoryOpt, history: &mut InputHistory) -> Result<Data> {
if self.snap().op != InputOp::None || self.obscure {
succ!();
}
if !history.navigate(opt.offset, &mut self.snaps, self.limit) {
succ!();
}
succ!(render!());
}
}

View file

@ -1 +1 @@
yazi_macro::mod_flat!(actor backspace backward casefy complete delete escape forward history insert kill paste r#move r#type redo replace undo visual yank); yazi_macro::mod_flat!(actor backspace backward casefy complete delete escape forward insert kill paste r#move r#type redo replace undo visual yank);