diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index 1e2345cec..73682aedb 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -42,6 +42,8 @@ var cmEditor = new CodeMirror( } ); +uBlockDashboard.patchCodeMirrorEditor(cmEditor); + /******************************************************************************/ // This is to give a visual hint that the content of user blacklist has changed. diff --git a/src/js/dashboard-common.js b/src/js/dashboard-common.js index 47e04c5ca..db28b6b8a 100644 --- a/src/js/dashboard-common.js +++ b/src/js/dashboard-common.js @@ -112,6 +112,33 @@ self.uBlockDashboard.dateNowToSensibleString = function() { /******************************************************************************/ +self.uBlockDashboard.patchCodeMirrorEditor = (function() { + // https://github.com/gorhill/uBlock/issues/3646 + var patchSelectAll = function(cm, details) { + var vp = cm.getViewport(); + if ( details.ranges.length !== 1 ) { return; } + var range = details.ranges[0], + lineFrom = range.anchor.line, + lineTo = range.head.line; + if ( range.head.ch !== 0 ) { lineTo += 1; } + if ( lineFrom !== vp.from || lineTo !== vp.to ) { return; } + details.update([ + { + anchor: { line: 0, ch: 0 }, + head: { line: cm.lineCount(), ch: 0 } + } + ]); + }; + + return function(cm) { + if ( cm.options.inputStyle === 'contenteditable' ) { + cm.on('beforeSelectionChange', patchSelectAll); + } + }; +})(); + +/******************************************************************************/ + // Open links in the proper window uDom('a').attr('target', '_blank'); uDom('a[href*="dashboard.html"]').attr('target', '_parent'); diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js index d4feef23a..00036efb4 100644 --- a/src/js/dyna-rules.js +++ b/src/js/dyna-rules.js @@ -48,6 +48,8 @@ mergeView.editor().setOption('styleActiveLine', true); mergeView.editor().setOption('lineNumbers', false); mergeView.leftOriginal().setOption('readOnly', 'nocursor'); +uBlockDashboard.patchCodeMirrorEditor(mergeView.editor()); + var unfilteredRules = { orig: { doc: mergeView.leftOriginal(), rules: [] }, edit: { doc: mergeView.editor(), rules: [] } diff --git a/src/js/whitelist.js b/src/js/whitelist.js index 18ea4a933..13456f010 100644 --- a/src/js/whitelist.js +++ b/src/js/whitelist.js @@ -78,6 +78,8 @@ var cmEditor = new CodeMirror( } ); +uBlockDashboard.patchCodeMirrorEditor(cmEditor); + /******************************************************************************/ var whitelistChanged = function() {