Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2017-09-14 05:25:35 -0400
committerAlexander Kurtakov2017-09-14 09:40:58 -0400
commit2b8d08aec84668f677c6b7e83ddfbbbf2afa2835 (patch)
tree325cf472a7bd1c8fbfe7149222f83eac7c4d9ac2
parent9a4e10eb08f09361fd9fdc63937033f8b7706565 (diff)
downloadorg.eclipse.dltk.sh-2b8d08aec84668f677c6b7e83ddfbbbf2afa2835.tar.gz
org.eclipse.dltk.sh-2b8d08aec84668f677c6b7e83ddfbbbf2afa2835.tar.xz
org.eclipse.dltk.sh-2b8d08aec84668f677c6b7e83ddfbbbf2afa2835.zip
Bug 520842 - As soon as the 'Indentation - Tab policy' is changed to
'Spaces' no more Tabs are possible Takes into account the current offset when generating indentation. Change-Id: I5c9a8b1fb837bf2014bfa1caf048c3d6da508473 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java13
1 files changed, 7 insertions, 6 deletions
diff --git a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
index 19cb4fb..16ea5b7 100644
--- a/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
+++ b/plugins/org.eclipse.dltk.sh.ui/src/org/eclipse/dltk/sh/internal/ui/text/ScriptAutoIndentStrategy.java
@@ -85,7 +85,9 @@ public class ScriptAutoIndentStrategy implements IAutoEditStrategy {
int line = document.getLineOfOffset(p);
int start = document.getLineOffset(line);
int bracketCount = getBracketCount(document, null, start, c.offset, true);
- buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount <= 0 ? 0 : 1));
+ String indentOfLine = getIndentOfLine(document, line, p);
+ String indentation = generateIndentation(indentOfLine, bracketCount <= 0 ? 0 : 1);
+ buf.append(indentation);
c.text = buf.toString();
} catch (BadLocationException x) {
// ignore
@@ -107,13 +109,13 @@ public class ScriptAutoIndentStrategy implements IAutoEditStrategy {
}
try {
StringBuilder buf = new StringBuilder();
- int p = c.offset == document.getLength() ? c.offset - 1 : c.offset;
+ int p = c.offset;
int line = document.getLineOfOffset(p);
int start = document.getLineOffset(line);
int whiteEnd = findEndOfWhiteSpace(document, start, c.offset);
int bracketCount = getBracketCount(document, c, start, c.offset, false);
- buf.append(generateIndentation(getIndentOfLine(document, line), bracketCount >= 0 ? 0 : -1));
+ buf.append(generateIndentation(getIndentOfLine(document, line, p), bracketCount >= 0 ? 0 : -1));
buf.append(document.get(whiteEnd, c.offset - whiteEnd));
buf.append(c.text);
// Alter the command
@@ -161,11 +163,10 @@ public class ScriptAutoIndentStrategy implements IAutoEditStrategy {
* - the line number being searched
* @return the string containing the indentation from the specified line
*/
- private static String getIndentOfLine(IDocument document, int line) throws BadLocationException {
+ private static String getIndentOfLine(IDocument document, int line, int offset) throws BadLocationException {
if (line > -1) {
int start = document.getLineOffset(line);
- int end = start + document.getLineLength(line);
- int whiteend = findEndOfWhiteSpace(document, start, end);
+ int whiteend = findEndOfWhiteSpace(document, start, offset);
return document.get(start, whiteend - start);
} else {
return "";

Back to the top