[autocomplete] 105/143: AutoComplete: Fixed bug: Template completions ending with a param/cursor, you couldn't cycle through the params properly. AutoComplete: Fixed bug: Multi-line template completions with tabs, when replacing tabs with spaces, could incorrectly calculate param offsets (e.g. "switch" in Java/JS support).

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:26 UTC 2013


This is an automated email from the git hooks/post-receive script.

ben pushed a commit to branch master
in repository autocomplete.

commit 1ecfa2a5916a907095f63f63363c27a677460692
Author: bobbylight <robert at fifesoft.com>
Date:   Sun Aug 12 04:50:06 2012 +0000

    AutoComplete: Fixed bug: Template completions ending with a param/cursor, you couldn't cycle through the params properly.
    AutoComplete: Fixed bug: Multi-line template completions with tabs, when replacing tabs with spaces, could incorrectly calculate param offsets (e.g. "switch" in Java/JS support).
---
 .../ParameterizedCompletionContext.java            |    2 +-
 .../fife/ui/autocomplete/TemplateCompletion.java   |   64 +++++++++++++-------
 2 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
index 8cd6fe4..fa99f4f 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
@@ -998,7 +998,7 @@ class ParameterizedCompletionContext {
 				return;
 			}
 			int dot = e.getDot();
-			if (dot<minPos || dot>=maxPos.getOffset()) {
+			if (dot<minPos || dot>maxPos.getOffset()) {
 				deactivate();
 				return;
 			}
diff --git a/src/org/fife/ui/autocomplete/TemplateCompletion.java b/src/org/fife/ui/autocomplete/TemplateCompletion.java
index 7c31734..4e727f1 100644
--- a/src/org/fife/ui/autocomplete/TemplateCompletion.java
+++ b/src/org/fife/ui/autocomplete/TemplateCompletion.java
@@ -20,6 +20,7 @@ import javax.swing.text.Position;
 
 import org.fife.ui.autocomplete.TemplatePiece.Param;
 import org.fife.ui.autocomplete.TemplatePiece.ParamCopy;
+import org.fife.ui.autocomplete.TemplatePiece.Text;
 import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
 
 
@@ -193,10 +194,16 @@ public class TemplateCompletion extends AbstractCompletion
 		for (int i=0; i<pieces.size(); i++) {
 			TemplatePiece piece = (TemplatePiece)pieces.get(i);
 			String text = getPieceText(i, leadingWS);
-			if (piece instanceof Param && "cursor".equals(text)) {
+			if (piece instanceof Text) {
 				if (replaceTabsWithSpaces) {
-					start = possiblyReplaceTabsWithSpaces(sb, tc, start);
+					start = possiblyReplaceTabsWithSpaces(sb, text, tc, start);
 				}
+				else {
+					sb.append(text);
+					start += text.length();
+				}
+			}
+			else if (piece instanceof Param && "cursor".equals(text)) {
 				defaultEndOffs = start;
 			}
 			else {
@@ -317,30 +324,41 @@ public class TemplateCompletion extends AbstractCompletion
 	}
 
 
-	private int possiblyReplaceTabsWithSpaces(StringBuffer sb, JTextComponent tc,
-											int start) {
+	private int possiblyReplaceTabsWithSpaces(StringBuffer sb, String text,
+											JTextComponent tc, int start) {
 
-		int size = 4;
-		Document doc = tc.getDocument();
-		if (doc != null) {
-			Integer i = (Integer) doc.getProperty(PlainDocument.tabSizeAttribute);
-			if (i != null) {
-				size = i.intValue();
-			}
-		}
-		String tab = "";
-		for (int i=0; i<size; i++) {
-			tab += " ";
-		}
+		int tab = text.indexOf('\t');
+		if (tab>-1) {
+
+			int startLen = sb.length();
 
-		int lastNewline = sb.lastIndexOf("\n");
-		int lineOffs = 0;
-		for (int j=lastNewline+1; j<sb.length(); j++) {
-			if (sb.charAt(j)=='\t') {
-				int count = size - (lineOffs%size);
-				sb.replace(j, j+1, tab.substring(0, count));
-				start += count - 1;
+			int size = 4;
+			Document doc = tc.getDocument();
+			if (doc != null) {
+				Integer i = (Integer) doc.getProperty(PlainDocument.tabSizeAttribute);
+				if (i != null) {
+					size = i.intValue();
+				}
+			}
+			String tabStr = "";
+			for (int i=0; i<size; i++) {
+				tabStr += " ";
 			}
+
+			int lastOffs = 0;
+			do {
+				sb.append(text.substring(lastOffs, tab));
+				sb.append(tabStr);
+				lastOffs = tab + 1;
+			} while ((tab=text.indexOf('\t', lastOffs))>-1);
+			sb.append(text.substring(lastOffs));
+
+			start += sb.length() - startLen;
+
+		}
+		else {
+			sb.append(text);
+			start += text.length();
 		}
 
 		return start;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git



More information about the pkg-java-commits mailing list