Implemented SkipMultiCursorBack as a counterpart to SkipMultiCursor

This commit is contained in:
Massimo Mund 2024-07-24 19:22:06 +02:00
parent e042bb3514
commit b25eb52f80
3 changed files with 37 additions and 0 deletions

View File

@ -2099,6 +2099,41 @@ func (h *BufPane) SkipMultiCursor() bool {
return true
}
// SkipMultiCursorBack moves the current multiple cursor to the previously available position
func (h *BufPane) SkipMultiCursorBack() bool {
lastC := h.Buf.GetCursor(h.Buf.NumCursors() - 1)
if !lastC.HasSelection() {
return false
}
sel := lastC.GetSelection()
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, false, true)
if err != nil {
InfoBar.Error(err)
}
if found {
lastC.SetSelectionStart(match[0])
lastC.SetSelectionEnd(match[1])
lastC.OrigSelection[0] = lastC.CurSelection[0]
lastC.OrigSelection[1] = lastC.CurSelection[1]
lastC.Loc = lastC.CurSelection[1]
h.Buf.MergeCursors()
h.Buf.SetCurCursor(h.Buf.NumCursors() - 1)
} else {
InfoBar.Message("No matches found")
}
h.Relocate()
return true
}
// RemoveMultiCursor removes the latest multiple cursor
func (h *BufPane) RemoveMultiCursor() bool {
if h.Buf.NumCursors() > 1 {

View File

@ -841,6 +841,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,

View File

@ -270,6 +270,7 @@ SpawnMultiCursorSelect
RemoveMultiCursor
RemoveAllMultiCursors
SkipMultiCursor
SkipMultiCursorBack
None
JumpToMatchingBrace
Autocomplete