Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,43 +751,63 @@ func (h *BufPane) Backspace() bool {

// DeleteWordRight deletes the word to the right of the cursor
func (h *BufPane) DeleteWordRight() bool {
h.SelectWordRight()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
} else {
h.SelectWordRight()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
}
}
h.Relocate()
return true
}

// DeleteWordLeft deletes the word to the left of the cursor
func (h *BufPane) DeleteWordLeft() bool {
h.SelectWordLeft()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
} else {
h.SelectWordLeft()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
}
}
h.Relocate()
return true
}

// DeleteSubWordRight deletes the sub-word to the right of the cursor
func (h *BufPane) DeleteSubWordRight() bool {
h.SelectSubWordRight()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
} else {
h.SelectSubWordRight()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
}
}
h.Relocate()
return true
}

// DeleteSubWordLeft deletes the sub-word to the left of the cursor
func (h *BufPane) DeleteSubWordLeft() bool {
h.SelectSubWordLeft()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
} else {
h.SelectSubWordLeft()
if h.Cursor.HasSelection() {
h.Cursor.DeleteSelection()
h.Cursor.ResetSelection()
}
}
h.Relocate()
return true
Expand All @@ -808,6 +828,24 @@ func (h *BufPane) Delete() bool {
return true
}

// DeleteSelections checks for any active cursors selections and if there are it deletes them and returns true. It returns false when there are no selections.
func (h *BufPane) DeleteSelections() bool {
hasSelection := false
for _, c := range h.Buf.GetCursors() {
if c.HasSelection() {
c.DeleteSelection()
c.ResetSelection()
hasSelection = true
}
}

if hasSelection {
h.Relocate()
return true
}
return false
}

// IndentSelection indents the current selection
func (h *BufPane) IndentSelection() bool {
if h.Cursor.HasSelection() {
Expand Down
1 change: 1 addition & 0 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ var BufKeyActions = map[string]BufKeyAction{
"InsertNewline": (*BufPane).InsertNewline,
"Backspace": (*BufPane).Backspace,
"Delete": (*BufPane).Delete,
"DeleteSelections": (*BufPane).DeleteSelections,
"InsertTab": (*BufPane).InsertTab,
"Save": (*BufPane).Save,
"SaveAll": (*BufPane).SaveAll,
Expand Down
4 changes: 2 additions & 2 deletions internal/action/defaults_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ var bufdefaults = map[string]string{
"CtrlH": "Backspace",
"Backspace": "Backspace",
"OldBackspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Alt-CtrlH": "DeleteSelections|DeleteWordLeft",
"Alt-Backspace": "DeleteSelections|DeleteWordLeft",
"Tab": "Autocomplete|IndentSelection|InsertTab",
"Backtab": "CycleAutocompleteBack|OutdentSelection|OutdentLine",
"Ctrl-o": "OpenFile",
Expand Down
4 changes: 2 additions & 2 deletions internal/action/defaults_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var bufdefaults = map[string]string{
"CtrlH": "Backspace",
"Backspace": "Backspace",
"OldBackspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Alt-CtrlH": "DeleteSelections|DeleteWordLeft",
"Alt-Backspace": "DeleteSelections|DeleteWordLeft",
"Tab": "Autocomplete|IndentSelection|InsertTab",
"Backtab": "CycleAutocompleteBack|OutdentSelection|OutdentLine",
"Ctrl-o": "OpenFile",
Expand Down
9 changes: 5 additions & 4 deletions runtime/help/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ SelectToParagraphNext
InsertNewline
Backspace
Delete
DeleteSelections
InsertTab
Save
SaveAll
Expand Down Expand Up @@ -559,8 +560,8 @@ conventions for text editing defaults.
"Enter": "InsertNewline",
"Ctrl-h": "Backspace",
"Backspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Alt-CtrlH": "DeleteSelections|DeleteWordLeft",
"Alt-Backspace": "DeleteSelections|DeleteWordLeft",
"Tab": "Autocomplete|IndentSelection|InsertTab",
"Backtab": "OutdentSelection|OutdentLine",
"Ctrl-o": "OpenFile",
Expand Down Expand Up @@ -693,8 +694,8 @@ are given below:
"CtrlH": "Backspace",
"Backspace": "Backspace",
"OldBackspace": "Backspace",
"Alt-CtrlH": "DeleteWordLeft",
"Alt-Backspace": "DeleteWordLeft",
"Alt-CtrlH": "DeleteSelections|DeleteWordLeft",
"Alt-Backspace": "DeleteSelections|DeleteWordLeft",
"Tab": "CommandComplete",
"Backtab": "CycleAutocompleteBack",
"Ctrl-z": "Undo",
Expand Down