Skip to content

Commit 8b62850

Browse files
author
Paul Verest
committed
Merge pull request #23 from tuck182/master
When indenting, respect Eclipse editor preferences for tabs/spaces
2 parents f01485f + 2a90244 commit 8b62850

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

csep.ui/src/csep/ui/autoedit/IndentLineAutoEditStrategy.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package csep.ui.autoedit;
22

3+
import org.eclipse.core.runtime.Platform;
34
import org.eclipse.jface.text.BadLocationException;
45
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
56
import org.eclipse.jface.text.DocumentCommand;
@@ -12,6 +13,8 @@
1213
public class IndentLineAutoEditStrategy extends
1314
DefaultIndentLineAutoEditStrategy {
1415

16+
private static final String EDITORS_QUALIFIER = "org.eclipse.ui.editors";
17+
1518
/**
1619
* Start an indented block after certain lines
1720
*/
@@ -31,9 +34,20 @@ protected void indentBlock(IDocument d, DocumentCommand c) {
3134
int p = (c.offset == d.getLength() ? c.offset - 1 : c.offset);
3235
IRegion info= d.getLineInformationOfOffset(p);
3336
String line = d.get(info.getOffset(), info.getLength());
34-
if (Helper.isBlockContainer(line))
35-
// TODO: get actual indentation string
36-
c.text += "\t";
37+
if (Helper.isBlockContainer(line)) {
38+
if (Helper.isBlockContainer(line)) {
39+
boolean spacesForTabs = Platform.getPreferencesService().getBoolean(EDITORS_QUALIFIER,
40+
"spacesForTabs", false, null);
41+
if (spacesForTabs) {
42+
int tabWidth = Platform.getPreferencesService().getInt(EDITORS_QUALIFIER, "tabWidth", 4, null);
43+
for (int i = 0; i < tabWidth; i++) {
44+
c.text += " ";
45+
}
46+
} else {
47+
c.text += "\t";
48+
}
49+
}
50+
}
3751
}
3852
catch (BadLocationException e) {
3953
// do nothing

0 commit comments

Comments
 (0)