MCPcopy
hub / github.com/micro-editor/micro / FindNext

Method FindNext

internal/action/actions.go:1203–1237  ·  view source on GitHub ↗

FindNext searches forwards for the last used search term

()

Source from the content-addressed store, hash-verified

1201
1202// FindNext searches forwards for the last used search term
1203func (h *BufPane) FindNext() bool {
1204 if h.Buf.LastSearch == "" {
1205 return false
1206 }
1207 // If the cursor is at the start of a selection and we search we want
1208 // to search from the end of the selection in the case that
1209 // the selection is a search result in which case we wouldn't move at
1210 // at all which would be bad
1211 searchLoc := h.Cursor.Loc
1212 if h.Cursor.HasSelection() {
1213 searchLoc = h.Cursor.CurSelection[1]
1214 }
1215 match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex)
1216 if err != nil {
1217 InfoBar.Error(err)
1218 } else if found && searchLoc == match[0] && match[0] == match[1] {
1219 // skip empty match at present cursor location
1220 if searchLoc == h.Buf.End() {
1221 searchLoc = h.Buf.Start()
1222 } else {
1223 searchLoc = searchLoc.Move(1, h.Buf)
1224 }
1225 match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex)
1226 }
1227 if found {
1228 h.Cursor.SetSelectionStart(match[0])
1229 h.Cursor.SetSelectionEnd(match[1])
1230 h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0]
1231 h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1]
1232 h.GotoLoc(h.Cursor.CurSelection[1])
1233 } else {
1234 h.Cursor.ResetSelection()
1235 }
1236 return true
1237}
1238
1239// FindPrevious searches backwards for the last used search term
1240func (h *BufPane) FindPrevious() bool {

Callers 6

SearchMethod · 0.45
findMethod · 0.45
FindPreviousMethod · 0.45
SpawnMultiCursorMethod · 0.45
skipMultiCursorMethod · 0.45
ReplaceCmdMethod · 0.45

Calls 9

GotoLocMethod · 0.95
MoveMethod · 0.80
SetSelectionStartMethod · 0.80
SetSelectionEndMethod · 0.80
ResetSelectionMethod · 0.80
HasSelectionMethod · 0.45
StartMethod · 0.45
EndMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected