sxyazi / yazi

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

Items selected in visual mode aren't count in `cx.active.selected` #1553

Closed TD-Sky closed 1 month ago

TD-Sky commented 1 month ago

What system are you running Yazi on?

Linux Wayland

What terminal are you running Yazi in?

wezterm

yazi --debug output

Yazi
    Version: 0.3.1 (9cf85c09 2024-08-24)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.1 (9cf85c09 2024-08-24)

Emulator
    Emulator.via_env: ("xterm-256color", "WezTerm")
    Emulator.via_csi: Ok(WezTerm)
    Emulator.detect : WezTerm

Adapter
    Adapter.matches: Iterm2

Desktop
    XDG_SESSION_TYPE: Some("wayland")
    WAYLAND_DISPLAY : Some("wayland-0")
    DISPLAY         : Some(":1")

SSH
    shared.in_ssh_connection: false

WSL
    /proc/sys/fs/binfmt_misc/WSLInterop: false

Variables
    SHELL              : Some("/bin/zsh")
    EDITOR             : Some("lvim")
    VISUAL             : Some("lvim")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "$EDITOR \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "$EDITOR \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    ZELLIJ_SESSION_NAME: None
    Zellij version     : 0.40.1

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: 2.2.2
    magick           : 7.1.1-36
    fzf              : 0.54.3
    fd               : 10.1.0
    rg               : 14.1.0
    chafa            : No such file or directory (os error 2)
    zoxide           : 0.9.4
    7z               : 17.05
    7zz              : No such file or directory (os error 2)
    jq               : 1.7.1

--------------------------------------------------
log is empty

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

cx.active.selected is empty when there are items selected in visual mode.

Minimal reproducer

  1. Running git clone https://github.com/TD-Sky/sudo.yazi.git ~/.config/yazi/plugins/sudo.yazi
  2. Install nushell: cargo install nu or use your favorite package manager
  3. add ya.dbg(#cx.active.selected) in ~/.config/yazi/plugins/sudo.yazi/init.lua:47`
  4. Bind a key like:
    [[manager.keymap]]
    on = ["R", "d"]
    run = "plugin sudo --args='remove'"
    desc = "sudo trash"
  5. Running yazi, selecting items in visual mode, run the command.
  6. You will see only the hovered file get removed
  7. The log will tell you #cx.active.selected equals 0

Anything else?

No response

sxyazi commented 1 month ago

This is expected behavior. For safety reasons, the visual mode is designed as a temporary selection state because there are cases where selection failures can occur due to nested selection conflicts:

https://github.com/sxyazi/yazi/blob/cd7209c040a706bd826b20f47d4accdcf0c5a762/yazi-core/src/tab/commands/escape.rs#L101

https://github.com/sxyazi/yazi/blob/cd7209c040a706bd826b20f47d4accdcf0c5a762/yazi-core/src/tab/commands/escape.rs#L114-L119

If your plugin needs to support visual mode, simply send an escape command:

ya.manager_emit("escape", { visual = true })

Take a look at how the chmod.yazi plugin does it: https://github.com/yazi-rs/plugins/blob/main/chmod.yazi/init.lua#L14

Closing as it's expected

github-actions[bot] commented 2 weeks 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 open a new issue and complete the issue template so we can capture all the details necessary to investigate further.