From 3152a7ebfeff980c0a77d6d5c87c83599e0f7488 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 23 Nov 2017 14:13:07 +0300 Subject: [PATCH] simpler plain string method for same token check --- edit/match-highlighter-helper.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/edit/match-highlighter-helper.js b/edit/match-highlighter-helper.js index 6036d8ce..2d3ed913 100644 --- a/edit/match-highlighter-helper.js +++ b/edit/match-highlighter-helper.js @@ -69,11 +69,13 @@ return; } const {line, ch} = this.getCursor(); - const rx = query instanceof RegExp ? query : new RegExp(`\\b${query}\\b`); - const start = Math.max(0, ch - rx.source.length + 4 + 1); - const end = ch + rx.source.length - 4; + const rx = query instanceof RegExp && query; + const queryLen = rx ? rx.source.length - 4 : query.length; + const start = Math.max(0, ch - queryLen + 1); + const end = ch + queryLen; const area = this.getLine(line).substring(start, end); - const startInArea = (area.match(rx) || {}).index; + const startInArea = rx ? (area.match(rx) || {}).index : + (area.indexOf(query) + 1 || NaN) - 1; if (start + startInArea <= ch) { // same token on cursor => prevent the highlighter from rerunning state.stylusMHLHelper = {