Skip to content

Commit 7a51626

Browse files
committed
feat: drag and drop (#4005)
1 parent cf8b541 commit 7a51626

52 files changed

Lines changed: 784 additions & 173 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
1414

1515
### Added
1616

17+
- Drag and drop ([#4005])
1718
- Bulk create ([#3793])
1819
- Image preview with Überzug++ on Niri ([#3990])
1920

@@ -1729,3 +1730,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/):
17291730
[#3943]: https://github.com/sxyazi/yazi/pull/3943
17301731
[#3989]: https://github.com/sxyazi/yazi/pull/3989
17311732
[#3990]: https://github.com/sxyazi/yazi/pull/3990
1733+
[#4005]: https://github.com/sxyazi/yazi/pull/4005

Cargo.lock

Lines changed: 20 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Yazi (means "duck") is a terminal file manager written in Rust, based on non-blo
2424
- 💫 Vim-like input/pick/confirm/which/notify component, auto-completion for cd paths
2525
- 🏷️ Multi-Tab Support, Cross-directory selection, Scrollable Preview (for videos, PDFs, archives, code, directories, etc.)
2626
- 🔄 Bulk Rename/Create, Archive Extraction, Visual Mode, File Chooser, [Git Integration](https://github.com/yazi-rs/plugins/tree/main/git.yazi), [Mount Manager](https://github.com/yazi-rs/plugins/tree/main/mount.yazi)
27-
- 🎨 Theme System, Mouse Support, Trash Bin, Custom Layouts, CSI u, OSC 52
27+
- 🎨 Theme System, Mouse Support, Drag and Drop, Trash Bin, Custom Layouts, CSI u, OSC 52
2828
- ... and more!
2929

3030
https://github.com/sxyazi/yazi/assets/17523360/92ff23fa-0cd5-4f04-b387-894c12265cc7

cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit","lockin","rposition","resvg","foldhash","tilded","futs","chdir","hashbrown","JEMALLOC","RUSTFLAGS","RDONLY","GETPATH","fcntl","casefold","inodes","Splatable","casefied","thiserror","memchr","memmem","russh","deadpool","keepalive","nodelay","publickey","deadpool","initing","treelize","TOCTOU","fellback","watchee","Textlike","sstr","pointee","writef","wakeup","nonblocking","sigwinch","timespec","termios","tcgetattr","tcsetattr","tcgetwinsize","rustix","codepoint","codepoints","Raterm","mimetypes"],"language":"en","version":"0.2"}
1+
{"version":"0.2","language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit","lockin","rposition","resvg","foldhash","tilded","futs","chdir","hashbrown","JEMALLOC","RUSTFLAGS","RDONLY","GETPATH","fcntl","casefold","inodes","Splatable","casefied","thiserror","memchr","memmem","russh","deadpool","keepalive","nodelay","publickey","deadpool","initing","treelize","TOCTOU","fellback","watchee","Textlike","sstr","pointee","writef","wakeup","nonblocking","sigwinch","timespec","termios","tcgetattr","tcsetattr","tcgetwinsize","rustix","codepoint","codepoints","Raterm","mimetypes","Mimelist"]}

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/yazi-unwrapped.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ rustPlatform.buildRustPackage (finalAttrs: {
2828

2929
cargoLock = {
3030
lockFile = "${src}/Cargo.lock";
31-
#outputHashes = {
32-
# "mlua-0.10.0" = "sha256-Xg6/jc+UP8tbJJ6x1sbAgt8ZHt051xEBBcjmikQqYlw=";
33-
#};
3431
};
3532

3633
env = {

yazi-actor/src/app/dnd.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use anyhow::Result;
2+
use mlua::{ObjectLike, Table};
3+
use tracing::error;
4+
use yazi_actor::lives::Lives;
5+
use yazi_binding::runtime_scope;
6+
use yazi_macro::succ;
7+
use yazi_parser::app::DndForm;
8+
use yazi_plugin::LUA;
9+
use yazi_shared::data::Data;
10+
11+
use crate::{Actor, Ctx};
12+
13+
pub struct Dnd;
14+
15+
impl Actor for Dnd {
16+
type Form = DndForm;
17+
18+
const NAME: &str = "dnd";
19+
20+
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
21+
let event = yazi_binding::DndEvent::from(form.event);
22+
23+
let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() };
24+
let area = yazi_binding::elements::Rect::from(size);
25+
26+
let result = Lives::scope(cx.core, move || {
27+
runtime_scope!(LUA, "root", {
28+
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;
29+
30+
if event.is_drag() {
31+
root.call_method::<()>("drag", event)?;
32+
} else {
33+
root.call_method::<()>("drop", event)?;
34+
}
35+
36+
Ok(())
37+
})
38+
});
39+
40+
if let Err(ref e) = result {
41+
error!("{e}");
42+
}
43+
succ!(result?);
44+
}
45+
}

yazi-actor/src/app/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ yazi_macro::mod_flat!(
22
accept_payload
33
bootstrap
44
deprecate
5+
dnd
56
focus
67
lua
78
mouse

yazi-actor/src/app/mouse.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ impl Actor for Mouse {
2525
let area = yazi_binding::elements::Rect::from(size);
2626

2727
let result = Lives::scope(cx.core, move || {
28-
let root = runtime_scope!(LUA, "root", {
29-
LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)
30-
})?;
28+
runtime_scope!(LUA, "root", {
29+
let root = LUA.globals().raw_get::<Table>("Root")?.call_method::<Table>("new", area)?;
3130

32-
match event.kind {
33-
MouseEventKind::Down(_) => root.call_method("click", (event, false))?,
34-
MouseEventKind::Up(_) => root.call_method("click", (event, true))?,
31+
match event.kind {
32+
MouseEventKind::Down(_) => root.call_method("click", (event, false))?,
33+
MouseEventKind::Up(_) => root.call_method("click", (event, true))?,
3534

36-
MouseEventKind::ScrollDown => root.call_method("scroll", (event, 1))?,
37-
MouseEventKind::ScrollUp => root.call_method("scroll", (event, -1))?,
35+
MouseEventKind::ScrollDown => root.call_method("scroll", (event, 1))?,
36+
MouseEventKind::ScrollUp => root.call_method("scroll", (event, -1))?,
3837

39-
MouseEventKind::ScrollRight => root.call_method("touch", (event, 1))?,
40-
MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?,
38+
MouseEventKind::ScrollRight => root.call_method("touch", (event, 1))?,
39+
MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?,
4140

42-
MouseEventKind::Moved => root.call_method("move", event)?,
43-
MouseEventKind::Drag(_) => root.call_method("drag", event)?,
44-
}
41+
MouseEventKind::Moved => root.call_method("move", event)?,
42+
MouseEventKind::Drag(_) => root.call_method("drag", event)?,
43+
}
4544

46-
Ok(())
45+
Ok(())
46+
})
4747
});
4848

4949
if let Err(ref e) = result {

yazi-actor/src/tasks/spawn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl Actor for Spawn {
1515

1616
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
1717
succ!(match form.opt {
18+
TaskOpt::Cut(r#in) => cx.tasks.scheduler.file_cut(r#in),
1819
TaskOpt::Plugin(r#in) => cx.tasks.scheduler.plugin_entry(r#in),
1920
})
2021
}

0 commit comments

Comments
 (0)