Skip to content

Commit

Permalink
feat(tui): Add vimlike keybind "S" to string editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Jul 2, 2024
1 parent 9ce2a38 commit cc388bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func NewController(
"C": "delete-to-end-and-insert",
"c$": "delete-to-end-and-insert",
"c0": "backspace-to-beginning-and-insert",
"S": "delete-everything-and-insert",
"x": "delete-rune",
"s": "delete-rune-and-insert",
"i": "swap-mode-insert",
Expand Down
8 changes: 8 additions & 0 deletions internal/control/edit/editors/string_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func (e *StringEditor) BackspaceToBeginning() {
e.CursorPos = 0
}

// DeleteEverything deletes all runes in the editor.
func (e *StringEditor) DeleteEverything() {
e.Content = ""
e.CursorPos = 0
}

// DeleteToEnd deletes all runes after the cursor position.
func (e *StringEditor) DeleteToEnd() {
nameBeforeCursor := []rune(e.Content)[:e.CursorPos]
Expand Down Expand Up @@ -283,6 +289,8 @@ func (e *StringEditor) CreateInputProcessor(cfg input.InputConfig) (input.ModalI
"quit": e.Quit,
"backspace": e.BackspaceRune,
"backspace-to-beginning": e.BackspaceToBeginning,
"delete-everything": e.DeleteEverything,
"delete-everything-and-insert": func() { e.DeleteEverything(); enterInsertMode() },
"backspace-to-beginning-and-insert": func() { e.BackspaceToBeginning(); enterInsertMode() },
"delete-rune": e.DeleteRune,
"delete-rune-and-insert": func() { e.DeleteRune(); enterInsertMode() },
Expand Down

0 comments on commit cc388bf

Please sign in to comment.