-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Attempt to add basic mouse support #1038
base: main
Are you sure you want to change the base?
Conversation
Thank you for the awesome work! Mouse support is a feature I've been wanting to add for a while, and I'm very happy to see it implemented now! It definitely deserves a separate version to be released ;) |
Here are some change requests:
And the
When the event type is |
How to deal with |
I've updated the comment |
I've finished the requested change, could you have a look at it? |
@@ -12,6 +12,7 @@ linemode = "none" | |||
show_hidden = false | |||
show_symlink = true | |||
scrolloff = 5 | |||
mouse = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mouse = true | |
mouse_events = [ "click", "scroll" ] |
This allows us to selectively ignore certain minor events, such as touch
, move
, drag
, which can be manually enabled by the user when needed. Due to the high frequency of move
events, this would be a significant optimization.
@@ -20,6 +20,7 @@ pub struct Manager { | |||
pub show_hidden: bool, | |||
pub show_symlink: bool, | |||
pub scrolloff: u8, | |||
pub mouse: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub mouse: bool, | |
pub mouse: MouseEvents, |
MouseEvents
looks like:
bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[serde(try_from = "Vec<String>")]
pub struct MouseEvents: u8 {
const CLICK = 0b00001;
const SCROLL = 0b00010;
const TOUCH = 0b00100;
const MOVE = 0b01000;
const DRAG = 0b10000;
}
}
You can check out
yazi/yazi-config/src/popup/offset.rs
Line 13 in 28dfe72
impl TryFrom<Vec<i16>> for Offset { |
for implementing it.
Hi. Thanks for this amazing project! This is an attempt to add mouse support to yazi. I make it as a draft PR because I think it still needs tasks to be done before it can be merged. But I would appreciate it if I could get some early feedback from reviewing and help me to know what is the next step.
This PR tries to enable capturing
MouseEvent
in the terminal and spawn it to theApp
struct, thenApp
will try to dispatch this event and route this event to themouse
method in different components (Header
,Manager
, andStatus
), based on coordination comparison between mouse event andRect
fromLayout
. TheManager
is a special case. Because inLAYOUT
,Manager
is divided intoCurrent
,Parent
andPreview
. So I create a newenum ManagerComponent
to indicate which specific component in Manager this MouseEvent belongs to and pass it as an argument. Themouse
method will finally encapsulate theMouseEvent
as lua object and invoke the correspondingmouse
method in lua field.In the lua field, I create a new type named
MouseEvent
, which contains the following attributes:nil
for events that are notDown
,Up
, andDrag
u8
valueThe different
kind
andbutton
are indicated as different numbers, specifically:For
kind
:For
button
button
will benil
for events other thanDown
,Up
, andDrag
.Currently, only "left click to jump" is fully supported by lua script, which is implemented by
ya.manager_emit("reveal", { f.url })
. For scrolling, onlyCurrent
window supports item-based scrolling. Scrolling inPreview
will invoke theseek
in the preview window.Here are some potential things that people may like to see:
ranger
Preview
andParent
windowAFAIK, both of them need a new API for
ya.manager_emit
to invoke. If you think that's a good idea, I will try to implement these. Before that, it would be great if you could review the current implementation and provide some feedback.