sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
16.98k stars 397 forks source link

[Bug] Inconsistent behavior between calling built-in command and plugin. #1820

Closed boydaihungst closed 1 month ago

boydaihungst commented 1 month ago

What system are you running Yazi on?

Linux Wayland

What terminal are you running Yazi in?

kitty 0.36.4

yazi --debug output

Yazi
    Version: 0.3.3 (3e8ac85 2024-10-15)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (3e8ac85 2024-10-15)

Emulator
    Emulator.via_env: ("xterm-kitty", "")
    Emulator.via_csi: Ok(Kitty)
    Emulator.detect : Kitty

Adapter
    Adapter.matches: Kgp

Desktop
    XDG_SESSION_TYPE           : Some("wayland")
    WAYLAND_DISPLAY            : Some("wayland-1")
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : Some("/run/user/1000/sway-ipc.1000.1032.sock")
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/usr/bin/fish")
    EDITOR             : Some("nvim")
    VISUAL             : Some("nvim")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default     : Some(Opener { run: "kitty --class \"nvim\" -e nvim \"$@\"", block: false, orphan: true, desc: "Nvim", for_: None, spread: true })
    block-create: Some(Opener { run: "exiftool \"$1\"; echo \"Press enter to exit\"; read _", block: true, orphan: false, desc: "Show EXIF", for_: None, spread: false })
    block-rename: Some(Opener { run: "exiftool \"$1\"; echo \"Press enter to exit\"; read _", block: true, orphan: false, desc: "Show EXIF", for_: None, spread: false })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : 2.9.6
    ffmpegthumbnailer: 2.2.3
    magick           : 7.1.1-39
    fzf              : 0.55.0
    fd               : 10.2.0
    rg               : 14.1.1
    chafa            : 1.14.2
    zoxide           : 0.9.6
    7z               : 17.05
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1

--------------------------------------------------
When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time.
You can find it in the "/home/huyhoang/.local/state/yazi" directory.

Did you try the latest nightly build to see if the problem got fixed?

Yes, and I updated the debug information above (yazi --debug) to the nightly that I tried

Describe the bug

When you're in visual mode and select some files (moving up/down, don't use select command), running a built-in command like enter or rename will show that you have selected those files. However, if you use run=plugin --sync abc, it will only show that 0 files are selected.

Minimal reproducer

{ on = "r", run = "plugin --sync abc "', desc = "Test function" },

-- plugin abc.yazi/init.lua
return {
    entry = function()
        local h = cx.active.selected
        ya.err(#h) -- this print 0
    end,
}

Anything else?

No response

boydaihungst commented 1 month ago

OK I found a solution for this. But it could be awesome if you could run ya.manager_emit("escape", { visual = true }) in plugin and wait for the result.

{ on = "r", run = ["escape --visual", "plugin --sync abc"], desc = "Test abc" },
sxyazi commented 1 month ago

You can also make the plugin async to achieve this, see https://github.com/sxyazi/yazi/issues/1553#issuecomment-2309119135

github-actions[bot] commented 1 week ago

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please file a new issue and complete the issue template so we can capture all the details necessary to investigate further.