Skip to content

Commit

Permalink
feat: Support unyank
Browse files Browse the repository at this point in the history
There are two options to put the unyank ability:
- Option 1: Register a new command like in this CL
- Option 2: Add the unyank to the escape sequence, maybe after the escape_select.

I chose option 1 because the yank function is its own module but the escape
sequence belongs to the tab class. Option 2 is infeasible without touching the
module structure.

I just randomly choose a meaninful and unoccuped key binding for the `unyank`
function. Feel free to modify or remove it from the preset. I personally remap
the yank related functions to dance keys such as ["y" "y"].
  • Loading branch information
15cm committed Oct 24, 2023
1 parent 6a651f4 commit 62702c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions yazi-config/preset/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ keymap = [
{ 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 = [ "Y" ], exec = [ "unyank", "escape --visual --select" ], desc = "Remove the files from the yank clipboard" },
{ 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)" },
Expand Down
5 changes: 5 additions & 0 deletions yazi-core/src/manager/commands/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ impl Manager {
self.yanked.1 = self.selected().into_iter().map(|f| f.url()).collect();
true
}

pub fn unyank(&mut self) -> bool {
self.yanked = Default::default();
true
}
}
1 change: 1 addition & 0 deletions yazi-fm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Executor {
// Operation
"open" => cx.manager.open(exec.named.contains_key("interactive")),
"yank" => cx.manager.yank(exec.named.contains_key("cut")),
"unyank" => cx.manager.unyank(),
"paste" => {
let dest = cx.manager.cwd();
let (cut, ref src) = cx.manager.yanked;
Expand Down

0 comments on commit 62702c3

Please sign in to comment.