From 6ff72af4aae9f7c53f7d478983d3667ee6da1dad Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 11 Oct 2020 07:45:58 -0400 Subject: [PATCH] Only URLs in comments can be selected through double-click --- src/js/codemirror/ubo-static-filtering.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 7f6299dfe..656aaa0c1 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -578,16 +578,24 @@ CodeMirror.registerHelper('fold', 'ubo-static-filtering', (( ) => { return Pass; } } - const s = cm.getLine(line); - // Select URL - let lmatch = /\bhttps?:\/\/\S+$/.exec(s.slice(0, ch)); - let rmatch = /^\S+/.exec(s.slice(ch)); + const s = cm.getLine(line); + const token = cm.getTokenTypeAt(pos); + let lmatch, rmatch; + let select = false; + + // Select URL in comments + if ( token === 'comment link' ) { + lmatch = /\S+$/.exec(s.slice(0, ch)); + rmatch = /^\S+/.exec(s.slice(ch)); + select = lmatch !== null && rmatch !== null && + /^https?:\/\//.test(s.slice(lmatch.index)); + } // TODO: add more convenient word-matching cases here - // if ( lmatch === null || rmatch === null ) { ... } + // if ( select === false ) { ... } - if ( lmatch === null || rmatch === null ) { return Pass; } + if ( select === false ) { return Pass; } cm.setSelection( { line, ch: lmatch.index }, { line, ch: ch + rmatch.index + rmatch[0].length }