Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 344459

Summary: Indentation incorrect if formatting selection in XML file and first line is not selected completely
Product: [WebTools] WTP Source Editing Reporter: Tobias Oberlies <t-oberlies>
Component: wst.xmlAssignee: wst.xml <wst.xml-inbox>
Status: NEW --- QA Contact: Nick Sandonato <nsand.dev>
Severity: normal    
Priority: P3 CC: stan
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Tobias Oberlies CLA 2011-05-02 10:17:19 EDT
When I select a part of an XML file, and the selection starts directly at the first selected element (i.e. it does not include any whitespace before the first element), hitting CTRL+SHIFT+F formats the selection with an incorrect indentation.

Steps to reproduce:
1) Create a simple XML file with at least three levels of nesting, e.g.

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<selected>
		<inner></inner>
			<inner></inner>
	</selected>
</root>

2) Select an element below the root element completely, e.g. by placing the cursor inside the element and pressing SHIFT+ALT+UP-ARROW one or more times. In the example, the following shall be selected (and ^ and $ mark beginning and end of the selection):

<?xml version="1.0" encoding="UTF-8"?>
<root>
	^<selected>
		<inner></inner>
			<inner></inner>
	</selected>$
</root>

3) Format the selection (CTRL+SHIFT+F). From the second line, the indentation is incorrect:

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<selected>
	<inner></inner>
	<inner></inner>
</selected>
</root>

The result should be the same as if the whole file was formatted, i.e.

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<selected>
		<inner></inner>
		<inner></inner>
	</selected>
</root>
Comment 1 Stanislav Marencik CLA 2013-04-12 09:54:51 EDT
In my case the selected has result indent always one tab (4 spaces in my case)
    <dependencies>
        ^<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>$

ctrl+shift+F
An the result is:
    <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>