From d6c595d94e9c88cdb012075a5dd2902c17f04172 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 22 Dec 2017 16:46:30 +0300 Subject: [PATCH] detect double-clicked token boundaries better --- edit/codemirror-default.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/edit/codemirror-default.js b/edit/codemirror-default.js index 7e9700e2..8ffa9025 100644 --- a/edit/codemirror-default.js +++ b/edit/codemirror-default.js @@ -167,20 +167,23 @@ }); function selectTokenOnDoubleclick(cm, pos) { + let {ch} = pos; const {line} = pos; const text = cm.getLine(line); - const type = cm.getTokenTypeAt(pos); + const type = cm.getTokenTypeAt(pos) || + cm.getTokenTypeAt({line, ch: ch += 1}) || + cm.getTokenTypeAt({line, ch: ch -= 2}); const isCss = type && !/^(comment|string)/.test(type); const isNumber = type === 'number'; - let wordChars = isNumber ? /[-+\w.]/uy : isCss ? /[-#\w!]/uy : /[#\w]/uy; - let {ch} = pos; + let wordChars = isNumber ? /[-+\w.]/uy : isCss ? /[-\w]/uy : /\w/uy; let i = ch; while (i >= 0) { - wordChars.lastIndex = i--; + wordChars.lastIndex = i; if (!wordChars.test(text)) break; + i--; } - i += !i ? 0 : isCss && /^qualifier/.test(type) && text[i + 1] === '.' ? 1 : 2; + i += !i && wordChars.test(text[i]) || /[.!#]/.test(text[i]) ? 0 : 1; let j; if (isNumber) {