Skip to content

Commit

Permalink
Implemented SkipMultiCursorBack as a counterpart to `SkipMultiCurso…
Browse files Browse the repository at this point in the history
…r` (#3404)
  • Loading branch information
masmu committed Sep 16, 2024
1 parent 9eaeb19 commit 4f4a13a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
18 changes: 15 additions & 3 deletions internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2167,22 +2167,24 @@ func (h *BufPane) MouseMultiCursor(e *tcell.EventMouse) bool {
return true
}

// SkipMultiCursor moves the current multiple cursor to the next available position
func (h *BufPane) SkipMultiCursor() bool {
func (h *BufPane) skipMultiCursor(forward bool) bool {
lastC := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
if !lastC.HasSelection() {
return false
}
sel := lastC.GetSelection()
searchStart := lastC.CurSelection[1]
if !forward {
searchStart = lastC.CurSelection[0]
}

search := string(sel)
search = regexp.QuoteMeta(search)
if h.multiWord {
search = "\\b" + search + "\\b"
}

match, found, err := h.Buf.FindNext(search, h.Buf.Start(), h.Buf.End(), searchStart, true, true)
match, found, err := h.Buf.FindNext(search, h.Buf.Start(), h.Buf.End(), searchStart, forward, true)
if err != nil {
InfoBar.Error(err)
}
Expand All @@ -2202,6 +2204,16 @@ func (h *BufPane) SkipMultiCursor() bool {
return true
}

// SkipMultiCursor moves the current multiple cursor to the next available position
func (h *BufPane) SkipMultiCursor() bool {
return h.skipMultiCursor(true)
}

// SkipMultiCursorBack moves the current multiple cursor to the previous available position
func (h *BufPane) SkipMultiCursorBack() bool {
return h.skipMultiCursor(false)
}

// RemoveMultiCursor removes the latest multiple cursor
func (h *BufPane) RemoveMultiCursor() bool {
if h.Buf.NumCursors() > 1 {
Expand Down
1 change: 1 addition & 0 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ var BufKeyActions = map[string]BufKeyAction{
"RemoveMultiCursor": (*BufPane).RemoveMultiCursor,
"RemoveAllMultiCursors": (*BufPane).RemoveAllMultiCursors,
"SkipMultiCursor": (*BufPane).SkipMultiCursor,
"SkipMultiCursorBack": (*BufPane).SkipMultiCursorBack,
"JumpToMatchingBrace": (*BufPane).JumpToMatchingBrace,
"JumpLine": (*BufPane).JumpLine,
"Deselect": (*BufPane).Deselect,
Expand Down
1 change: 1 addition & 0 deletions runtime/help/keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ SpawnMultiCursorSelect
RemoveMultiCursor
RemoveAllMultiCursors
SkipMultiCursor
SkipMultiCursorBack
None
JumpToMatchingBrace
Autocomplete
Expand Down

0 comments on commit 4f4a13a

Please sign in to comment.