mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor(history): move actor to core
This commit is contained in:
parent
5b5257034b
commit
7b6fca136f
4 changed files with 28 additions and 31 deletions
|
|
@ -2,7 +2,9 @@ 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 {
|
||||||
|
|
@ -16,16 +18,33 @@ pub struct Input {
|
||||||
|
|
||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 => {
|
||||||
|
|
|
||||||
|
|
@ -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!());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue