mirror of https://github.com/gorhill/uBlock.git
This commit is contained in:
parent
79d5af20fc
commit
224661f905
|
@ -79,31 +79,27 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchWidgetTimerHandler(cm) {
|
|
||||||
var state = getSearchState(cm);
|
|
||||||
state.queryTimer = null;
|
|
||||||
findCommit(cm);
|
|
||||||
}
|
|
||||||
|
|
||||||
function searchWidgetInputHandler(cm) {
|
function searchWidgetInputHandler(cm) {
|
||||||
var state = getSearchState(cm);
|
let state = getSearchState(cm);
|
||||||
if ( queryTextFromSearchWidget(cm) !== state.queryText ) {
|
if ( queryTextFromSearchWidget(cm) === state.queryText ) { return; }
|
||||||
if ( state.queryTimer !== null ) {
|
if ( state.queryTimer !== null ) {
|
||||||
clearTimeout(state.queryTimer);
|
clearTimeout(state.queryTimer);
|
||||||
}
|
|
||||||
state.queryTimer = setTimeout(
|
|
||||||
searchWidgetTimerHandler.bind(null, cm),
|
|
||||||
350
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
state.queryTimer = setTimeout(
|
||||||
|
() => {
|
||||||
|
state.queryTimer = null;
|
||||||
|
findCommit(cm, 0);
|
||||||
|
},
|
||||||
|
350
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchWidgetClickHandler(cm, ev) {
|
function searchWidgetClickHandler(cm, ev) {
|
||||||
var tcl = ev.target.classList;
|
var tcl = ev.target.classList;
|
||||||
if ( tcl.contains('cm-search-widget-up') ) {
|
if ( tcl.contains('cm-search-widget-up') ) {
|
||||||
findNext(cm, true);
|
findNext(cm, -1);
|
||||||
} else if ( tcl.contains('cm-search-widget-down') ) {
|
} else if ( tcl.contains('cm-search-widget-down') ) {
|
||||||
findNext(cm, false);
|
findNext(cm, 1);
|
||||||
}
|
}
|
||||||
if ( ev.target.localName !== 'input' ) {
|
if ( ev.target.localName !== 'input' ) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
@ -156,7 +152,7 @@
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( queryText.length !== 0 ) {
|
if ( queryText.length !== 0 ) {
|
||||||
findNext(cm, command === 'findPrev');
|
findNext(cm, command === 'findPrev' ? -1 : 1);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -223,22 +219,23 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNext(cm, rev, callback) {
|
function findNext(cm, dir, callback) {
|
||||||
cm.operation(function() {
|
cm.operation(function() {
|
||||||
var state = getSearchState(cm);
|
var state = getSearchState(cm);
|
||||||
if ( !state.query ) { return; }
|
if ( !state.query ) { return; }
|
||||||
var cursor = getSearchCursor(
|
var cursor = getSearchCursor(
|
||||||
cm,
|
cm,
|
||||||
state.query,
|
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(
|
cursor = getSearchCursor(
|
||||||
cm,
|
cm,
|
||||||
state.query,
|
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.setSelection(cursor.from(), cursor.to());
|
||||||
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
|
cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20);
|
||||||
|
@ -270,7 +267,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function findCommit(cm) {
|
function findCommit(cm, dir) {
|
||||||
var state = getSearchState(cm);
|
var state = getSearchState(cm);
|
||||||
if ( state.queryTimer !== null ) {
|
if ( state.queryTimer !== null ) {
|
||||||
clearTimeout(state.queryTimer);
|
clearTimeout(state.queryTimer);
|
||||||
|
@ -284,7 +281,7 @@
|
||||||
} else {
|
} else {
|
||||||
cm.operation(function() {
|
cm.operation(function() {
|
||||||
startSearch(cm, state);
|
startSearch(cm, state);
|
||||||
findNext(cm, false);
|
findNext(cm, dir);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,17 +297,17 @@
|
||||||
cm.setCursor(word.anchor);
|
cm.setCursor(word.anchor);
|
||||||
}
|
}
|
||||||
queryTextToSearchWidget(cm, queryText);
|
queryTextToSearchWidget(cm, queryText);
|
||||||
findCommit(cm);
|
findCommit(cm, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNextCommand(cm) {
|
function findNextCommand(cm) {
|
||||||
var state = getSearchState(cm);
|
var state = getSearchState(cm);
|
||||||
if ( state.query ) { return findNext(cm, false); }
|
if ( state.query ) { return findNext(cm, 1); }
|
||||||
}
|
}
|
||||||
|
|
||||||
function findPrevCommand(cm) {
|
function findPrevCommand(cm) {
|
||||||
var state = getSearchState(cm);
|
var state = getSearchState(cm);
|
||||||
if ( state.query ) { return findNext(cm, true); }
|
if ( state.query ) { return findNext(cm, -1); }
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeMirror.commands.find = findCommand;
|
CodeMirror.commands.find = findCommand;
|
||||||
|
|
Loading…
Reference in New Issue