colorpicker always picks up the only color in a line

This commit is contained in:
tophf 2017-11-24 00:56:38 +03:00
parent 7c0d8f0841
commit 15c5df0e6e

View File

@ -437,16 +437,21 @@
const lineText = this.cm.getLine(line); const lineText = this.cm.getLine(line);
const lineTextLC = lineText.toLowerCase(); const lineTextLC = lineText.toLowerCase();
const atImportant = lineTextLC.lastIndexOf('!important', ch); const atImportant = lineTextLC.lastIndexOf('!important', ch);
ch -= (atImportant >= Math.max(0, ch - '!important'.length)) ? '!important'.length : 0; if (atImportant >= Math.max(0, ch - '!important'.length)) {
const lineCache = this.cm.state.colorpicker.cache.get(lineText); ch -= Math.max(0, ch - atImportant);
}
const data = {line, ch, colorValue: color, isShortCut: true}; const data = {line, ch, colorValue: color, isShortCut: true};
for (const [start, {color, colorValue = color}] of lineCache && lineCache.entries() || []) { const lineCache = this.cm.state.colorpicker.cache.get(lineText);
if (start <= ch && ch <= start + color.length) { if (lineCache) {
for (const [start, {color, colorValue = color}] of lineCache.entries()) {
// one entry is for lastAccessTime
if (lineCache.size === 2 || start <= ch && ch <= start + color.length) {
Object.assign(data, {ch: start, color, colorValue}); Object.assign(data, {ch: start, color, colorValue});
this.openPopupForToken({colorpickerData: data}); this.openPopupForToken({colorpickerData: data});
return; return;
} }
} }
}
Object.assign(data, parseColorAtCursor(lineText, lineTextLC, ch)); Object.assign(data, parseColorAtCursor(lineText, lineTextLC, ch));
this.openPopupForToken({colorpickerData: data}); this.openPopupForToken({colorpickerData: data});
} }