mirror of https://github.com/gorhill/uBlock.git
Fix search widget when swapping document in new code viewer
This commit is contained in:
parent
aa21952379
commit
fd9bb02aab
|
@ -208,7 +208,7 @@ async function setURL(resourceURL) {
|
||||||
afterDoc = new CodeMirror.Doc(r.text, r.mime || '');
|
afterDoc = new CodeMirror.Doc(r.text, r.mime || '');
|
||||||
urlToDocMap.set(afterURL, afterDoc);
|
urlToDocMap.set(afterURL, afterDoc);
|
||||||
}
|
}
|
||||||
cmEditor.swapDoc(afterDoc);
|
swapDoc(afterDoc);
|
||||||
currentURL = afterURL;
|
currentURL = afterURL;
|
||||||
setInputURL(afterURL);
|
setInputURL(afterURL);
|
||||||
const a = qs$('.cm-search-widget .sourceURL');
|
const a = qs$('.cm-search-widget .sourceURL');
|
||||||
|
@ -244,6 +244,20 @@ function removeURL(url) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
function swapDoc(doc) {
|
||||||
|
const r = cmEditor.swapDoc(doc);
|
||||||
|
if ( self.searchThread ) {
|
||||||
|
self.searchThread.setHaystack(cmEditor.getValue());
|
||||||
|
}
|
||||||
|
const input = qs$('.cm-search-widget-input input[type="search"]');
|
||||||
|
if ( input.value !== '' ) {
|
||||||
|
qs$('.cm-search-widget').dispatchEvent(new Event('input'));
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
await setURL(params.get('url'));
|
await setURL(params.get('url'));
|
||||||
|
|
||||||
|
@ -254,7 +268,7 @@ async function start() {
|
||||||
dom.on('#reloadURL', 'click', ( ) => {
|
dom.on('#reloadURL', 'click', ( ) => {
|
||||||
const input = qs$('#header input[type="url"]');
|
const input = qs$('#header input[type="url"]');
|
||||||
const url = input.value;
|
const url = input.value;
|
||||||
const beforeDoc = cmEditor.swapDoc(new CodeMirror.Doc('', ''));
|
const beforeDoc = swapDoc(new CodeMirror.Doc('', ''));
|
||||||
fetchResource(url).then(r => {
|
fetchResource(url).then(r => {
|
||||||
if ( urlToDocMap.has(url) === false ) { return; }
|
if ( urlToDocMap.has(url) === false ) { return; }
|
||||||
const afterDoc = r !== undefined
|
const afterDoc = r !== undefined
|
||||||
|
@ -262,7 +276,7 @@ async function start() {
|
||||||
: beforeDoc;
|
: beforeDoc;
|
||||||
urlToDocMap.set(url, afterDoc);
|
urlToDocMap.set(url, afterDoc);
|
||||||
if ( currentURL !== url ) { return; }
|
if ( currentURL !== url ) { return; }
|
||||||
cmEditor.swapDoc(afterDoc);
|
swapDoc(afterDoc);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,18 @@
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchWidgetInputHandler = function(cm) {
|
const searchWidgetInputHandler = function(cm, ev) {
|
||||||
let state = getSearchState(cm);
|
const state = getSearchState(cm);
|
||||||
|
if ( ev.isTrusted !== true ) {
|
||||||
|
if ( state.queryText === '' ) {
|
||||||
|
clearSearch(cm);
|
||||||
|
} else {
|
||||||
|
cm.operation(function() {
|
||||||
|
startSearch(cm, state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ( queryTextFromSearchWidget(cm) === state.queryText ) { return; }
|
if ( queryTextFromSearchWidget(cm) === state.queryText ) { return; }
|
||||||
if ( state.queryTimer !== null ) {
|
if ( state.queryTimer !== null ) {
|
||||||
clearTimeout(state.queryTimer);
|
clearTimeout(state.queryTimer);
|
||||||
|
|
Loading…
Reference in New Issue