yazi_core/input/commands/
delete.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use yazi_macro::render;
use yazi_shared::event::CmdCow;

use crate::input::{Input, op::InputOp};

struct Opt {
	cut:    bool,
	insert: bool,
}

impl From<CmdCow> for Opt {
	fn from(c: CmdCow) -> Self { Self { cut: c.bool("cut"), insert: c.bool("insert") } }
}

impl Input {
	#[yazi_codegen::command]
	pub fn delete(&mut self, opt: Opt) {
		match self.snap().op {
			InputOp::None => {
				self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, self.snap().cursor);
			}
			InputOp::Select(start) => {
				self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, start);
				render!(self.handle_op(self.snap().cursor, true));
				self.move_(0);
			}
			InputOp::Delete(..) => {
				self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, 0);
				self.move_(self.snap().len() as isize);
			}
			_ => {}
		}
	}
}