From 352846c8b422120170900900781dcf3cf975e2db Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 21 Nov 2017 18:38:07 +0300 Subject: [PATCH] fix and update ColorView.openPopup() --- vendor-overwrites/colorpicker/colorview.js | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/vendor-overwrites/colorpicker/colorview.js b/vendor-overwrites/colorpicker/colorview.js index 7bf179ce..3fa3c554 100644 --- a/vendor-overwrites/colorpicker/colorview.js +++ b/vendor-overwrites/colorpicker/colorview.js @@ -397,23 +397,16 @@ this.cm.state.colorpicker = null; } - openPopup(defaultColor = '#FFFFFF') { - const cursor = this.cm.getCursor(); - const data = { - line: cursor.line, - ch: cursor.ch, - color: defaultColor, - isShortCut: true, - }; - for (const {from, marker} of this.cm.getLineHandle(cursor.line).markedSpans || []) { - if (from <= data.ch && (marker.replacedWith || {}).colorpickerData) { - const {color, colorValue} = marker.replacedWith.colorpickerData; - if (data.ch <= from + color.length) { - data.ch = from; - data.color = color; - data.colorValue = colorValue; - break; - } + openPopup(color) { + let {line, ch} = this.cm.getCursor(); + const lineText = this.cm.getLine(line); + ch -= (lineText.lastIndexOf('!important', ch) >= ch - '!important'.length) ? '!important'.length : 0; + const lineCache = this.cm.state.colorpicker.cache.get(lineText); + const data = {line, ch, color, isShortCut: true}; + for (const [start, {color, colorValue}] of lineCache && lineCache.entries() || []) { + if (start <= ch && ch <= start + color.length) { + Object.assign(data, {ch: start, color, colorValue}); + break; } } this.openPopupForToken({colorpickerData: data}); @@ -426,8 +419,8 @@ top, left, cm: this.cm, - color: data.colorValue || data.color, - prevColor: data.color, + color: data.colorValue || data.color || '#fff', + prevColor: data.color || '', isShortCut: false, callback: ColorMarker.popupOnChange, }));