mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Fix various quirks with "My filters" trust-related checkbox
Simplify code to force syntax highlighter and linter to reprocess the content when toggling trust-related checkbox. Fix issue with using `mousedown` on searchbar widgets, related feedback: https://github.com/uBlockOrigin/uBlock-issues/issues/3161#issuecomment-2002112770 Fix issues reported by eslint.
This commit is contained in:
parent
58c935aa9e
commit
0cb6170584
3 changed files with 185 additions and 198 deletions
|
@ -21,12 +21,10 @@
|
|||
|
||||
/* global CodeMirror, uBlockDashboard */
|
||||
|
||||
'use strict';
|
||||
|
||||
import { onBroadcast } from './broadcast.js';
|
||||
import './codemirror/ubo-static-filtering.js';
|
||||
import { dom, qs$ } from './dom.js';
|
||||
import { i18n$ } from './i18n.js';
|
||||
import './codemirror/ubo-static-filtering.js';
|
||||
import { onBroadcast } from './broadcast.js';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
@ -123,10 +121,6 @@ function setEditorText(text) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/codemirror/codemirror5/issues/3318
|
||||
// "How could I force to redraw the highlight of all the lines?"
|
||||
// "Resetting the mode option with setOption will trigger a full re-parse."
|
||||
|
||||
function userFiltersChanged(details = {}) {
|
||||
const changed = typeof details.changed === 'boolean'
|
||||
? details.changed
|
||||
|
@ -138,8 +132,19 @@ function userFiltersChanged(details = {}) {
|
|||
const trustedbefore = cmEditor.getOption('trustedSource');
|
||||
const trustedAfter = enabled && qs$('#trustMyFilters input').checked;
|
||||
if ( trustedAfter === trustedbefore ) { return; }
|
||||
cmEditor.setOption('mode', 'ubo-static-filtering');
|
||||
cmEditor.startOperation();
|
||||
cmEditor.setOption('trustedSource', trustedAfter);
|
||||
const doc = cmEditor.getDoc();
|
||||
const history = doc.getHistory();
|
||||
const selections = doc.listSelections();
|
||||
doc.replaceRange(doc.getValue(),
|
||||
{ line: 0, ch: 0 },
|
||||
{ line: doc.lineCount(), ch: 0 }
|
||||
);
|
||||
doc.setSelections(selections);
|
||||
doc.setHistory(history);
|
||||
cmEditor.endOperation();
|
||||
cmEditor.focus();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
// Ctrl-G.
|
||||
// =====
|
||||
|
||||
'use strict';
|
||||
|
||||
import { dom, qs$ } from '../dom.js';
|
||||
import { i18n$ } from '../i18n.js';
|
||||
|
||||
|
@ -45,7 +43,7 @@ import { i18n$ } from '../i18n.js';
|
|||
const searchOverlay = function(query, caseInsensitive) {
|
||||
if ( typeof query === 'string' )
|
||||
query = new RegExp(
|
||||
query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'),
|
||||
query.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'),
|
||||
caseInsensitive ? 'gi' : 'g'
|
||||
);
|
||||
else if ( !query.global )
|
||||
|
@ -98,7 +96,7 @@ import { i18n$ } from '../i18n.js';
|
|||
state.queryTimer.offon(350);
|
||||
};
|
||||
|
||||
const searchWidgetClickHandler = function(cm, ev) {
|
||||
const searchWidgetClickHandler = (ev, cm) => {
|
||||
if ( ev.button !== 0 ) { return; }
|
||||
const target = ev.target;
|
||||
const tcl = target.classList;
|
||||
|
@ -117,9 +115,7 @@ import { i18n$ } from '../i18n.js';
|
|||
}
|
||||
}
|
||||
if ( target.localName !== 'input' ) {
|
||||
ev.preventDefault();
|
||||
} else {
|
||||
ev.stopImmediatePropagation();
|
||||
cm.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -143,7 +139,9 @@ import { i18n$ } from '../i18n.js';
|
|||
this.widget = widgetParent.children[0];
|
||||
this.widget.addEventListener('keydown', searchWidgetKeydownHandler.bind(null, cm));
|
||||
this.widget.addEventListener('input', searchWidgetInputHandler.bind(null, cm));
|
||||
this.widget.addEventListener('mousedown', searchWidgetClickHandler.bind(null, cm));
|
||||
this.widget.addEventListener('click', ev => {
|
||||
searchWidgetClickHandler(ev, cm);
|
||||
});
|
||||
if ( typeof cm.addPanel === 'function' ) {
|
||||
this.panel = cm.addPanel(this.widget);
|
||||
}
|
||||
|
@ -252,10 +250,7 @@ import { i18n$ } from '../i18n.js';
|
|||
notation: 'compact',
|
||||
maximumSignificantDigits: 3
|
||||
});
|
||||
if (
|
||||
intl.resolvedOptions instanceof Function &&
|
||||
intl.resolvedOptions().hasOwnProperty('notation')
|
||||
) {
|
||||
if ( intl.resolvedOptions().notation ) {
|
||||
intlNumberFormat = intl;
|
||||
}
|
||||
}
|
||||
|
@ -346,9 +341,6 @@ import { i18n$ } from '../i18n.js';
|
|||
state.annotate.update(annotations);
|
||||
});
|
||||
state.widget.setAttribute('data-query', state.queryText);
|
||||
// Ensure the caret is visible
|
||||
const input = state.widget.querySelector('.cm-search-widget-input input');
|
||||
input.selectionStart = input.selectionStart;
|
||||
};
|
||||
|
||||
const findNext = function(cm, dir, callback) {
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
/* global CodeMirror */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
import * as sfp from '../static-filtering-parser.js';
|
||||
|
@ -577,7 +575,7 @@ function initHints() {
|
|||
|
||||
const getExtScriptletHints = function(cursor, line) {
|
||||
const beg = cursor.ch;
|
||||
const matchLeft = /#\+\js\(([^,]*)$/.exec(line.slice(0, beg));
|
||||
const matchLeft = /#\+js\(([^,]*)$/.exec(line.slice(0, beg));
|
||||
const matchRight = /^([^,)]*)/.exec(line.slice(beg));
|
||||
if ( matchLeft === null || matchRight === null ) { return; }
|
||||
const hints = [];
|
||||
|
@ -1103,16 +1101,8 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {
|
|||
};
|
||||
|
||||
self.addEventListener('trustedSource', ev => {
|
||||
const { cm, trusted } = ev.detail;
|
||||
const { trusted } = ev.detail;
|
||||
astParser.options.trustedSource = trusted;
|
||||
const doc = cm.getDoc();
|
||||
const lineCount = doc.lineCount();
|
||||
onBeforeChanges(cm, {
|
||||
from: { line: 0, ch: 0 },
|
||||
to: { line: lineCount, ch: 0 },
|
||||
});
|
||||
changeset.push({ from: 0, to: lineCount });
|
||||
processChangesetAsync(doc);
|
||||
});
|
||||
|
||||
self.addEventListener('trustedScriptletTokens', ev => {
|
||||
|
|
Loading…
Reference in a new issue