Skip to content

XML Editor behaves incorrectly when using tabs and indent_size other than 1 #41

@JacksonBailey

Description

@JacksonBailey

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

  1. Have this plugin installed (of course)
  2. Use indent_style = tab and any indent_size bigger than 1
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions