Skip to content

Commit

Permalink
feat(string-editor): Allow entering insert mode via append bind
Browse files Browse the repository at this point in the history
also fix exiting insert mode from string editor
  • Loading branch information
ja-he committed Jul 1, 2024
1 parent cb07c49 commit 21541c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/control/cli/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func NewController(
"x": "delete-rune",
"s": "delete-rune-and-insert",
"i": "swap-mode-insert",
"a": "swap-mode-insert-append",
},
Insert: map[input.Keyspec]input.Actionspec{
"<left>": "move-cursor-rune-left",
Expand Down
7 changes: 4 additions & 3 deletions internal/control/edit/editors/string_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type StringEditorControl interface {
MoveCursorPastEnd()
MoveCursorLeft()
MoveCursorRight()
MoveCursorRightA()
MoveCursorToNextWordBeginning()
MoveCursorToPrevWordBeginning()
MoveCursorToNextWordEnd()
Expand Down Expand Up @@ -156,7 +155,8 @@ func (e *StringEditor) MoveCursorLeft() {
// MoveCursorRight moves the cursor one rune to the right.
func (e *StringEditor) MoveCursorRight() {
nameLen := len([]rune(e.Content))
if e.CursorPos+1 < nameLen {
allow := (e.Mode == input.TextEditModeInsert && e.CursorPos+1 <= nameLen) || (e.Mode == input.TextEditModeNormal && e.CursorPos+1 < nameLen)
if allow {
e.CursorPos++
}
}
Expand Down Expand Up @@ -288,7 +288,8 @@ func (e *StringEditor) CreateInputProcessor(cfg input.InputConfig) (input.ModalI
"delete-to-end": e.DeleteToEnd,
"delete-to-end-and-insert": func() { e.DeleteToEnd(); enterInsertMode() },
"swap-mode-insert": func() { enterInsertMode() },
"swap-mode-normal": func() { exitInsertMode() },
"swap-mode-insert-append": func() { enterInsertMode(); e.MoveCursorRight() },
"swap-mode-normal": func() { exitInsertMode(); e.MoveCursorLeft() },
}

normalModeMappings := map[input.Keyspec]action.Action{}
Expand Down

0 comments on commit 21541c8

Please sign in to comment.