Support Ctrl Modifier for Word Navigation and Deletion in Text Areas#5394
Support Ctrl Modifier for Word Navigation and Deletion in Text Areas#5394iskandergaba wants to merge 3 commits intojesseduffield:masterfrom
Ctrl Modifier for Word Navigation and Deletion in Text Areas#5394Conversation
|
Thanks for the contribution. I'm not going to merge this because I'm in the process of rewriting the key handling in gocui and lazygit, so all the code you are touching here will be different. I will try to remember to make this change as part of that work. However:
Which platform are you on? As far as I am aware, using Alt is standard on Mac. Windows does use Ctrl though; not sure about Linux, I don't have a Linux system to test this on. I think I would like to avoid offering both variants on all platforms; I'd prefer to only have the one that is standard on each platform. Also, it would be good to make them configurable I guess. Never seen Ctrl-Delete or Alt-D for forward-delete-word; is this standard? What software supports it? |
Fair enough. Thanks for taking the time to consider the PR. I will lay out my case here. I will start from this point and build back from there.
These shortcuts are standard on:
Here are a couple of sources that support the existence of the action and the key-binding (
Technically, the shortcut is the Emacs key-biding
For the sake of more clarity, I did some digging. Listing the key binding on a
$ bind -p | grep -w " backward-kill-word"
"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word
$ bind -p | grep -w " unix-word-rubout"
"\C-w": unix-word-rubout
Notes:
$ bind -p | grep -w " kill-word"
"\e[3;5~": kill-word
"\ed": kill-word
$ bind -p | grep -w " backward-word"
"\e\e[D": backward-word
"\e[1;3D": backward-word
"\e[1;5D": backward-word
"\e[5D": backward-word
"\eb": backward-word
$ bind -p | grep -w " forward-word"
"\e\e[C": forward-word
"\e[1;3C": forward-word
"\e[1;5C": forward-word
"\e[5C": forward-word
"\ef": forward-word
Fair point. Ultimately, this has to do more with the shell you use rather than then the OS. The reason you can't find those key bindings on macOS is because it defaults to I guess I just wanted less friction switching between my code editors and Lazygit. I think it can be configurable, say bash-style, zsh-style, and PowerShell-style key bindings. An auto setting could select the key binding corresponding to default shell, with a fallback to Or you could force the law on everyone and dictate the key bindings :) Either way, I hope this discussion has shed more light on the matter and that it will help your technical choices in the ongoing rewrite. Good luck. |
Up to standards ✅🟢 Issues
|
PR Description
Unlike
lazygit, most text editors and TUIs supportCtrlbased key bindings for word navigation and deletion. They also support forward word deletion. As a heavy user of these key bindings, I wanted to extend their support tolazygitto switch between tools more easily.I am sure that I am not the only one who would appreciate this, and in any case, this extension does not break any preexisting key bindings.
Changes:
Ctrl+Left/Ctrl+Right: Move cursor one word left/right (alongside existingAlt+Left/Rightand Emacs-styleAlt+B/Alt+F)Ctrl+Backspace: delete word to the left (alongside existingAlt+BackspaceandCtrl+W)Ctrl+Delete/Alt+D: Delete word to the right (new; no equivalent existed before)Note:
ModCtrlwas previously disabled ingocuiwith a comment stating it didn't work with keyboard keys. This comment was written 5 years ago and mentionstcell.v1while the project is currently usingtcell.v2, so I suspect it is a bit legacy now, but I would like it if the maintainers double-checked that part. I managed to makeModCtrlwork by patchingtcell_driver.goto preserve it for right/left and deletion key events while keeping it stripped from all other ones, as before.Please Check If the PR Fulfills these Requirements
go generate ./...)