mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-19 14:51:42 +03:00
feat: cancel selected items automatically on entering, leaving, copying, or cutting (#273)
This commit is contained in:
parent
85b4892d40
commit
56cd3dc940
@ -52,7 +52,7 @@ impl Executor {
|
||||
|
||||
fn manager(cx: &mut Ctx, exec: &Exec) -> bool {
|
||||
match exec.cmd.as_str() {
|
||||
"escape" => cx.manager.active_mut().escape(),
|
||||
"escape" => cx.manager.active_mut().escape(exec),
|
||||
"quit" => cx.manager.quit(&cx.tasks, exec.named.contains_key("no-cwd-file")),
|
||||
"close" => cx.manager.close(&cx.tasks),
|
||||
"suspend" => cx.manager.suspend(),
|
||||
|
@ -19,8 +19,8 @@ keymap = [
|
||||
{ on = [ "<C-b>" ], exec = "arrow -100%", desc = "Move cursor up one page" },
|
||||
{ on = [ "<C-f>" ], exec = "arrow 100%", desc = "Move cursor down one page" },
|
||||
|
||||
{ on = [ "h" ], exec = "leave", desc = "Go back to the parent directory" },
|
||||
{ on = [ "l" ], exec = "enter", desc = "Enter the child directory" },
|
||||
{ on = [ "h" ], exec = [ "leave", "escape --visual --select" ], desc = "Go back to the parent directory" },
|
||||
{ on = [ "l" ], exec = [ "enter", "escape --visual --select" ], desc = "Enter the child directory" },
|
||||
|
||||
{ on = [ "H" ], exec = "back", desc = "Go back to the previous directory" },
|
||||
{ on = [ "L" ], exec = "forward", desc = "Go forward to the next directory" },
|
||||
@ -44,28 +44,28 @@ keymap = [
|
||||
{ on = [ "<C-r>" ], exec = "select_all --state=none", desc = "Inverse selection of all files" },
|
||||
|
||||
# Operation
|
||||
{ on = [ "o" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "O" ], exec = "open --interactive", desc = "Open the selected files interactively" },
|
||||
{ on = [ "<Enter>" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "<C-Enter>" ], exec = "open --interactive", desc = "Open the selected files interactively" }, # It's cool if you're using a terminal that supports CSI u
|
||||
{ on = [ "y" ], exec = "yank", desc = "Copy the selected files" },
|
||||
{ on = [ "x" ], exec = "yank --cut", desc = "Cut the selected files" },
|
||||
{ on = [ "p" ], exec = "paste", desc = "Paste the files" },
|
||||
{ on = [ "P" ], exec = "paste --force", desc = "Paste the files (overwrite if the destination exists)" },
|
||||
{ on = [ "-" ], exec = "link", desc = "Symlink the absolute path of files" },
|
||||
{ on = [ "_" ], exec = "link --relative", desc = "Symlink the relative path of files" },
|
||||
{ on = [ "d" ], exec = "remove", desc = "Move the files to the trash" },
|
||||
{ on = [ "D" ], exec = "remove --permanently", desc = "Permanently delete the files" },
|
||||
{ on = [ "a" ], exec = "create", desc = "Create a file or directory (ends with / for directories)" },
|
||||
{ on = [ "r" ], exec = "rename", desc = "Rename a file or directory" },
|
||||
{ on = [ ";" ], exec = "shell", desc = "Run a shell command" },
|
||||
{ on = [ ":" ], exec = "shell --block", desc = "Run a shell command (block the UI until the command finishes)" },
|
||||
{ on = [ "." ], exec = "hidden toggle", desc = "Toggle the visibility of hidden files" },
|
||||
{ on = [ "s" ], exec = "search fd", desc = "Search files by name using fd" },
|
||||
{ on = [ "S" ], exec = "search rg", desc = "Search files by content using ripgrep" },
|
||||
{ on = [ "<C-s>" ], exec = "search none", desc = "Cancel the ongoing search" },
|
||||
{ on = [ "z" ], exec = "jump zoxide", desc = "Jump to a directory using zoxide" },
|
||||
{ on = [ "Z" ], exec = "jump fzf", desc = "Jump to a directory, or reveal a file using fzf" },
|
||||
{ on = [ "o" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "O" ], exec = "open --interactive", desc = "Open the selected files interactively" },
|
||||
{ on = [ "<Enter>" ], exec = "open", desc = "Open the selected files" },
|
||||
{ on = [ "<C-Enter>" ], exec = "open --interactive", desc = "Open the selected files interactively" },
|
||||
{ on = [ "y" ], exec = [ "yank", "escape --visual --select" ], desc = "Copy the selected files" },
|
||||
{ on = [ "x" ], exec = [ "yank --cut", "escape --visual --select" ], desc = "Cut the selected files" },
|
||||
{ on = [ "p" ], exec = "paste", desc = "Paste the files" },
|
||||
{ on = [ "P" ], exec = "paste --force", desc = "Paste the files (overwrite if the destination exists)" },
|
||||
{ on = [ "-" ], exec = "link", desc = "Symlink the absolute path of files" },
|
||||
{ on = [ "_" ], exec = "link --relative", desc = "Symlink the relative path of files" },
|
||||
{ on = [ "d" ], exec = [ "remove", "escape --visual --select" ], desc = "Move the files to the trash" },
|
||||
{ on = [ "D" ], exec = [ "remove --permanently", "escape --visual --select" ], desc = "Permanently delete the files" },
|
||||
{ on = [ "a" ], exec = "create", desc = "Create a file or directory (ends with / for directories)" },
|
||||
{ on = [ "r" ], exec = "rename", desc = "Rename a file or directory" },
|
||||
{ on = [ ";" ], exec = "shell", desc = "Run a shell command" },
|
||||
{ on = [ ":" ], exec = "shell --block", desc = "Run a shell command (block the UI until the command finishes)" },
|
||||
{ on = [ "." ], exec = "hidden toggle", desc = "Toggle the visibility of hidden files" },
|
||||
{ on = [ "s" ], exec = "search fd", desc = "Search files by name using fd" },
|
||||
{ on = [ "S" ], exec = "search rg", desc = "Search files by content using ripgrep" },
|
||||
{ on = [ "<C-s>" ], exec = "search none", desc = "Cancel the ongoing search" },
|
||||
{ on = [ "z" ], exec = "jump zoxide", desc = "Jump to a directory using zoxide" },
|
||||
{ on = [ "Z" ], exec = "jump fzf", desc = "Jump to a directory, or reveal a file using fzf" },
|
||||
|
||||
# Copy
|
||||
{ on = [ "c", "c" ], exec = "copy path", desc = "Copy the absolute path" },
|
||||
|
@ -7,13 +7,3 @@ mod refresh;
|
||||
mod rename;
|
||||
mod suspend;
|
||||
mod yank;
|
||||
|
||||
pub use close::*;
|
||||
pub use create::*;
|
||||
pub use open::*;
|
||||
pub use peek::*;
|
||||
pub use quit::*;
|
||||
pub use refresh::*;
|
||||
pub use rename::*;
|
||||
pub use suspend::*;
|
||||
pub use yank::*;
|
||||
|
@ -1,21 +1,64 @@
|
||||
use config::keymap::Exec;
|
||||
|
||||
use crate::tab::{Mode, Tab};
|
||||
|
||||
impl Tab {
|
||||
pub fn escape(&mut self) -> bool {
|
||||
if self.finder.take().is_some() {
|
||||
return true;
|
||||
}
|
||||
pub struct Opt(u8);
|
||||
|
||||
impl From<&Exec> for Opt {
|
||||
fn from(e: &Exec) -> Self {
|
||||
Self(e.named.iter().fold(0, |acc, (k, _)| match k.as_str() {
|
||||
"all" => 0b1111,
|
||||
"find" => acc | 0b0001,
|
||||
"visual" => acc | 0b0010,
|
||||
"select" => acc | 0b0100,
|
||||
"search" => acc | 0b1000,
|
||||
_ => acc,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl Tab {
|
||||
#[inline]
|
||||
fn escape_find(&mut self) -> bool { self.finder.take().is_some() }
|
||||
|
||||
#[inline]
|
||||
fn escape_visual(&mut self) -> bool {
|
||||
if let Some((_, indices)) = self.mode.visual() {
|
||||
self.current.files.select_index(indices, Some(self.mode.is_select()));
|
||||
self.mode = Mode::Normal;
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
if self.select_all(Some(false)) {
|
||||
return true;
|
||||
#[inline]
|
||||
fn escape_select(&mut self) -> bool { self.select_all(Some(false)) }
|
||||
|
||||
#[inline]
|
||||
fn escape_search(&mut self) -> bool { self.search_stop() }
|
||||
|
||||
pub fn escape(&mut self, opt: impl Into<Opt>) -> bool {
|
||||
let opt = opt.into();
|
||||
if opt.0 == 0 {
|
||||
return self.escape_find()
|
||||
|| self.escape_visual()
|
||||
|| self.escape_select()
|
||||
|| self.escape_search();
|
||||
}
|
||||
|
||||
self.search_stop()
|
||||
let mut b = false;
|
||||
if opt.0 & 0b0001 != 0 {
|
||||
b |= self.escape_find();
|
||||
}
|
||||
if opt.0 & 0b0010 != 0 {
|
||||
b |= self.escape_visual();
|
||||
}
|
||||
if opt.0 & 0b0100 != 0 {
|
||||
b |= self.escape_select();
|
||||
}
|
||||
if opt.0 & 0b1000 != 0 {
|
||||
b |= self.escape_search();
|
||||
}
|
||||
b
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,3 @@ mod search;
|
||||
mod select;
|
||||
mod shell;
|
||||
mod visual_mode;
|
||||
|
||||
pub use arrow::*;
|
||||
pub use backstack::*;
|
||||
pub use cd::*;
|
||||
pub use copy::*;
|
||||
pub use enter::*;
|
||||
pub use escape::*;
|
||||
pub use find::*;
|
||||
pub use jump::*;
|
||||
pub use leave::*;
|
||||
pub use search::*;
|
||||
pub use select::*;
|
||||
pub use shell::*;
|
||||
pub use visual_mode::*;
|
||||
|
Loading…
Reference in New Issue
Block a user