Skip to content

Commit c3da137

Browse files
committed
fix: preference for color inline preview not working
1 parent a0b0ead commit c3da137

File tree

1 file changed

+14
-9
lines changed
  • src/extensionsIntegrated/CSSColorPreview

1 file changed

+14
-9
lines changed

src/extensionsIntegrated/CSSColorPreview/main.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ define(function (require, exports, module) {
4646
MULTI_COLOR_PREVIEW_CLASS = "ico-multiple-cssColorPreview",
4747
COLOR_PREVIEW_GUTTER_PRIORITY = 200,
4848
COLOR_LANGUAGES= ["css", "scss", "less", "sass", "stylus", "html", "svg", "jsx", "tsx",
49-
"php", "ejs", "erb_html", "pug"];
49+
"php", "ejs", "erb_html", "pug"],
50+
COLOR_LANGUAGES_SET = new Set(COLOR_LANGUAGES);
5051

5152

5253
// For preferences settings, to toggle this feature on/off
@@ -59,7 +60,7 @@ define(function (require, exports, module) {
5960
description: Strings.DESCRIPTION_CSS_COLOR_PREVIEW
6061
});
6162

62-
PreferencesManager.definePreference(PREFERENCES_INLINE_COLOR_PREVIEW, "boolean", enabled, {
63+
PreferencesManager.definePreference(PREFERENCES_INLINE_COLOR_PREVIEW, "boolean", inlinePreviewEnabled, {
6364
description: Strings.DESCRIPTION_CSS_COLOR_PREVIEW_INLINE
6465
});
6566

@@ -76,7 +77,7 @@ define(function (require, exports, module) {
7677
}
7778

7879
const editor = EditorManager.getActiveEditor();
79-
if (editor) {
80+
if (editor && editor.isGutterActive(GUTTER_NAME)) {
8081
showGutters(editor, _getAllColorsAndLineNums(editor));
8182
}
8283
}
@@ -217,6 +218,10 @@ define(function (require, exports, module) {
217218
function _applyInlineColor(editor, line) {
218219
editor._currentlyColorMarkedLine = line;
219220
editor.clearAllMarks(COLOR_MARK_NAME);
221+
const editorLanguage = editor.document.getLanguage().getId();
222+
if(!COLOR_LANGUAGES_SET.has(editorLanguage)) {
223+
return;
224+
}
220225
const colors = detectValidColorsInLine(editor, line);
221226
for(let color of colors){
222227
_colorMark(editor, {line, ch: color.index}, {line, ch: color.index + color.color.length},
@@ -230,10 +235,7 @@ define(function (require, exports, module) {
230235
if(enabled){
231236
_addDummyGutterMarkerIfNotExist(editor, line);
232237
}
233-
if(!inlinePreviewEnabled){
234-
return;
235-
}
236-
if(editor.hasSelection()){
238+
if(editor.hasSelection() || !inlinePreviewEnabled){
237239
if(editor._currentlyColorMarkedLine === line){
238240
editor._currentlyColorMarkedLine = null;
239241
editor.clearAllMarks(COLOR_MARK_NAME);
@@ -255,7 +257,7 @@ define(function (require, exports, module) {
255257

256258
// Add listener for all editor changes
257259
EditorManager.on("activeEditorChange", function (event, newEditor, oldEditor) {
258-
if (newEditor && newEditor.isGutterActive(GUTTER_NAME)) {
260+
if (newEditor) {
259261
newEditor.off("cursorActivity.colorPreview");
260262
newEditor.on("cursorActivity.colorPreview", _cursorActivity);
261263
// Unbind the previous editor's change event if it exists
@@ -435,14 +437,17 @@ define(function (require, exports, module) {
435437
*/
436438
function onChanged(_evt, instance, changeList) {
437439
// for insertion and deletion, update the changed lines
438-
if(!changeList || !changeList.length || !enabled) {
440+
if(!changeList || !changeList.length) {
439441
return;
440442
}
441443
const changeObj = changeList[0];
442444
instance._currentlyColorMarkedLine = null;
443445
if(inlinePreviewEnabled && changeObj.origin && changeObj.origin.startsWith("+InlineColorEditor")){
444446
_applyInlineColor(instance, instance.getCursorPos().line);
445447
}
448+
if(!enabled){
449+
return;
450+
}
446451
if(changeList.length === 1 && changeObj.origin === '+input' || changeObj.origin === '+delete') {
447452
// we only do the diff updates on single key type input/delete and not bulk changes
448453
// somehow the performance degrades if we do the diff logic on large blocks.

0 commit comments

Comments
 (0)