X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategyDQ.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategyDQ.java index d7642bf..509c921 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategyDQ.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategyDQ.java @@ -162,7 +162,7 @@ public class JavaStringAutoIndentStrategyDQ extends String indentation = ""; int start; int end; - int length; + int length = 0; // find start of line int adjustedOffset = (offset == document.getLength() ? offset - 1 : offset);// Check whether the offset is not at the end of file @@ -172,7 +172,17 @@ public class JavaStringAutoIndentStrategyDQ extends end = findStringStart (document, start, offset); IPreferenceStore preferenceStore = PHPeclipsePlugin.getDefault().getPreferenceStore(); - length = end - start; + + int tabWidth = preferenceStore.getInt (PreferenceConstants.EDITOR_TAB_WIDTH); + + for (int pos = start; pos < end; pos++) { + if (document.getChar (pos) == '\t') { // If the character is a tab + length += tabWidth; // take the tab width for calculating the indentation length + } + else { // If it's just a space + length++; // add one character to the indentation length + } + } if (preferenceStore.getBoolean (PreferenceConstants.EDITOR_SPACES_FOR_TABS)) { // Indentation with spaces only if (length > 0) { @@ -182,14 +192,15 @@ public class JavaStringAutoIndentStrategyDQ extends else { // Indentation with tabs if (length > 0) { int spaces; - int tabs; - int tabWidth = preferenceStore.getInt (PreferenceConstants.EDITOR_TAB_WIDTH); - + int tabs; tabs = length / tabWidth; spaces = length % tabWidth; indentation = new String (new char[tabs]).replace('\0', '\t'); - indentation += String.format ("%" + spaces + "s", ""); + + if (spaces > 0) { + indentation += String.format ("%" + spaces + "s", ""); + } } }