yazi_widgets/input/commands/
commands.rs

1use anyhow::Result;
2use yazi_macro::{act, succ};
3use yazi_shared::{data::Data, event::CmdCow};
4
5use crate::input::{Input, InputMode};
6
7impl Input {
8	pub fn execute(&mut self, cmd: CmdCow) -> Result<Data> {
9		macro_rules! on {
10			($name:ident) => {
11				if cmd.name == stringify!($name) {
12					return act!($name, self, cmd);
13				}
14			};
15			($name:ident, $alias:literal) => {
16				if cmd.name == $alias {
17					return act!($name, self, cmd);
18				}
19			};
20		}
21
22		on!(r#move, "move");
23		on!(backward);
24		on!(forward);
25
26		match self.mode() {
27			InputMode::Normal => {
28				on!(insert);
29				on!(visual);
30				on!(replace);
31
32				on!(delete);
33				on!(yank);
34				on!(paste);
35
36				on!(undo);
37				on!(redo);
38
39				on!(casefy);
40			}
41			InputMode::Insert => {
42				on!(visual);
43
44				on!(backspace);
45				on!(kill);
46			}
47			InputMode::Replace => {}
48		}
49
50		succ!();
51	}
52}