1) Fixed calculation of the new indentation method of splitted strings.
authorrobekras <robert.kraske@weihenstephan.org>
Sun, 23 Dec 2012 21:18:12 +0000 (22:18 +0100)
committerrobekras <robert.kraske@weihenstephan.org>
Sun, 23 Dec 2012 21:20:26 +0000 (22:20 +0100)
Signed-off-by: robekras <robert.kraske@weihenstephan.org>

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategyDQ.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java

index d7642bf..509c921 100644 (file)
@@ -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", "");
+                               }
                        }
                }               
                
index 0b29a0b..e4f4d54 100644 (file)
@@ -161,7 +161,7 @@ public class JavaStringAutoIndentStrategySQ 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
@@ -171,24 +171,36 @@ public class JavaStringAutoIndentStrategySQ 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) {
-                 indentation = String.format ("%" + length + "s", "");
-               }
+                               indentation = String.format ("%" + length + "s", "");
+                       }
                }
                else {                                                                                                                                                  // Indentation with tabs
                        if (length > 0) {
                                int spaces;
                                int tabs;
-                               int tabWidth = preferenceStore.getInt (PreferenceConstants.EDITOR_TAB_WIDTH);
 
                                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", "");
+                               }
                        }
                }               
 
@@ -212,7 +224,7 @@ public class JavaStringAutoIndentStrategySQ extends
                        }
                        
                        offset++;
-       }
+               }
 
                return end;
        }