IDEA-162844 more correct fix

STR: https://youtrack.jetbrains.com/issue/IDEA-162774#comment=27-1678789)
This commit is contained in:
Vladimir Krivosheev
2016-10-28 14:46:46 +02:00
parent 5c7a1a647e
commit 94b4385ef1
3 changed files with 48 additions and 9 deletions
@@ -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<TextAttributesKey> 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()));
@@ -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 = """
<scheme name="Foo" version="142" parent_scheme="Default">
<metaInfo>
<property name="created">2016-09-29T12:13:05</property>
<property name="ide">idea</property>
<property name="ideVersion">2016.3.0.0</property>
<property name="modified">2016-09-29T12:14:54</property>
<property name="originalScheme">Default</property>
</metaInfo>
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_FONT_NAME" value="Menlo" />
<option name="JAVA_NUMBER" baseAttributes="DEFAULT_NUMBER" />
</scheme>""".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("""
<scheme name="Foo" version="142" parent_scheme="Default">
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_FONT_NAME" value="Menlo" />
</scheme>""".trimIndent())
assertThat(schemeFile.parent).hasChildren("Foo.icls")
}
}
@@ -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+<metaInfo>.*</metaInfo>", Pattern.DOTALL).matcher(result)
if (!matcher.find()) {
return result
}
val builder = StringBuffer()
matcher.appendReplacement(builder, "")
matcher.appendTail(builder)
return builder.toString()
}