FindNext searches forwards for the last used search term
()
| 1201 | |
| 1202 | // FindNext searches forwards for the last used search term |
| 1203 | func (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 |
| 1240 | func (h *BufPane) FindPrevious() bool { |
no test coverage detected