yazi/yazi-core/src/input/commands/escape.rs
2024-09-21 20:12:35 +08:00

38 lines
719 B
Rust

use yazi_proxy::CompletionProxy;
use yazi_shared::{event::Cmd, render};
use crate::input::{Input, InputMode, op::InputOp};
pub struct Opt;
impl From<Cmd> for Opt {
fn from(_: Cmd) -> Self { Self }
}
impl From<()> for Opt {
fn from(_: ()) -> Self { Self }
}
impl Input {
pub fn escape(&mut self, _: impl Into<Opt>) {
let snap = self.snap_mut();
match snap.mode {
InputMode::Normal if snap.op == InputOp::None => {
self.close(false);
}
InputMode::Normal => {
snap.op = InputOp::None;
}
InputMode::Insert => {
snap.mode = InputMode::Normal;
self.move_(-1);
if self.completion {
CompletionProxy::close();
}
}
}
self.snaps.tag(self.limit());
render!();
}
}