From 74f180bbaa522b8d213405ba2ef6887a82ea8958 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 2 Jul 2018 18:48:15 +0300 Subject: [PATCH] IDEA-189920 Attribute inheritance flag in Editor color scheme is reverted on Apply --- .../editor/JavaEditorTextAttributesTest.java | 22 ++++++++++++++++--- .../colors/impl/EditorColorsSchemeImpl.java | 4 ++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/editor/JavaEditorTextAttributesTest.java b/java/java-tests/testSrc/com/intellij/java/editor/JavaEditorTextAttributesTest.java index ceb019a366de..ec75ea871a16 100644 --- a/java/java-tests/testSrc/com/intellij/java/editor/JavaEditorTextAttributesTest.java +++ b/java/java-tests/testSrc/com/intellij/java/editor/JavaEditorTextAttributesTest.java @@ -1,6 +1,9 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.editor; +import com.intellij.ide.highlighter.JavaHighlightingColors; +import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager; import com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl; @@ -20,9 +23,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -/** - * Ensures that Java attributes are not affected by changes in EditorColorScheme or these changes are planned and intentional. - */ +import static org.junit.Assert.assertNotEquals; + public class JavaEditorTextAttributesTest extends LightPlatformTestCase { private static List getDescriptors() { @@ -107,6 +109,9 @@ public class JavaEditorTextAttributesTest extends LightPlatformTestCase { return dumpBuilder.toString(); } + /** + * Ensures that Java attributes are not affected by changes in EditorColorScheme or these changes are planned and intentional. + */ public void testDefaultColorScheme() { assertEquals( "ABSTRACT_CLASS_NAME_ATTRIBUTES { color: #000000; font-style: normal; }\n" + @@ -211,4 +216,15 @@ public class JavaEditorTextAttributesTest extends LightPlatformTestCase { dumpDefaultColorScheme("Darcula") ); } + + public void testInheritanceFlagCanBeOverwrittenWithDefaultAttributes() { + EditorColorsScheme defaultScheme = EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME); + EditorColorsScheme editorScheme = (EditorColorsScheme)defaultScheme.clone(); + TextAttributes localVarAttrs = defaultScheme.getAttributes(JavaHighlightingColors.LOCAL_VARIABLE_ATTRIBUTES); + editorScheme.setAttributes(JavaHighlightingColors.LOCAL_VARIABLE_ATTRIBUTES, localVarAttrs); + TextAttributes changedAttrs = new TextAttributes(Color.BLUE, Color.WHITE, null, EffectType.BOXED, 0); + editorScheme.setAttributes(DefaultLanguageHighlighterColors.LOCAL_VARIABLE, changedAttrs); + TextAttributes attributes = editorScheme.getAttributes(JavaHighlightingColors.LOCAL_VARIABLE_ATTRIBUTES); + assertNotEquals(attributes, changedAttrs); + } } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java index f8a1a777b8d7..f3e508069b51 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/EditorColorsSchemeImpl.java @@ -51,7 +51,7 @@ public class EditorColorsSchemeImpl extends AbstractColorsScheme implements Exte if (TextAttributesKey.isTemp(key)) { myAttributesTempMap.put(key, attributes); } - else if (attributes == INHERITED_ATTRS_MARKER || !Comparing.equal(attributes, getAttributes(key))) { + else if (attributes == INHERITED_ATTRS_MARKER || !Comparing.equal(attributes, getDirectlyDefinedAttributes(key))) { myAttributesMap.put(key, attributes); myAttributesTempMap.clear(); } @@ -59,7 +59,7 @@ public class EditorColorsSchemeImpl extends AbstractColorsScheme implements Exte @Override public void setColor(ColorKey key, Color color) { - if (color == INHERITED_COLOR_MARKER || !Comparing.equal(color, getColor(key))) { + if (color == INHERITED_COLOR_MARKER || !Comparing.equal(color, getDirectlyDefinedColor(key))) { myColorsMap.put(key, ObjectUtils.notNull(color, NULL_COLOR_MARKER)); } }