1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00
Raymond Hill 2018-07-09 15:21:45 -04:00
parent 79d5af20fc
commit 224661f905
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -79,31 +79,27 @@
);
}
function searchWidgetTimerHandler(cm) {
var state = getSearchState(cm);
state.queryTimer = null;
findCommit(cm);
}
function searchWidgetInputHandler(cm) {
var state = getSearchState(cm);
if ( queryTextFromSearchWidget(cm) !== state.queryText ) {
if ( state.queryTimer !== null ) {
clearTimeout(state.queryTimer);
}
state.queryTimer = setTimeout(
searchWidgetTimerHandler.bind(null, cm),
350
);
let state = getSearchState(cm);
if ( queryTextFromSearchWidget(cm) === state.queryText ) { return; }
if ( state.queryTimer !== null ) {
clearTimeout(state.queryTimer);
}
state.queryTimer = setTimeout(
() => {
state.queryTimer = null;
findCommit(cm, 0);
},
350
);
}
function searchWidgetClickHandler(cm, ev) {
var tcl = ev.target.classList;
if ( tcl.contains('cm-search-widget-up') ) {
findNext(cm, true);
findNext(cm, -1);
} else if ( tcl.contains('cm-search-widget-down') ) {
findNext(cm, false);
findNext(cm, 1);
}
if ( ev.target.localName !== 'input' ) {
ev.preventDefault();
@ -156,7 +152,7 @@
return true;
}
if ( queryText.length !== 0 ) {
findNext(cm, command === 'findPrev');
findNext(cm, command === 'findPrev' ? -1 : 1);
}
return true;
}
@ -223,22 +219,23 @@
}
}
function findNext(cm, rev, callback) {
function findNext(cm, dir, callback) {
cm.operation(function() {
var state = getSearchState(cm);
if ( !state.query ) { return; }
var cursor = getSearchCursor(
cm,
state.query,
rev ? cm.getCursor('from') : cm.getCursor('to')
dir <= 0 ? cm.getCursor('from') : cm.getCursor('to')
);
if (!cursor.find(rev)) {
let previous = dir < 0;
if (!cursor.find(previous)) {
cursor = getSearchCursor(
cm,
state.query,
rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0)
previous ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0)
);
if (!cursor.find(rev)) return;
if (!cursor.find(previous)) return;
}
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
@ -270,7 +267,7 @@
});
}
function findCommit(cm) {
function findCommit(cm, dir) {
var state = getSearchState(cm);
if ( state.queryTimer !== null ) {
clearTimeout(state.queryTimer);
@ -284,7 +281,7 @@
} else {
cm.operation(function() {
startSearch(cm, state);
findNext(cm, false);
findNext(cm, dir);
});
}
}
@ -300,17 +297,17 @@
cm.setCursor(word.anchor);
}
queryTextToSearchWidget(cm, queryText);
findCommit(cm);
findCommit(cm, 1);
}
function findNextCommand(cm) {
var state = getSearchState(cm);
if ( state.query ) { return findNext(cm, false); }
if ( state.query ) { return findNext(cm, 1); }
}
function findPrevCommand(cm) {
var state = getSearchState(cm);
if ( state.query ) { return findNext(cm, true); }
if ( state.query ) { return findNext(cm, -1); }
}
CodeMirror.commands.find = findCommand;