rbreaves / kinto

Mac-style shortcut keys for Linux & Windows.
http://kinto.sh
GNU General Public License v2.0
4.44k stars 213 forks source link

Ctrl key not working properly in vscode integrated terminal #324

Open edsonboldrini opened 3 years ago

edsonboldrini commented 3 years ago

Describe the bug When I'm in integrated terminal from vscode, the commands Ctrl+C (stop command running on terminal) and Ctrl+L (clear terminal) aren't working properly but working correctly into my Konsole (terminal app).

Expected behavior Those commands should be mapped into vscode as they're working properly on terminal app

Install Type: Bare Metal Distro: Manjaro DE: KDE Branch: master Commit: 0c53a7a

Logs and status if relevant

xkeysnail

sudo systemctl status xkeysnail

● xkeysnail.service - xkeysnail
     Loaded: loaded (/usr/lib/systemd/system/xkeysnail.service; disabled; vendor preset: >
     Active: active (running) since Tue 2020-11-17 10:24:17 -03; 14min ago
   Main PID: 40634 (sudo)
      Tasks: 2 (limit: 14328)
     Memory: 17.5M
     CGroup: /system.slice/xkeysnail.service
             ├─40634 /usr/bin/sudo /bin/bash -c /usr/bin/xhost +SI:localuser:root && /hom>
             └─40635 /usr/bin/python /usr/bin/xkeysnail --quiet --watch /home/edsonboldri>

nov 17 10:24:17 manjaro systemd[1]: Started xkeysnail.
nov 17 10:24:17 manjaro sudo[40634]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:24:17 manjaro sudo[40634]: pam_unix(sudo:session): session opened for user root>
nov 17 10:24:17 manjaro sudo[40636]: localuser:root being added to access control list

sudo journalctl --unit=xkeysnail.service -b

-- Logs begin at Mon 2020-11-16 05:28:50 -03, end at Tue 2020-11-17 10:39:10 -03. --
nov 17 08:40:49 manjaro sudo[1524]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=>
nov 17 08:40:49 manjaro sudo[1524]: pam_unix(sudo:session): session opened for user root(>
nov 17 08:40:49 manjaro sudo[1526]: localuser:root being added to access control list
nov 17 08:40:49 manjaro systemd[1]: Started xkeysnail.
nov 17 10:17:35 manjaro systemd[1]: Stopping xkeysnail...
nov 17 10:17:35 manjaro sudo[32383]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:17:35 manjaro sudo[32383]: pam_unix(sudo:session): session opened for user root>
nov 17 10:17:35 manjaro sudo[32385]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:17:35 manjaro sudo[32385]: pam_unix(sudo:session): session opened for user root>
nov 17 10:17:35 manjaro sudo[32385]: pam_unix(sudo:session): session closed for user root
nov 17 10:17:35 manjaro sudo[32383]: pam_unix(sudo:session): session closed for user root
nov 17 10:17:35 manjaro systemd[1]: xkeysnail.service: Control process exited, code=kille>
nov 17 10:17:35 manjaro sudo[1524]: pam_unix(sudo:session): session closed for user root
nov 17 10:17:35 manjaro systemd[1]: xkeysnail.service: Failed with result 'signal'.
nov 17 10:17:35 manjaro systemd[1]: Stopped xkeysnail.
nov 17 10:17:35 manjaro systemd[1]: Started xkeysnail.
nov 17 10:17:35 manjaro sudo[32394]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:17:35 manjaro sudo[32394]: pam_unix(sudo:session): session opened for user root>
nov 17 10:17:35 manjaro sudo[32396]: localuser:root being added to access control list
nov 17 10:19:15 manjaro systemd[1]: Stopping xkeysnail...
nov 17 10:19:15 manjaro sudo[33310]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:19:15 manjaro sudo[33310]: pam_unix(sudo:session): session opened for user root>
nov 17 10:19:15 manjaro sudo[33313]:     root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND>
nov 17 10:19:15 manjaro sudo[33313]: pam_unix(sudo:session): session opened for user root>
nov 17 10:19:15 manjaro sudo[33310]: pam_unix(sudo:session): session closed for user root
nov 17 10:19:15 manjaro sudo[33313]: pam_unix(sudo:session): session closed for user root
nov 17 10:19:15 manjaro systemd[1]: xkeysnail.service: Control process exited, code=kille>
nov 17 10:19:16 manjaro sudo[32394]: pam_unix(sudo:session): session closed for user root
nov 17 10:19:16 manjaro systemd[1]: xkeysnail.service: Failed with result 'signal'.
nov 17 10:19:16 manjaro systemd[1]: Stopped xkeysnail.

xkb

systemctl --user status keyswap

Unit keyswap.service could not be found.

journalctl --user-unit=keyswap.service -b

-- Logs begin at Mon 2020-11-16 05:28:50 -03, end at Tue 2020-11-17 10:41:00 -03. --
-- No entries --

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

carleeno commented 3 years ago

Hi, I recently started using kinto and it's absolutely perfect except for this issue. Was wondering if there's already been any work towards this, or if it's something I could try to dig into more?

To add a bit of extra detail about the issue description: While in vscode, switching between an editor pane and a terminal pane does not change the key mapping to terminal mappings. While in vscode's terminal pane, I have to cmd-c to cancel, and cmd-shift-c to copy, etc.

Fortunately it's still usable, but as I switch between vscode on a linux machine and vscode on a macbook daily, it's still difficult to remember to use the alternate mapping.

I still have a lot to learn about kinto, so I'm not sure how trivial to impossible this fix might be, since it'd have to detect which pane is focused in vscode. But I'm happy to try if RedBear or someone hasn't already been working on it!

rbreaves commented 3 years ago

@carleeno I think this issue is non-existent on the Windows side so I will have to look at it again on the Linux side. It should be resolvable I think.. but simply by making either Ctrl-C or Cmd-C work for sigint while also working for copy if text is highlight I think. There may not be any particularly good way of fixing it within only Kinto but by slightly changing the vscode keymap setup itself rather. Main reason is because the terminal pane looks no different in x11 than the entire vscode app itself.

carleeno commented 3 years ago

Thanks @rbreaves! That's great to hear it should be possible, I don't mind tweaking vscode's keymapping. I should mention that if there's a way to pass through other bash shortcuts in addition to sigint (ctrl-r, ctrl-\, ctrl-z, etc) that would be supreme. Heck, it's not uncommon for me to encounter nano while in vscode's terminal (git rebase for example), but I feel it's probably not trivial to keep all terminal shortcuts consistent, so even just fixing a few common ones would be fantastic.

I don't know of any shortcuts vscode uses that uses ctrl-so maybe it's possible to just keep the ctrl key mapped to ctrl in vs-code without breaking anything. Then all ctrl-based shortcuts in terminal would work. I'll play with this a bit later today.

rbreaves commented 3 years ago

@carleeno It really sort of depends to be honest - on the "Would making the physical control ctrl again as well make things break (while still having ctrl in the cmd position too)?" question. If you are really trying to make things like a Mac in VS Code then I would say that it would make things break because the Mac, by design, allows for and expects to have 3 unique modifier keys available.

Forcing only 2 modifier keys in the space of 3 would almost certainly break it - having said that though, there should be no real problem or hurdle I don't think about remapping LWin/Super + single letter keys to LCtrl + letter key instead as needed. It is just a matter of adding those keybindings to the VSCode keymap segment of kinto.py and kinto.ahk. Until I really step through it though I am not positive that it won't hinder some OS level hotkeys while using VS Code, as that is a real possibility - but the other route would certainly cause a loss of OS level shortcuts w/o a left win key.

Another reason why I keep 3 modifiers on the left as much as I can, bar terminal usage, and even then I try to pipe back in the Win/Super key over there whenever I can to allow for some OS level hotkeys but inevitably some things I have either not yet added back in or may not be possible to add back in even. If things get brought to my attention though then I normally take a look at fixing it.

rbreaves commented 3 years ago

@carleeno My preferred solution will be to remap Super-{letter key} to LCtrl-{letter key} and go through the entire alphabet if I have to. Remapping Super to Ctrl altogether would pretty well break a number of mac like hotkeys for VS Code, as mentioned and outlined above.

The only area where that type of global remap, that you mentioned, makes sense imo is the actual dedicated Terminal apps because of differently they operate and everything it expects hotkey wise compared to other GUI apps, so despite any possible OS system level shortcut breakage I go head and map Ctrl back to Ctrl and try to pipe Super back in when I need to - aka virtual desktop switching, etc.

raraz15 commented 8 months ago

I am facing a similar problem. Trying to use my macbook keyboard on an ubuntu computer and using VSCode with this setup. I am not an advanced keyboard user but some basic functionalities which work in the ubuntu terminal does not work in the VSCode. Some examples

Any idea what should I look into?

RedBearAK commented 8 months ago

@raraz15

This needs to be solved inside VSCode, because only VSCode, which is basically a web browser with internal window frames, knows when you have the keyboard focus in the embedded terminal, in the overall VSCode window.

The keymapper that Kinto uses only knows about the "application class" property of the window, which remains the same whether you are in the code editor or any other area of the window, or the terminal. So the keymapper can't change its behavior (modifier key remapping) the way that it does for independent "terminal" apps. The whole VSCode window, including the embedded terminal, gets treated like a "GUI" app instead of a "terminal" app.

Here is what that means in practice:

In GUI apps, pressing the physical equivalent of Cmd+C actually emits Ctrl+C. This is why it kills the process in the embedded terminal. It's just a modifier remap, not technically a shortcut transformation.

In terminal apps, pressing those same keys emits Shift+Ctrl+C, so that the "copy" shortcut works correctly in most terminal apps. This is a shortcut transformation, from Ctrl+C to Shift+Ctrl+C, in addition to the modifier remap. This is also why you have to do Shift+Cmd+C to copy, because that emits Shift+Ctrl+C due to the modifier remap.

In terminals, the physical Ctrl key is "left Ctrl", but in GUI apps it becomes the Meta/Super/Win/Cmd key code. This is why the Ctrl key doesn't do what you expect in the embedded terminal, because the whole VSCode window needs to be treated as a "GUI" app in order for all non-terminal shortcuts to work correctly.

The good news is that if you open the "keyboard settings json" (not the "default keyboard settings json"), it is possible to remap shortcuts only within the embedded terminal, since VSCode knows which pane has the keyboard focus. But you do have to carefully use the correct limiters on the shortcuts so that they will only be active in the embedded terminal pane.

Here is another issue thread with a basic starting point to use as an example:

https://github.com/rbreaves/kinto/issues/605

For the Option/Alt key to stop focusing the menu bar, you need to set some items in your "User Settings JSON", like this:

{
    "window.titleBarStyle": "custom",
    "window.enableMenuBarMnemonics": false,
    "window.customMenuBarAltFocus": false
}

There's also a fix for Firefox popping up the menu bar whenever you touch the Option/Alt key. See this FAQ entry in my own project README for a little more information on both the VSCode and Firefox fixes:

https://github.com/RedBearAK/toshy#vscodes-and-firefox-menu-stealing-focus-when-hitting-optionalt

RedBearAK commented 8 months ago

@raraz15

Here are some fixes I came up with for basic things like Copy/Paste, Ctrl+C/SIGINT and some deletion shortcuts. Not sure how much more could or would need to be fixed.

This needs to go into or be added to an existing keybindings.json that you open from the command palette with "Open Keyboard Shortcuts (JSON)". Doesn't require restarting VSCode to see the results. Should work as soon as the file is saved.

[
    //////////////////////////////////////////////////////////
    // Fixes for embedded terminal for use with Toshy/Kinto //
    //////////////////////////////////////////////////////////
    {
        // Send the Ctrl+C/SIGINT interrupt sequence in terminal
        "key": "ctrl+.",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0003" },
        "when": "terminalFocus"
    },
    {
        // Clear screen in terminal with Cmd+L
        "key": "ctrl+l",
        "command": "workbench.action.terminal.clear",
        "when": "terminalFocus"
    },
    {
        // Copy selected text in terminal with Cmd+C
        "key": "ctrl+c",
        "command": "workbench.action.terminal.copySelection",
        "when": "terminalFocus"
    },    
    {
        // Paste text in terminal with Cmd+V
        "key": "ctrl+v",
        "command": "workbench.action.terminal.paste",
        "when": "terminalFocus"
    },
    {
        // Delete all text left of cursor in terminal (Ctrl+U sequence)
        // For Kinto (Cmd+Backspace)
        "key": "ctrl+backspace", // delete all text (left of cursor)
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0015" },
        "when": "terminalFocus"
    },
    {
        // Delete all text left of cursor in terminal (Ctrl+U sequence)
        // Alternate for Toshy (Shift+Cmd+Backspace)
        "key": "shift+ctrl+backspace", // delete all text (left of cursor)
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0015" },
        "when": "terminalFocus"
    },
    {
        // Delete word left of cursor in terminal (Ctrl+W sequence)
        "key": "alt+backspace",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0017" },
        "when": "terminalFocus"
    }
]
RedBearAK commented 8 months ago

Here is also a way to allow Cmd+B to toggle the sidebar while the focus is in the terminal. Some shortcuts are captured by the shell and can't be fixed through keybindings.json. This must be added to the "User Settings JSON" file:

    "terminal.integrated.commandsToSkipShell": [
        "workbench.action.toggleSidebarVisibility"
    ]
Wuffz commented 8 months ago

@RedBearAK that Keybindings json is a real life saver, thanks!.

I added these aswell :

{
        // Cancel command in terminal (Ctrl+C sequence)
        "key": "meta+c",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0003" },
        "when": "terminalFocus"
},
{
        // Reverse search history (Ctrl+R sequence)
        "key": "meta+r",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0012" },
        "when": "terminalFocus"
},
RedBearAK commented 8 months ago

@Wuffz

Those are good additions. I knew I was forgetting something. I only fixed the Mac-style Cmd+Dot functionality, forgot to fix the physical Ctrl+C. I'm sure there may be a few others besides Ctrl+R that someone will find useful.

I'll be adding those to the Wiki page about this on my own repo.

Embedded Terminal in VSCode and Variants