From f9fd53f8fea249dfe9fde24c90b3913a0ff1c1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20No=C3=ABl?= Date: Sat, 9 Jun 2018 19:07:12 +0200 Subject: [PATCH] Fix xml indentation with indent_size != 1 --- .../editorconfig/eclipse/test/EditorConfigTest.java | 12 ++++++++++++ .../ui/internal/EditorConfigVisitor.java | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/editorconfig-eclipse-functional-test/src/main/java/com/ncjones/editorconfig/eclipse/test/EditorConfigTest.java b/editorconfig-eclipse-functional-test/src/main/java/com/ncjones/editorconfig/eclipse/test/EditorConfigTest.java index e07cca7..6c7d22d 100644 --- a/editorconfig-eclipse-functional-test/src/main/java/com/ncjones/editorconfig/eclipse/test/EditorConfigTest.java +++ b/editorconfig-eclipse-functional-test/src/main/java/com/ncjones/editorconfig/eclipse/test/EditorConfigTest.java @@ -79,4 +79,16 @@ public void testIndentStyleTab() throws Exception { assertThat(context.fileContents(fileName), equalTo("\t")); } + @Test + public void testIndentStyleTabWithSize() throws Exception { + context.editorConfig( + "root = true", + "[*]", + "indent_style = tab", + "indent_size = 2" + ); + context.editFile(fileName, "\t"); + assertThat(context.fileContents(fileName), equalTo("\t")); + } + } diff --git a/org.eclipse.editorconfig.ui/src/main/java/org/eclipse/editorconfig/ui/internal/EditorConfigVisitor.java b/org.eclipse.editorconfig.ui/src/main/java/org/eclipse/editorconfig/ui/internal/EditorConfigVisitor.java index 3cd0d80..a0ca88f 100644 --- a/org.eclipse.editorconfig.ui/src/main/java/org/eclipse/editorconfig/ui/internal/EditorConfigVisitor.java +++ b/org.eclipse.editorconfig.ui/src/main/java/org/eclipse/editorconfig/ui/internal/EditorConfigVisitor.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.editorconfig.core.ConfigProperty; +import org.eclipse.editorconfig.core.ConfigPropertyType; import org.eclipse.editorconfig.core.ConfigPropertyVisitor; import org.eclipse.editorconfig.core.EditorFileConfig; import org.eclipse.editorconfig.core.EndOfLineOption; @@ -51,13 +52,17 @@ public void visitIndentStyle(final ConfigProperty property) { @Override public void visitIndentSize(final ConfigProperty property) { final String indentSizeString = property.getValue().toString(); - setPreference("org.eclipse.wst.xml.core", "indentationSize", indentSizeString); - setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.indentation.size", indentSizeString); + // this represents the number of tabs, not their width + setPreference("org.eclipse.wst.xml.core", "indentationSize", + config.getConfigProperty(ConfigPropertyType.INDENT_STYLE.getName()).getValue().equals(IndentStyleOption.SPACE) + ? indentSizeString + : "1"); } @Override public void visitTabWidth(final ConfigProperty property) { final String tabWidth = property.getValue().toString(); + // xml editor will follow this setPreference("org.eclipse.ui.editors", "tabWidth", tabWidth); setPreference("org.eclipse.jdt.core", "org.eclipse.jdt.core.formatter.tabulation.size", tabWidth); setPreference("org.eclipse.ant.ui", "formatter_tab_size", tabWidth);