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
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) {
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", "");
+ }
}
}
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
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", "");
+ }
}
}
}
offset++;
- }
+ }
return end;
}