FindPrevious searches backwards for the last used search term
()
| 1238 | |
| 1239 | // FindPrevious searches backwards for the last used search term |
| 1240 | func (h *BufPane) FindPrevious() bool { |
| 1241 | if h.Buf.LastSearch == "" { |
| 1242 | return false |
| 1243 | } |
| 1244 | // If the cursor is at the end of a selection and we search we want |
| 1245 | // to search from the beginning of the selection in the case that |
| 1246 | // the selection is a search result in which case we wouldn't move at |
| 1247 | // at all which would be bad |
| 1248 | searchLoc := h.Cursor.Loc |
| 1249 | if h.Cursor.HasSelection() { |
| 1250 | searchLoc = h.Cursor.CurSelection[0] |
| 1251 | } |
| 1252 | match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex) |
| 1253 | if err != nil { |
| 1254 | InfoBar.Error(err) |
| 1255 | } else if found && searchLoc == match[0] && match[0] == match[1] { |
| 1256 | // skip empty match at present cursor location |
| 1257 | if searchLoc == h.Buf.Start() { |
| 1258 | searchLoc = h.Buf.End() |
| 1259 | } else { |
| 1260 | searchLoc = searchLoc.Move(-1, h.Buf) |
| 1261 | } |
| 1262 | match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex) |
| 1263 | } |
| 1264 | if found { |
| 1265 | h.Cursor.SetSelectionStart(match[0]) |
| 1266 | h.Cursor.SetSelectionEnd(match[1]) |
| 1267 | h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] |
| 1268 | h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] |
| 1269 | h.GotoLoc(h.Cursor.CurSelection[1]) |
| 1270 | } else { |
| 1271 | h.Cursor.ResetSelection() |
| 1272 | } |
| 1273 | return true |
| 1274 | } |
| 1275 | |
| 1276 | // DiffNext searches forward until the beginning of the next block of diffs |
| 1277 | func (h *BufPane) DiffNext() bool { |
nothing calls this directly
no test coverage detected