diff --git a/docs-master/Config.md b/docs-master/Config.md index ebe2524ae..725f6ccc5 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -639,6 +639,9 @@ keybinding: # on Mac backspaceWord: + + # on Mac + forwardDeleteWord: optionMenu: optionMenu-alt1: '?' select: diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index c0b086d98..4cff2463c 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -454,9 +454,10 @@ type KeybindingUniversalConfig struct { NextMatch string `yaml:"nextMatch"` PrevMatch string `yaml:"prevMatch"` StartSearch string `yaml:"startSearch"` - MoveWordLeft string `yaml:"moveWordLeft"` // on Mac - MoveWordRight string `yaml:"moveWordRight"` // on Mac - BackspaceWord string `yaml:"backspaceWord"` // on Mac + MoveWordLeft string `yaml:"moveWordLeft"` // on Mac + MoveWordRight string `yaml:"moveWordRight"` // on Mac + BackspaceWord string `yaml:"backspaceWord"` // on Mac + ForwardDeleteWord string `yaml:"forwardDeleteWord"` // on Mac OptionMenu string `yaml:"optionMenu"` OptionMenuAlt1 string `yaml:"optionMenu-alt1"` Select string `yaml:"select"` @@ -939,6 +940,7 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { MoveWordLeft: platformKeyBinding(platform, map[string]string{"darwin": ""}, ""), MoveWordRight: platformKeyBinding(platform, map[string]string{"darwin": ""}, ""), BackspaceWord: platformKeyBinding(platform, map[string]string{"darwin": ""}, ""), + ForwardDeleteWord: platformKeyBinding(platform, map[string]string{"darwin": ""}, ""), OptionMenu: "", OptionMenuAlt1: "?", Select: "", diff --git a/pkg/gocui/edit.go b/pkg/gocui/edit.go index 7180aba18..3b6c15677 100644 --- a/pkg/gocui/edit.go +++ b/pkg/gocui/edit.go @@ -23,9 +23,10 @@ func (f EditorFunc) Edit(v *View, key Key) bool { var DefaultEditor Editor = EditorFunc(SimpleEditor) var ( - moveWordLeftKeybinding = NewKey(KeyArrowLeft, "", ModCtrl) - moveWordRightKeybinding = NewKey(KeyArrowRight, "", ModCtrl) - backspaceWordKeybinding = NewKey(KeyBackspace, "", ModCtrl) + moveWordLeftKeybinding = NewKey(KeyArrowLeft, "", ModCtrl) + moveWordRightKeybinding = NewKey(KeyArrowRight, "", ModCtrl) + backspaceWordKeybinding = NewKey(KeyBackspace, "", ModCtrl) + forwardDeleteWordKeybinding = NewKey(KeyDelete, "", ModCtrl) ) // SimpleEditor is used as the default gocui editor. @@ -34,6 +35,9 @@ func SimpleEditor(v *View, key Key) bool { case key.Equals(backspaceWordKeybinding), key.Equals(NewKeyStrMod("w", ModCtrl)): v.TextArea.BackSpaceWord() + case key.Equals(forwardDeleteWordKeybinding), + key.Equals(NewKeyStrMod("d", ModAlt)): + v.TextArea.ForwardDeleteWord() case key.Equals(NewKeyName(KeyBackspace)): v.TextArea.BackSpaceChar() case key.Equals(NewKeyStrMod("d", ModCtrl)), diff --git a/pkg/gocui/gui.go b/pkg/gocui/gui.go index eb3eb738c..d145f62ba 100644 --- a/pkg/gocui/gui.go +++ b/pkg/gocui/gui.go @@ -1630,8 +1630,9 @@ func (g *Gui) Snapshot() string { return builder.String() } -func (g *Gui) SetEditKeybindings(moveWordLeft, moveWordRight, backspaceWord Key) { +func (g *Gui) SetEditKeybindings(moveWordLeft, moveWordRight, backspaceWord, forwardDeleteWord Key) { moveWordLeftKeybinding = moveWordLeft moveWordRightKeybinding = moveWordRight backspaceWordKeybinding = backspaceWord + forwardDeleteWordKeybinding = forwardDeleteWord } diff --git a/pkg/gocui/text_area.go b/pkg/gocui/text_area.go index 9c88e983b..7aeb6220a 100644 --- a/pkg/gocui/text_area.go +++ b/pkg/gocui/text_area.go @@ -340,13 +340,12 @@ func (self *TextArea) MoveLeftWord() { self.cursor = self.newCursorForMoveLeftWord() } -func (self *TextArea) MoveRightWord() { +func (self *TextArea) newCursorForMoveRightWord() int { if self.atEnd() { - return + return self.cursor } if self.atLineEnd() { - self.cursor++ - return + return self.cursor + 1 } cellCursor := self.contentCursorToCellCursor(self.cursor) @@ -364,7 +363,11 @@ func (self *TextArea) MoveRightWord() { } } - self.cursor = self.cellCursorToContentCursor(cellCursor) + return self.cellCursorToContentCursor(cellCursor) +} + +func (self *TextArea) MoveRightWord() { + self.cursor = self.newCursorForMoveRightWord() } func (self *TextArea) MoveCursorUp() { @@ -559,6 +562,20 @@ func (self *TextArea) BackSpaceWord() { self.updateCells() } +func (self *TextArea) ForwardDeleteWord() { + newCursor := self.newCursorForMoveRightWord() + if newCursor == self.cursor { + return + } + + clipboard := self.content[self.cursor:newCursor] + if clipboard != "\n" { + self.clipboard = clipboard + } + self.content = self.content[:self.cursor] + self.content[newCursor:] + self.updateCells() +} + func (self *TextArea) Yank() { self.TypeString(self.clipboard) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 7fb732d99..ce22f4240 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -478,6 +478,7 @@ func (gui *Gui) onUserConfigLoaded() error { config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.MoveWordLeft), config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.MoveWordRight), config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.BackspaceWord), + config.GetValidatedKeyBindingKey(userConfig.Keybinding.Universal.ForwardDeleteWord), ) gui.g.ShowListFooter = userConfig.Gui.ShowListFooter diff --git a/schema-master/config.json b/schema-master/config.json index 5830772bb..1287a93b3 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -1425,6 +1425,11 @@ "description": "\u003ca-backspace\u003e on Mac", "default": "\u003cc-backspace\u003e" }, + "forwardDeleteWord": { + "type": "string", + "description": "\u003ca-delete\u003e on Mac", + "default": "\u003cc-delete\u003e" + }, "optionMenu": { "type": "string", "default": "\u003cdisabled\u003e"