* Pretty much the same as `findNext`, except for the following differences: * * 1. Before starting the search, move to the previous search. This way if our cursor is * already inside a match, we should return the current match. * 2. Rather than only returning the cursor's from, w
(cm, prev, query, repeat, vim)
| 4445 | * 2. Rather than only returning the cursor's from, we return the cursor's from and to as a tuple. |
| 4446 | */ |
| 4447 | function findNextFromAndToInclusive(cm, prev, query, repeat, vim) { |
| 4448 | if (repeat === undefined) { repeat = 1; } |
| 4449 | return cm.operation(function() { |
| 4450 | var pos = cm.getCursor(); |
| 4451 | var cursor = cm.getSearchCursor(query, pos); |
| 4452 | |
| 4453 | // Go back one result to ensure that if the cursor is currently a match, we keep it. |
| 4454 | var found = cursor.find(!prev); |
| 4455 | |
| 4456 | // If we haven't moved, go back one more (similar to if i==0 logic in findNext). |
| 4457 | if (!vim.visualMode && found && cursorEqual(cursor.from(), pos)) { |
| 4458 | cursor.find(!prev); |
| 4459 | } |
| 4460 | |
| 4461 | for (var i = 0; i < repeat; i++) { |
| 4462 | found = cursor.find(prev); |
| 4463 | if (!found) { |
| 4464 | // SearchCursor may have returned null because it hit EOF, wrap |
| 4465 | // around and try again. |
| 4466 | cursor = cm.getSearchCursor(query, |
| 4467 | (prev) ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0) ); |
| 4468 | if (!cursor.find(prev)) { |
| 4469 | return; |
| 4470 | } |
| 4471 | } |
| 4472 | } |
| 4473 | return [cursor.from(), cursor.to()]; |
| 4474 | }); |
| 4475 | } |
| 4476 | function clearSearchHighlight(cm) { |
| 4477 | var state = getSearchState(cm); |
| 4478 | cm.removeOverlay(getSearchState(cm).getOverlay()); |