-
Notifications
You must be signed in to change notification settings - Fork 236
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: allow quitting the app with escape when there's no selection #1042
Conversation
const FILTER = 0b0001000; | ||
const SEARCH = 0b0010000; | ||
const QUIT = 0b0100000; | ||
const CASCADE = 0b1000000; |
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.
This is to make it possible to explicitly invoke the default behavior (what happened previously when opt
was empty)
Sorry, I'm afraid I can't accept this PR. I prefer to keep each command as simple as possible, and this new I prefer each command to do only one thing. If you want to implement exiting by pressing -- ~/.config/yazi/plugins/smart-escape.yazi/init.lua
return {
entry = function()
local active = cx.active
local current = active.current
local esc = active.mode.is_visual or #active.selected > 0 or current.files.filter or current.cwd.is_search
ya.manager_emit(esc and "escape" or "quit", {})
end,
} Then bind it to your [[manager.prepend_keymap]]
on = [ "<Esc>" ]
run = "plugin --sync smart-escape" Note: There's a missing check for |
Fair enough.
Thanks for the snippet! Can I find a detailed reference for the plugin api anywhere? When I checked, it was hard for me to find out what functionality is exposed through the context.
Well, I'm not sure if I need it now. However, it seems wrong to me to duplicate (and keep in sync) internals of the escape command in a plugin. Could we expose the return value of the command to the plugin API? Or is it already there? |
Here it is https://yazi-rs.github.io/docs/plugins/types#app-data
I didn't quite understand this, could you explain it in more detail?
Not supported at the moment, but it may be added in the future. I still need to think it through carefully because currently, all commands do not return a value, including the pub fn escape(&mut self, opt: impl Into<Opt>) { Instead of something like: pub fn escape(&mut self, opt: impl Into<Opt>) -> bool { This would be a large change to the event system. |
Well, in the plugin, we basically rewrite a part of the escape command in lua. If a new UI element that is controlled with the escape key is added, I will have to reflect that in the plugin. That doesn't seem ideal.
I understand, and it may be too much of a niche use case anyway. Still, it would make it trivial to "extend" the escape command. |
Yes, this is currently a problem with the plugin system. However, it's unlikely that the behavior of the escape key will be changed because I consistently refuse to add new behaviors to it. An example is the 'unyank' command, which was added as a new command rather than being integrated into the 'escape' sequence. Adding too many behaviors would cause inconvenience. Currently, some actions require pressing
I plan to add a method parallel to I am going to close this PR. If you have any other questions, feel free to reply. |
Okay, sounds good! |
This allows making a key binding that first cancels visual mode, search, selections, etc., and if there is no such thing, it quits Yazi.
I use Yazi in neovim inside a floating window and my other tools can be closed with escape as well, so this is nice for me usability-wise, and should be opt-in.
How can I update the docs, do I just submit another PR to the website repo?