mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Make edit keybindings for move-by-word and backspace-word configurable
And make them platform dependent so that they are with ctrl on Windows and Linux, but alt on Mac.
This commit is contained in:
@@ -630,6 +630,15 @@ keybinding:
|
||||
nextMatch: "n"
|
||||
prevMatch: "N"
|
||||
startSearch: /
|
||||
|
||||
# <a-left> on Mac
|
||||
moveWordLeft: <c-left>
|
||||
|
||||
# <a-right> on Mac
|
||||
moveWordRight: <c-right>
|
||||
|
||||
# <a-backspace> on Mac
|
||||
backspaceWord: <c-backspace>
|
||||
optionMenu: <disabled>
|
||||
optionMenu-alt1: '?'
|
||||
select: <space>
|
||||
|
||||
@@ -454,6 +454,9 @@ type KeybindingUniversalConfig struct {
|
||||
NextMatch string `yaml:"nextMatch"`
|
||||
PrevMatch string `yaml:"prevMatch"`
|
||||
StartSearch string `yaml:"startSearch"`
|
||||
MoveWordLeft string `yaml:"moveWordLeft"` // <a-left> on Mac
|
||||
MoveWordRight string `yaml:"moveWordRight"` // <a-right> on Mac
|
||||
BackspaceWord string `yaml:"backspaceWord"` // <a-backspace> on Mac
|
||||
OptionMenu string `yaml:"optionMenu"`
|
||||
OptionMenuAlt1 string `yaml:"optionMenu-alt1"`
|
||||
Select string `yaml:"select"`
|
||||
@@ -933,6 +936,9 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig {
|
||||
NextMatch: "n",
|
||||
PrevMatch: "N",
|
||||
StartSearch: "/",
|
||||
MoveWordLeft: platformKeyBinding(platform, map[string]string{"darwin": "<a-left>"}, "<c-left>"),
|
||||
MoveWordRight: platformKeyBinding(platform, map[string]string{"darwin": "<a-right>"}, "<c-right>"),
|
||||
BackspaceWord: platformKeyBinding(platform, map[string]string{"darwin": "<a-backspace>"}, "<c-backspace>"),
|
||||
OptionMenu: "<disabled>",
|
||||
OptionMenuAlt1: "?",
|
||||
Select: "<space>",
|
||||
|
||||
+9
-3
@@ -22,10 +22,16 @@ func (f EditorFunc) Edit(v *View, key Key) bool {
|
||||
// DefaultEditor is the default editor.
|
||||
var DefaultEditor Editor = EditorFunc(SimpleEditor)
|
||||
|
||||
var (
|
||||
moveWordLeftKeybinding = NewKey(KeyArrowLeft, "", ModCtrl)
|
||||
moveWordRightKeybinding = NewKey(KeyArrowRight, "", ModCtrl)
|
||||
backspaceWordKeybinding = NewKey(KeyBackspace, "", ModCtrl)
|
||||
)
|
||||
|
||||
// SimpleEditor is used as the default gocui editor.
|
||||
func SimpleEditor(v *View, key Key) bool {
|
||||
switch {
|
||||
case key.Equals(NewKey(KeyBackspace, "", ModAlt)),
|
||||
case key.Equals(backspaceWordKeybinding),
|
||||
key.Equals(NewKeyStrMod("w", ModCtrl)):
|
||||
v.TextArea.BackSpaceWord()
|
||||
case key.Equals(NewKeyName(KeyBackspace)):
|
||||
@@ -38,13 +44,13 @@ func SimpleEditor(v *View, key Key) bool {
|
||||
case key.Equals(NewKeyName(KeyArrowUp)):
|
||||
v.TextArea.MoveCursorUp()
|
||||
case key.Equals(NewKeyStrMod("b", ModAlt)),
|
||||
key.Equals(NewKey(KeyArrowLeft, "", ModAlt)):
|
||||
key.Equals(moveWordLeftKeybinding):
|
||||
v.TextArea.MoveLeftWord()
|
||||
case key.Equals(NewKeyName(KeyArrowLeft)),
|
||||
key.Equals(NewKeyStrMod("b", ModCtrl)):
|
||||
v.TextArea.MoveCursorLeft()
|
||||
case key.Equals(NewKeyStrMod("f", ModAlt)),
|
||||
key.Equals(NewKey(KeyArrowRight, "", ModAlt)):
|
||||
key.Equals(moveWordRightKeybinding):
|
||||
v.TextArea.MoveRightWord()
|
||||
case key.Equals(NewKeyName(KeyArrowRight)),
|
||||
key.Equals(NewKeyStrMod("b", ModCtrl)):
|
||||
|
||||
@@ -1629,3 +1629,9 @@ func (g *Gui) Snapshot() string {
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func (g *Gui) SetEditKeybindings(moveWordLeft, moveWordRight, backspaceWord Key) {
|
||||
moveWordLeftKeybinding = moveWordLeft
|
||||
moveWordRightKeybinding = moveWordRight
|
||||
backspaceWordKeybinding = backspaceWord
|
||||
}
|
||||
|
||||
@@ -474,6 +474,12 @@ func (gui *Gui) onUserConfigLoaded() error {
|
||||
gui.g.NextSearchMatchKey = config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.NextMatch)
|
||||
gui.g.PrevSearchMatchKey = config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.PrevMatch)
|
||||
|
||||
gui.g.SetEditKeybindings(
|
||||
config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.MoveWordLeft),
|
||||
config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.MoveWordRight),
|
||||
config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.BackspaceWord),
|
||||
)
|
||||
|
||||
gui.g.ShowListFooter = userConfig.Gui.ShowListFooter
|
||||
|
||||
gui.g.Mouse = userConfig.Gui.MouseEvents
|
||||
|
||||
@@ -1410,6 +1410,21 @@
|
||||
"type": "string",
|
||||
"default": "/"
|
||||
},
|
||||
"moveWordLeft": {
|
||||
"type": "string",
|
||||
"description": "\u003ca-left\u003e on Mac",
|
||||
"default": "\u003cc-left\u003e"
|
||||
},
|
||||
"moveWordRight": {
|
||||
"type": "string",
|
||||
"description": "\u003ca-right\u003e on Mac",
|
||||
"default": "\u003cc-right\u003e"
|
||||
},
|
||||
"backspaceWord": {
|
||||
"type": "string",
|
||||
"description": "\u003ca-backspace\u003e on Mac",
|
||||
"default": "\u003cc-backspace\u003e"
|
||||
},
|
||||
"optionMenu": {
|
||||
"type": "string",
|
||||
"default": "\u003cdisabled\u003e"
|
||||
|
||||
Reference in New Issue
Block a user