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
48 changes: 44 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()
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not:

	if !h.Cursor.HasSelection() {
		h.SelectWordRight()
	}
	h.Cursor.DeleteSelection()
	h.Cursor.ResetSelection()

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's more simple. I am gonna change that for DeleteWordRight, DeleteWordLeft, DeleteSubWordRight, DeleteSubWordLeft.

}
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,26 @@ 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",
Comment thread
JoeKar marked this conversation as resolved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the default behavior of these keys inconsistent with the default behavior of Backspace and Delete (which still don't "prevent accidental deletion of adjacent text when selections are present")?

I think we shouldn't change these default keybindings, we should just add this DeleteSelections action, and let the user rebind them to DeleteSelections|DeleteWordLeft (or rebind Delete to DeleteSelections|Delete, or Backspace to DeleteSelections|Backspace, or whatever) if the user wants to.

...Also, could you fix huge lines in the commit messages?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the default behavior of these keys inconsistent with the default behavior of Backspace and Delete (which still don't "prevent accidental deletion of adjacent text when selections are present")?

We could add DeleteSelections to Delete and Backspace as well to provide sane default bindings.

I think we shouldn't change these default keybindings, we should just add this DeleteSelections action, and let the user rebind them to DeleteSelections|DeleteWordLeft (or rebind Delete to DeleteSelections|Delete, or Backspace to DeleteSelections|Backspace, or whatever) if the user wants to.

I am fine with that as well.

...Also, could you fix huge lines in the commit messages?

Sure. What line limits do you suggest? 50/72?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What line limits do you suggest? 50/72?

Both are fine to me. I personally use 72.

"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",
Comment thread
JoeKar marked this conversation as resolved.
"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