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();
|
||||
if form.submit {
|
||||
if !input.obscure {
|
||||
yazi_widgets::input::INPUT_HISTORY.lock().unwrap().push(value.clone());
|
||||
input.history.push(value.clone());
|
||||
}
|
||||
_ = tx.send(InputEvent::Submit(value));
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,25 @@
|
|||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use anyhow::Result;
|
||||
use yazi_config::popup::Position;
|
||||
use yazi_shared::{data::Data, event::ActionCow};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Input {
|
||||
pub(super) inner: yazi_widgets::input::Input,
|
||||
pub history: yazi_widgets::input::InputHistory,
|
||||
|
||||
pub visible: bool,
|
||||
pub title: String,
|
||||
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 {
|
||||
type Target = yazi_widgets::input::Input;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use anyhow::Result;
|
|||
use yazi_macro::{act, succ};
|
||||
use yazi_shared::{data::Data, event::ActionCow};
|
||||
|
||||
use crate::input::{Input, InputMode};
|
||||
use crate::input::{Input, InputHistory, InputMode};
|
||||
|
||||
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 {
|
||||
($name:ident) => {
|
||||
if action.name == stringify!($name) {
|
||||
|
|
@ -22,7 +22,9 @@ impl Input {
|
|||
on!(r#move, "move");
|
||||
on!(backward);
|
||||
on!(forward);
|
||||
on!(history);
|
||||
if action.name == "history" {
|
||||
return self.history(action.into(), history);
|
||||
}
|
||||
|
||||
match self.mode() {
|
||||
InputMode::Normal => {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@ use anyhow::Result;
|
|||
use yazi_macro::{render, succ};
|
||||
use yazi_shared::data::Data;
|
||||
|
||||
use crate::input::{INPUT_HISTORY, Input, InputOp, parser::HistoryOpt};
|
||||
use crate::input::{Input, InputHistory, InputOp, parser::HistoryOpt};
|
||||
|
||||
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 {
|
||||
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!();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
use std::{mem, sync::Mutex};
|
||||
use std::mem;
|
||||
|
||||
use super::{InputMode, InputSnaps};
|
||||
|
||||
pub static INPUT_HISTORY: Mutex<InputHistory> = Mutex::new(InputHistory::new());
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct InputHistory {
|
||||
entries: Vec<String>,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue