microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.59k stars 29.03k forks source link

workbench.action.toggleSidebarVisibility forgets selected file #178705

Open ulcuber opened 1 year ago

ulcuber commented 1 year ago

Trying to toggle sidebar with:

{
        "key": "ctrl+\\",
        "command": "workbench.files.action.focusFilesExplorer",
        // "command": "workbench.explorer.fileView.focus",
        "when": "!explorerViewletVisible"
    },
    {
        "key": "ctrl+\\",
        "command": "workbench.action.toggleSidebarVisibility",
        // "command": "workbench.action.closeSidebar",
        "when": "sideBarVisible"
    },

But on invisible sidebar workbench.files.action.focusFilesExplorer just focuses whole list while on visible sidebar it focuses last selected item in list

lramos15 commented 1 year ago

Can you follow basic troubleshooting here https://github.com/microsoft/vscode/wiki/Keybinding-Issues and post which command is getting executed when the sidebar isn't visible. I wonder if the command is properly executing

ulcuber commented 1 year ago
2023-04-11 20:13:52.313 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
2023-04-11 20:13:52.313 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
2023-04-11 20:13:52.314 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2023-04-11 20:13:52.672 [info] [KeybindingService]: / Soft dispatching keyboard event
2023-04-11 20:13:52.672 [info] [KeybindingService]: | Resolving ctrl+\
2023-04-11 20:13:52.672 [info] [KeybindingService]: \ From 3 keybinding entries, matched workbench.action.toggleSidebarVisibility, when: sideBarVisible, source: user.
2023-04-11 20:13:52.672 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: Backslash, keyCode: 220, key: \
2023-04-11 20:13:52.673 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: Backslash, keyCode: 88 ('\')
2023-04-11 20:13:52.673 [info] [KeybindingService]: | Resolving ctrl+\
2023-04-11 20:13:52.673 [info] [KeybindingService]: \ From 3 keybinding entries, matched workbench.action.toggleSidebarVisibility, when: sideBarVisible, source: user.
2023-04-11 20:13:52.674 [info] [KeybindingService]: + Invoking command workbench.action.toggleSidebarVisibility.
2023-04-11 20:13:54.022 [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: Backslash, keyCode: 220, key: \
2023-04-11 20:13:54.023 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: Backslash, keyCode: 88 ('\')
2023-04-11 20:13:54.023 [info] [KeybindingService]: | Resolving ctrl+\
2023-04-11 20:13:54.024 [info] [KeybindingService]: \ From 3 keybinding entries, matched workbench.files.action.focusFilesExplorer, when: !explorerViewletVisible, source: user.
2023-04-11 20:13:54.024 [info] [KeybindingService]: + Invoking command workbench.files.action.focusFilesExplorer.
ulcuber commented 1 year ago

Some more info

settings:

{
    "keyboard.dispatch": "keyCode",
}

No virtualization

Env:

OS: Gentoo 2.13
Kernel: x86_64 Linux 5.10.76-gentoo-r1
WM: i3
Code:
1.76.2
ee2b180d582a7f601fa6ecfdad8d9fd269ab1884
x64

setxkbmap -query

rules:      evdev
model:      pc105
layout:     us,ru
options:    grp:caps_toggle,grp_led:caps
ulcuber commented 1 year ago

Screenshots: Problem: Has focus when opened: image

Toggled sidebar then opened back: image

Expected: With inactive but visible sidebar: image

File: Focus on Files Explorer gives focus back: image

lramos15 commented 1 year ago

Try using workbench.files.action.showActiveFileInExplorer as your command instead

ulcuber commented 1 year ago

Already have such keybinding

{
        "key": "ctrl+shift+\\",
        "command": "workbench.files.action.showActiveFileInExplorer",
    },

But it moves cursor to current opened file and only when file explorer visible. For invisible file explorer just opens file explorer without showing active file and only if opened file belongs to file tree.

Also tried workbench.explorer.fileView.focus instead of workbench.files.action.focusFilesExplorer. They behave the same

lramos15 commented 1 year ago

For invisible file explorer just opens file explorer without showing active file and only if opened file belongs to file tree.

Yes it must be in the file tree, but for when the sidebar is minimized this command does work for me to open and focus the file. You are correct however in that if the tree is hidden and then revealed selection is lost. This isn't the case for all trees so I will mark it as a bug