Skip to content

Commit 4fb16a9

Browse files
qsdrqssxyazi
authored andcommitted
feat: support mouse event
1 parent e4d6712 commit 4fb16a9

File tree

31 files changed

+396
-19
lines changed

31 files changed

+396
-19
lines changed

Cargo.lock

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

yazi-adaptor/src/chafa.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl Chafa {
5353
height: lines.len() as u16,
5454
};
5555

56+
Adaptor::Chafa.image_hide()?;
5657
Adaptor::shown_store(area);
5758
Emulator::move_lock((max.x, max.y), |stderr| {
5859
for (i, line) in lines.into_iter().enumerate() {

yazi-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ yazi-shared = { path = "../yazi-shared", version = "0.2.5" }
1414
# External dependencies
1515
anyhow = "1.0.86"
1616
arc-swap = "1.7.1"
17+
bitflags = "2.5.0"
1718
crossterm = "0.27.0"
1819
globset = "0.4.14"
1920
indexmap = "2.2.6"

yazi-config/preset/yazi.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ linemode = "none"
1313
show_hidden = false
1414
show_symlink = true
1515
scrolloff = 5
16+
mouse_events = [ "click", "scroll" ]
1617

1718
[preview]
1819
tab_size = 2
@@ -86,10 +87,8 @@ fetchers = [
8687
]
8788
preloaders = [
8889
# Image
89-
{ mime = "image/svg+xml", run = "magick" },
90-
{ mime = "image/heic", run = "magick" },
91-
{ mime = "image/jxl", run = "magick" },
92-
{ mime = "image/*", run = "image" },
90+
{ mime = "image/{heic,jxl,svg+xml}", run = "magick" },
91+
{ mime = "image/*", run = "image" },
9392
# Video
9493
{ mime = "video/*", run = "video" },
9594
# PDF
@@ -106,10 +105,8 @@ previewers = [
106105
# JSON
107106
{ mime = "application/json", run = "json" },
108107
# Image
109-
{ mime = "image/svg+xml", run = "magick" },
110-
{ mime = "image/heic", run = "magick" },
111-
{ mime = "image/jxl", run = "magick" },
112-
{ mime = "image/*", run = "image" },
108+
{ mime = "image/{heic,jxl,svg+xml}", run = "magick" },
109+
{ mime = "image/*", run = "image" },
113110
# Video
114111
{ mime = "video/*", run = "video" },
115112
# PDF

yazi-config/src/manager/manager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use validator::Validate;
33

4-
use super::{ManagerRatio, SortBy};
4+
use super::{ManagerRatio, MouseEvents, SortBy};
55
use crate::{validation::check_validation, MERGED_YAZI};
66

77
#[derive(Debug, Deserialize, Serialize, Validate)]
@@ -21,6 +21,7 @@ pub struct Manager {
2121
pub show_hidden: bool,
2222
pub show_symlink: bool,
2323
pub scrolloff: u8,
24+
pub mouse_events: MouseEvents,
2425
}
2526

2627
impl Default for Manager {

yazi-config/src/manager/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mod manager;
2+
mod mouse;
23
mod ratio;
34
mod sorting;
45

56
pub use manager::*;
7+
pub use mouse::*;
68
pub use ratio::*;
79
pub use sorting::*;

yazi-config/src/manager/mouse.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use anyhow::{bail, Result};
2+
use bitflags::bitflags;
3+
use crossterm::event::MouseEventKind;
4+
use serde::{Deserialize, Serialize};
5+
6+
bitflags! {
7+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
8+
#[serde(try_from = "Vec<String>", into = "Vec<String>")]
9+
pub struct MouseEvents: u8 {
10+
const CLICK = 0b00001;
11+
const SCROLL = 0b00010;
12+
const TOUCH = 0b00100;
13+
const MOVE = 0b01000;
14+
const DRAG = 0b10000;
15+
}
16+
}
17+
18+
impl MouseEvents {
19+
#[inline]
20+
pub const fn draggable(self) -> bool { self.contains(Self::DRAG) }
21+
}
22+
23+
impl TryFrom<Vec<String>> for MouseEvents {
24+
type Error = anyhow::Error;
25+
26+
fn try_from(value: Vec<String>) -> Result<Self, Self::Error> {
27+
value.into_iter().try_fold(Self::empty(), |aac, s| {
28+
Ok(match s.as_str() {
29+
"click" => aac | Self::CLICK,
30+
"scroll" => aac | Self::SCROLL,
31+
"touch" => aac | Self::TOUCH,
32+
"move" => aac | Self::MOVE,
33+
"drag" => aac | Self::DRAG,
34+
_ => bail!("Invalid mouse event: {s}"),
35+
})
36+
})
37+
}
38+
}
39+
40+
impl From<MouseEvents> for Vec<String> {
41+
fn from(value: MouseEvents) -> Self {
42+
let events = [
43+
(MouseEvents::CLICK, "click"),
44+
(MouseEvents::SCROLL, "scroll"),
45+
(MouseEvents::TOUCH, "touch"),
46+
(MouseEvents::MOVE, "move"),
47+
(MouseEvents::DRAG, "drag"),
48+
];
49+
events.into_iter().filter(|v| value.contains(v.0)).map(|v| v.1.to_owned()).collect()
50+
}
51+
}
52+
53+
impl From<crossterm::event::MouseEventKind> for MouseEvents {
54+
fn from(value: crossterm::event::MouseEventKind) -> Self {
55+
match value {
56+
MouseEventKind::Down(_) | MouseEventKind::Up(_) => Self::CLICK,
57+
MouseEventKind::ScrollDown | MouseEventKind::ScrollUp => Self::SCROLL,
58+
MouseEventKind::ScrollLeft | MouseEventKind::ScrollRight => Self::TOUCH,
59+
MouseEventKind::Moved => Self::MOVE,
60+
MouseEventKind::Drag(_) => Self::DRAG,
61+
}
62+
}
63+
}

yazi-core/src/manager/commands/update_files.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ impl Manager {
111111
|(p, pp)| matches!(*op, FilesOp::Deleting(ref parent, ref urls) if *parent == pp && urls.contains(p)),
112112
);
113113

114-
if let Some(f) = tab.history.get_mut(op.url()) {
115-
let hovered = f.hovered().filter(|_| f.tracing).map(|h| h.url());
116-
_ = f.update(op.into_owned()) && f.repos(hovered);
114+
let folder = tab.history.entry(op.url().clone()).or_insert_with(|| Folder::from(op.url()));
115+
let hovered = folder.hovered().filter(|_| folder.tracing).map(|h| h.url());
116+
if folder.update(op.into_owned()) {
117+
folder.repos(hovered);
117118
}
118119

119120
if leave {

yazi-fm/src/app/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl App {
5656
Event::Seq(cmds, layer) => self.dispatch_seq(cmds, layer),
5757
Event::Render => self.dispatch_render(),
5858
Event::Key(key) => self.dispatch_key(key),
59+
Event::Mouse(mouse) => self.mouse(mouse),
5960
Event::Resize => self.resize(()),
6061
Event::Paste(str) => self.dispatch_paste(str),
6162
Event::Quit(opt) => self.quit(opt),

yazi-fm/src/app/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod accept_payload;
2+
mod mouse;
23
mod notify;
34
mod plugin;
45
mod quit;

0 commit comments

Comments
 (0)