1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

code review: always search from current cursor position (#3567)

This commit is contained in:
Raymond Hill 2018-03-04 15:52:34 -05:00
parent a69379068e
commit c59ceff6a1
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -130,7 +130,6 @@
} }
function SearchState(cm) { function SearchState(cm) {
this.posFrom = this.posTo = null;
this.query = null; this.query = null;
this.overlay = null; this.overlay = null;
this.panel = null; this.panel = null;
@ -176,7 +175,11 @@
function getSearchCursor(cm, query, pos) { function getSearchCursor(cm, query, pos) {
// Heuristic: if the query string is all lowercase, do a case insensitive search. // Heuristic: if the query string is all lowercase, do a case insensitive search.
return cm.getSearchCursor(query, pos, {caseFold: queryCaseInsensitive(query), multiline: true}); return cm.getSearchCursor(
query,
pos,
{caseFold: queryCaseInsensitive(query), multiline: true}
);
} }
function parseString(string) { function parseString(string) {
@ -226,7 +229,11 @@
function findNext(cm, rev, callback) { function findNext(cm, rev, callback) {
cm.operation(function() { cm.operation(function() {
var state = getSearchState(cm); var state = getSearchState(cm);
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo); var cursor = getSearchCursor(
cm,
state.query,
rev ? cm.getCursor('from') : cm.getCursor('to')
);
if (!cursor.find(rev)) { if (!cursor.find(rev)) {
cursor = getSearchCursor( cursor = getSearchCursor(
cm, cm,
@ -237,7 +244,6 @@
} }
cm.setSelection(cursor.from(), cursor.to()); cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20); cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
state.posFrom = cursor.from(); state.posTo = cursor.to();
if (callback) callback(cursor.from(), cursor.to()); if (callback) callback(cursor.from(), cursor.to());
}); });
} }
@ -280,7 +286,6 @@
} else { } else {
cm.operation(function() { cm.operation(function() {
startSearch(cm, state); startSearch(cm, state);
state.posFrom = state.posTo = cm.getCursor();
findNext(cm, false); findNext(cm, false);
}); });
} }