From 8c502744dd312e3f65b94567bf07a7360101b962 Mon Sep 17 00:00:00 2001 From: robekras Date: Sun, 23 Dec 2012 22:18:12 +0100 Subject: [PATCH] 1) Fixed calculation of the new indentation method of splitted strings. Signed-off-by: robekras --- .../text/java/JavaStringAutoIndentStrategyDQ.java | 23 +++++++++++++---- .../text/java/JavaStringAutoIndentStrategySQ.java | 26 ++++++++++++++----- 2 files changed, 36 insertions(+), 13 deletions(-) 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", ""); + } } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java index 0b29a0b..e4f4d54 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/JavaStringAutoIndentStrategySQ.java @@ -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; } -- 1.7.1