From 94b4385ef1e16ac0f569dbedeb61ed764088cc4c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 28 Oct 2016 14:36:35 +0200 Subject: [PATCH] IDEA-162844 more correct fix STR: https://youtrack.jetbrains.com/issue/IDEA-162774#comment=27-1678789) --- .../colors/impl/AbstractColorsScheme.java | 9 +++++- .../editor/colors/EditorColorSchemeTest.kt | 18 ++++++----- .../editor/colors/editorColorScheme.kt | 30 +++++++++++++++++++ 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index 28fc81473e6e..60672f8bf92c 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -623,6 +623,12 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial } } + private boolean isParentOverwritingInheritance(@NotNull TextAttributesKey key) { + TextAttributes parentAttributes = + myParentScheme instanceof AbstractColorsScheme ? ((AbstractColorsScheme)myParentScheme).getDirectlyDefinedAttributes(key) : null; + return parentAttributes != null && parentAttributes != USE_INHERITED_MARKER; + } + private void writeAttributes(@NotNull Element attrElements) throws WriteExternalException { List list = new ArrayList<>(myAttributesMap.keySet()); list.sort(null); @@ -630,7 +636,8 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial TextAttributes attributes = myAttributesMap.get(key); TextAttributesKey baseKey = key.getFallbackAttributeKey(); if (attributes == USE_INHERITED_MARKER) { - if (baseKey != null) { + // do not store if inheritance = on in the parent scheme (https://youtrack.jetbrains.com/issue/IDEA-162774) + if (baseKey != null && isParentOverwritingInheritance(key)) { attrElements.addContent(new Element(OPTION_ELEMENT) .setAttribute(NAME_ATTR, key.getExternalName()) .setAttribute(BASE_ATTRIBUTES_ATTR, baseKey.getExternalName())); diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/EditorColorSchemeTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/EditorColorSchemeTest.kt index 0a16a493729a..dacc78257b15 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/EditorColorSchemeTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/colors/EditorColorSchemeTest.kt @@ -17,6 +17,7 @@ package com.intellij.openapi.editor.colors import com.intellij.configurationStore.SchemeManagerFactoryBase import com.intellij.openapi.editor.colors.ex.DefaultColorSchemesManager +import com.intellij.openapi.editor.colors.impl.AbstractColorsScheme import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl import com.intellij.testFramework.InMemoryFsRule import com.intellij.testFramework.ProjectRule @@ -43,15 +44,9 @@ class EditorColorSchemeTest { val schemeFile = fsRule.fs.getPath("colors/Foo.icls") val schemeData = """ - - 2016-09-29T12:13:05 - idea - 2016.3.0.0 - 2016-09-29T12:14:54 - Default - """.trimIndent() schemeFile.write(schemeData) val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(fsRule.fs.getPath("")) @@ -60,9 +55,16 @@ class EditorColorSchemeTest { val scheme = manager.getScheme("Foo") assertThat(scheme.name).isEqualTo("Foo") + (scheme as AbstractColorsScheme).isSaveNeeded = true + schemeManagerFactory.save() - assertThat(schemeFile.readText()).isEqualTo(schemeData) + // JAVA_NUMBER is removed - see isParentOverwritingInheritance + assertThat(removeSchemeMetaInfo(schemeFile.readText())).isEqualTo(""" + + """.trimIndent()) assertThat(schemeFile.parent).hasChildren("Foo.icls") } } diff --git a/platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt b/platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt new file mode 100644 index 000000000000..08b20e33c86e --- /dev/null +++ b/platform/testFramework/testSrc/com/intellij/openapi/editor/colors/editorColorScheme.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.editor.colors + +import java.util.regex.Pattern + +fun removeSchemeMetaInfo(result: String): String { + val matcher = Pattern.compile("\\s+.*", Pattern.DOTALL).matcher(result) + if (!matcher.find()) { + return result + } + + val builder = StringBuffer() + matcher.appendReplacement(builder, "") + matcher.appendTail(builder) + return builder.toString() +} \ No newline at end of file