mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor(history): global state belongs in core
This commit is contained in:
parent
3a42011fd3
commit
5b5257034b
5 changed files with 19 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ impl Actor for Close {
|
||||||
let value = input.snap().value.clone();
|
let value = input.snap().value.clone();
|
||||||
if form.submit {
|
if form.submit {
|
||||||
if !input.obscure {
|
if !input.obscure {
|
||||||
yazi_widgets::input::INPUT_HISTORY.lock().unwrap().push(value.clone());
|
input.history.push(value.clone());
|
||||||
}
|
}
|
||||||
_ = tx.send(InputEvent::Submit(value));
|
_ = tx.send(InputEvent::Submit(value));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,25 @@
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
use yazi_config::popup::Position;
|
use yazi_config::popup::Position;
|
||||||
|
use yazi_shared::{data::Data, event::ActionCow};
|
||||||
|
|
||||||
#[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 visible: bool,
|
pub visible: bool,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub position: Position,
|
pub position: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Input {
|
||||||
|
pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
|
||||||
|
self.inner.execute(action, &mut self.history)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for Input {
|
impl Deref for Input {
|
||||||
type Target = yazi_widgets::input::Input;
|
type Target = yazi_widgets::input::Input;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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, InputMode};
|
use crate::input::{Input, InputHistory, InputMode};
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn execute(&mut self, action: ActionCow) -> Result<Data> {
|
pub fn execute(&mut self, action: ActionCow, history: &mut InputHistory) -> Result<Data> {
|
||||||
macro_rules! on {
|
macro_rules! on {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
if action.name == stringify!($name) {
|
if action.name == stringify!($name) {
|
||||||
|
|
@ -22,7 +22,9 @@ impl Input {
|
||||||
on!(r#move, "move");
|
on!(r#move, "move");
|
||||||
on!(backward);
|
on!(backward);
|
||||||
on!(forward);
|
on!(forward);
|
||||||
on!(history);
|
if action.name == "history" {
|
||||||
|
return self.history(action.into(), history);
|
||||||
|
}
|
||||||
|
|
||||||
match self.mode() {
|
match self.mode() {
|
||||||
InputMode::Normal => {
|
InputMode::Normal => {
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@ use anyhow::Result;
|
||||||
use yazi_macro::{render, succ};
|
use yazi_macro::{render, succ};
|
||||||
use yazi_shared::data::Data;
|
use yazi_shared::data::Data;
|
||||||
|
|
||||||
use crate::input::{INPUT_HISTORY, Input, InputOp, parser::HistoryOpt};
|
use crate::input::{Input, InputHistory, InputOp, parser::HistoryOpt};
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn history(&mut self, opt: HistoryOpt) -> Result<Data> {
|
pub fn history(&mut self, opt: HistoryOpt, history: &mut InputHistory) -> Result<Data> {
|
||||||
if self.snap().op != InputOp::None || self.obscure {
|
if self.snap().op != InputOp::None || self.obscure {
|
||||||
succ!();
|
succ!();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !INPUT_HISTORY.lock().unwrap().navigate(opt.offset, &mut self.snaps, self.limit) {
|
if !history.navigate(opt.offset, &mut self.snaps, self.limit) {
|
||||||
succ!();
|
succ!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
use std::{mem, sync::Mutex};
|
use std::mem;
|
||||||
|
|
||||||
use super::{InputMode, InputSnaps};
|
use super::{InputMode, InputSnaps};
|
||||||
|
|
||||||
pub static INPUT_HISTORY: Mutex<InputHistory> = Mutex::new(InputHistory::new());
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct InputHistory {
|
pub struct InputHistory {
|
||||||
entries: Vec<String>,
|
entries: Vec<String>,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue