mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02: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
@ -21,12 +21,10 @@
|
|||||||
|
|
||||||
/* global CodeMirror, uBlockDashboard */
|
/* global CodeMirror, uBlockDashboard */
|
||||||
|
|
||||||
'use strict';
|
import './codemirror/ubo-static-filtering.js';
|
||||||
|
|
||||||
import { onBroadcast } from './broadcast.js';
|
|
||||||
import { dom, qs$ } from './dom.js';
|
import { dom, qs$ } from './dom.js';
|
||||||
import { i18n$ } from './i18n.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 = {}) {
|
function userFiltersChanged(details = {}) {
|
||||||
const changed = typeof details.changed === 'boolean'
|
const changed = typeof details.changed === 'boolean'
|
||||||
? details.changed
|
? details.changed
|
||||||
@ -138,8 +132,19 @@ function userFiltersChanged(details = {}) {
|
|||||||
const trustedbefore = cmEditor.getOption('trustedSource');
|
const trustedbefore = cmEditor.getOption('trustedSource');
|
||||||
const trustedAfter = enabled && qs$('#trustMyFilters input').checked;
|
const trustedAfter = enabled && qs$('#trustMyFilters input').checked;
|
||||||
if ( trustedAfter === trustedbefore ) { return; }
|
if ( trustedAfter === trustedbefore ) { return; }
|
||||||
cmEditor.setOption('mode', 'ubo-static-filtering');
|
cmEditor.startOperation();
|
||||||
cmEditor.setOption('trustedSource', trustedAfter);
|
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.
|
// Ctrl-G.
|
||||||
// =====
|
// =====
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
import { dom, qs$ } from '../dom.js';
|
import { dom, qs$ } from '../dom.js';
|
||||||
import { i18n$ } from '../i18n.js';
|
import { i18n$ } from '../i18n.js';
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ import { i18n$ } from '../i18n.js';
|
|||||||
const searchOverlay = function(query, caseInsensitive) {
|
const searchOverlay = function(query, caseInsensitive) {
|
||||||
if ( typeof query === 'string' )
|
if ( typeof query === 'string' )
|
||||||
query = new RegExp(
|
query = new RegExp(
|
||||||
query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'),
|
query.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&'),
|
||||||
caseInsensitive ? 'gi' : 'g'
|
caseInsensitive ? 'gi' : 'g'
|
||||||
);
|
);
|
||||||
else if ( !query.global )
|
else if ( !query.global )
|
||||||
@ -98,7 +96,7 @@ import { i18n$ } from '../i18n.js';
|
|||||||
state.queryTimer.offon(350);
|
state.queryTimer.offon(350);
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchWidgetClickHandler = function(cm, ev) {
|
const searchWidgetClickHandler = (ev, cm) => {
|
||||||
if ( ev.button !== 0 ) { return; }
|
if ( ev.button !== 0 ) { return; }
|
||||||
const target = ev.target;
|
const target = ev.target;
|
||||||
const tcl = target.classList;
|
const tcl = target.classList;
|
||||||
@ -117,9 +115,7 @@ import { i18n$ } from '../i18n.js';
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( target.localName !== 'input' ) {
|
if ( target.localName !== 'input' ) {
|
||||||
ev.preventDefault();
|
cm.focus();
|
||||||
} else {
|
|
||||||
ev.stopImmediatePropagation();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,7 +139,9 @@ import { i18n$ } from '../i18n.js';
|
|||||||
this.widget = widgetParent.children[0];
|
this.widget = widgetParent.children[0];
|
||||||
this.widget.addEventListener('keydown', searchWidgetKeydownHandler.bind(null, cm));
|
this.widget.addEventListener('keydown', searchWidgetKeydownHandler.bind(null, cm));
|
||||||
this.widget.addEventListener('input', searchWidgetInputHandler.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' ) {
|
if ( typeof cm.addPanel === 'function' ) {
|
||||||
this.panel = cm.addPanel(this.widget);
|
this.panel = cm.addPanel(this.widget);
|
||||||
}
|
}
|
||||||
@ -252,10 +250,7 @@ import { i18n$ } from '../i18n.js';
|
|||||||
notation: 'compact',
|
notation: 'compact',
|
||||||
maximumSignificantDigits: 3
|
maximumSignificantDigits: 3
|
||||||
});
|
});
|
||||||
if (
|
if ( intl.resolvedOptions().notation ) {
|
||||||
intl.resolvedOptions instanceof Function &&
|
|
||||||
intl.resolvedOptions().hasOwnProperty('notation')
|
|
||||||
) {
|
|
||||||
intlNumberFormat = intl;
|
intlNumberFormat = intl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,9 +341,6 @@ import { i18n$ } from '../i18n.js';
|
|||||||
state.annotate.update(annotations);
|
state.annotate.update(annotations);
|
||||||
});
|
});
|
||||||
state.widget.setAttribute('data-query', state.queryText);
|
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) {
|
const findNext = function(cm, dir, callback) {
|
||||||
|
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
/* global CodeMirror */
|
/* global CodeMirror */
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
import * as sfp from '../static-filtering-parser.js';
|
import * as sfp from '../static-filtering-parser.js';
|
||||||
@ -577,7 +575,7 @@ function initHints() {
|
|||||||
|
|
||||||
const getExtScriptletHints = function(cursor, line) {
|
const getExtScriptletHints = function(cursor, line) {
|
||||||
const beg = cursor.ch;
|
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));
|
const matchRight = /^([^,)]*)/.exec(line.slice(beg));
|
||||||
if ( matchLeft === null || matchRight === null ) { return; }
|
if ( matchLeft === null || matchRight === null ) { return; }
|
||||||
const hints = [];
|
const hints = [];
|
||||||
@ -1103,16 +1101,8 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.addEventListener('trustedSource', ev => {
|
self.addEventListener('trustedSource', ev => {
|
||||||
const { cm, trusted } = ev.detail;
|
const { trusted } = ev.detail;
|
||||||
astParser.options.trustedSource = trusted;
|
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 => {
|
self.addEventListener('trustedScriptletTokens', ev => {
|
||||||
|
Loading…
Reference in New Issue
Block a user