Problem
If indent_style = tab and indent_size = 2 (or anything other than 1) the XML editor behaves incorrectly. The tabs will (correctly) be the width specified by indent_size but indentation will be done with a number of tabs equal to the indent_size instead of just a single tab. (The reason 1 works is because it will use only one tab which will be only one unit wide. It looks ugly but technically behaves correctly.)
Steps to reproduce
- Have this plugin installed (of course)
- Use
indent_style = tab and any indent_size bigger than 1
- Format any XML file
Notes
I believe the issue is on this line. The problem is due to an oddity of the XML editor. The "indentation size" option is not how many units the indentation is, it is how many of the indentation character (see here) to use. (Why they have it set up like this is beyond me. It seems silly. I can't imagine anyone ever wanting to use multiple tabs to represent a single level of indentation.)
The simplest solution would be something like below.
@Override
public void visitIndentStyle(final ConfigProperty<IndentStyleOption> property) {
// ...
setPreference("org.eclipse.wst.xml.core", "indentationChar", spacesForTabs ? "space" : "tab");
// add this conditional to set size to 1 is using tabs
if (!spacesForTabs) {
setPreference("org.eclipse.wst.xml.core", "indentationSize", "1");
}
// ...
}
@Override
public void visitIndentSize(final ConfigProperty<Integer> property) {
// ...
// add this conditional to only set indent size when using spaces
if (<using spaces>) { // Not sure how to get that property here though...
setPreference("org.eclipse.wst.xml.core", "indentationSize", indentSizeString);
}
// ...
}
The only issue is not having access to the ConfigProperty for IndentStyleOption inside visitIndentSize. An alternative would be to make sure visitIndentStyle is called after visitIndentSize so it can override if it is needed, but I don't know how easy that would be with this code base, I haven't looked too far into it.
Problem
If
indent_style = tabandindent_size = 2(or anything other than1) the XML editor behaves incorrectly. The tabs will (correctly) be the width specified byindent_sizebut indentation will be done with a number of tabs equal to theindent_sizeinstead of just a single tab. (The reason1works is because it will use only one tab which will be only one unit wide. It looks ugly but technically behaves correctly.)Steps to reproduce
indent_style = taband anyindent_sizebigger than1Notes
I believe the issue is on this line. The problem is due to an oddity of the XML editor. The "indentation size" option is not how many units the indentation is, it is how many of the indentation character (see here) to use. (Why they have it set up like this is beyond me. It seems silly. I can't imagine anyone ever wanting to use multiple tabs to represent a single level of indentation.)
The simplest solution would be something like below.
The only issue is not having access to the
ConfigPropertyforIndentStyleOptioninsidevisitIndentSize. An alternative would be to make surevisitIndentStyleis called aftervisitIndentSizeso it can override if it is needed, but I don't know how easy that would be with this code base, I haven't looked too far into it.