[autocomplete] 114/143: Make user overtype closing ')' when typing a method completion and they type the '(' explicitly.
Benjamin Mesing
ben at alioth.debian.org
Sat Oct 19 12:53:28 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 8ca6559c6de9e11c4461c2a4b38e3d0011fcfe52
Author: bobbylight <robert at fifesoft.com>
Date: Mon Sep 17 02:53:00 2012 +0000
Make user overtype closing ')' when typing a method completion and they type the '(' explicitly.
---
.../ui/autocomplete/AutoCompletePopupWindow.java | 2 +-
src/org/fife/ui/autocomplete/AutoCompletion.java | 48 ++++++++++++++------
.../fife/ui/autocomplete/FunctionCompletion.java | 12 ++---
.../ui/autocomplete/ParameterizedCompletion.java | 3 +-
.../ParameterizedCompletionContext.java | 46 ++++++++-----------
.../fife/ui/autocomplete/TemplateCompletion.java | 3 +-
6 files changed, 60 insertions(+), 54 deletions(-)
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index fb505c7..4d22903 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -303,7 +303,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
*
* @see #getSelection()
*/
- public void insertSelectedCompletion() {
+ private void insertSelectedCompletion() {
Completion comp = getSelection();
ac.insertCompletion(comp);
}
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java
index 9fcb8ef..8f9b25e 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -516,7 +516,21 @@ public class AutoCompletion {
*
* @param c A completion to insert. This cannot be <code>null</code>.
*/
- protected void insertCompletion(Completion c) {
+ protected final void insertCompletion(Completion c) {
+ insertCompletion(c, false);
+ }
+
+
+ /**
+ * Inserts a completion. Any time a code completion event occurs, the
+ * actual text insertion happens through this method.
+ *
+ * @param c A completion to insert. This cannot be <code>null</code>.
+ * @param typedParamListStartChar Whether the parameterized completion
+ * start character was typed (typically <code>'('</code>).
+ */
+ protected void insertCompletion(Completion c,
+ boolean typedParamListStartChar) {
JTextComponent textComp = getTextComponent();
String alreadyEntered = c.getAlreadyEntered(textComp);
@@ -536,7 +550,7 @@ public class AutoCompletion {
if (isParameterAssistanceEnabled() &&
(c instanceof ParameterizedCompletion)) {
ParameterizedCompletion pc = (ParameterizedCompletion)c;
- startParameterizedCompletionAssistance(pc, true);
+ startParameterizedCompletionAssistance(pc, typedParamListStartChar);
}
}
@@ -974,33 +988,39 @@ public class AutoCompletion {
/**
- * Displays a "tooltip" detailing the inputs to the function just entered.
+ * Displays a "tool tip" detailing the inputs to the function just entered.
*
* @param pc The completion.
- * @param addParamListStart Whether or not
- * {@link CompletionProvider#getParameterListStart()} should be
- * added to the text component.
+ * @param typedParamListStartChar Whether the parameterized completion list
+ * starting character was typed.
*/
private void startParameterizedCompletionAssistance(
- ParameterizedCompletion pc, boolean addParamListStart) {
+ ParameterizedCompletion pc, boolean typedParamListStartChar) {
- // Get rid of the previous tooltip window, if there is one.
+ // Get rid of the previous tool tip window, if there is one.
hideParameterCompletionPopups();
- // Don't bother with a tooltip if there are no parameters.
+ // Don't bother with a tool tip if there are no parameters, but if
+ // they typed e.g. the opening '(', make them overtype the ')'.
if (pc.getParamCount()==0 && !(pc instanceof TemplateCompletion)) {
CompletionProvider p = pc.getProvider();
char end = p.getParameterListEnd(); // Might be '\0'
String text = end=='\0' ? "" : Character.toString(end);
- if (addParamListStart) {
+ if (typedParamListStartChar) {
+ String template = "${}" + text + "${cursor}";
+ textComponent.replaceSelection(Character.toString(p.getParameterListStart()));
+ TemplateCompletion tc = new TemplateCompletion(p, null, null, template);
+ pc = tc;
+ }
+ else {
text = p.getParameterListStart() + text;
+ textComponent.replaceSelection(text);
+ return;
}
- textComponent.replaceSelection(text);
- return;
}
pcc = new ParameterizedCompletionContext(parentWindow, this, pc);
- pcc.activate(addParamListStart);
+ pcc.activate();
}
@@ -1216,7 +1236,7 @@ public class AutoCompletion {
Completion c = popupWindow.getSelection();
if (c instanceof ParameterizedCompletion) { // Should always be true
// Fixes capitalization of the entered text.
- insertCompletion(c);
+ insertCompletion(c, true);
}
}
diff --git a/src/org/fife/ui/autocomplete/FunctionCompletion.java b/src/org/fife/ui/autocomplete/FunctionCompletion.java
index 8f42b11..e56b4fa 100644
--- a/src/org/fife/ui/autocomplete/FunctionCompletion.java
+++ b/src/org/fife/ui/autocomplete/FunctionCompletion.java
@@ -147,15 +147,15 @@ public class FunctionCompletion extends VariableCompletion
public ParameterizedCompletionInsertionInfo getInsertionInfo(
- JTextComponent tc, boolean addParamStartList,
- boolean replaceTabsWithSpaces) {
+ JTextComponent tc, boolean replaceTabsWithSpaces) {
ParameterizedCompletionInsertionInfo info =
new ParameterizedCompletionInsertionInfo();
StringBuffer sb = new StringBuffer();
- if (addParamStartList) {
- sb.append(getProvider().getParameterListStart());
+ char paramListStart = getProvider().getParameterListStart();
+ if (paramListStart!='\0') {
+ sb.append(paramListStart);
}
int dot = tc.getCaretPosition() + sb.length();
int paramCount = getParamCount();
@@ -194,9 +194,7 @@ public class FunctionCompletion extends VariableCompletion
}
sb.append(getProvider().getParameterListEnd());
int endOffs = dot + sb.length();
- if (addParamStartList) {
- endOffs -= 1;//getProvider().getParameterListStart().length();
- }
+ endOffs -= 1;//getProvider().getParameterListStart().length();
info.addReplacementLocation(endOffs, endOffs); // offset after function
info.setDefaultEndOffs(endOffs);
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletion.java b/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
index 2b4531e..43098b8 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
@@ -50,8 +50,7 @@ public interface ParameterizedCompletion extends Completion {
public ParameterizedCompletionInsertionInfo getInsertionInfo(
- JTextComponent tc, boolean addParamStartList,
- boolean replaceTabsWithSpaces);
+ JTextComponent tc, boolean replaceTabsWithSpaces);
/**
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
index 81ea1c3..426329e 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionContext.java
@@ -189,11 +189,9 @@ class ParameterizedCompletionContext {
/**
* Activates parameter completion support.
*
- * @param addParamListStart Whether the parameter list start token should
- * be inserted at the caret position before the parameters.
* @see #deactivate()
*/
- public void activate(boolean addParamListStart) {
+ public void activate() {
if (active) {
return;
@@ -222,7 +220,7 @@ class ParameterizedCompletionContext {
}
}
- listener.install(tc, addParamListStart);
+ listener.install(tc);
// First time through, we'll need to create this window.
if (paramChoicesWindow==null) {
paramChoicesWindow = createParamChoicesWindow();
@@ -252,7 +250,7 @@ class ParameterizedCompletionContext {
* Hides any popup windows and terminates parameterized completion
* assistance.
*
- * @see #activate(boolean)
+ * @see #activate()
*/
public void deactivate() {
if (!active) {
@@ -927,26 +925,21 @@ class ParameterizedCompletionContext {
// Are they at or past the end of the parameters?
if (dot>=maxPos.getOffset()-2) { // ">=" for overwrite mode
- if (dot==maxPos.getOffset()-1) { // Happens in overwrite mode
- tc.replaceSelection(Character.toString(end));
- }
-
- else { // Typical case.
- // Try to decide if we're closing a paren that is a part
- // of the (last) arg being typed.
- String text = getArgumentText(dot);
- if (text!=null) {
- char start = pc.getProvider().getParameterListStart();
- int startCount = getCount(text, start);
- int endCount = getCount(text, end);
- if (startCount>endCount) { // Just closing a paren
- tc.replaceSelection(Character.toString(end));
- return;
- }
+ // Try to decide if we're closing a paren that is a part
+ // of the (last) arg being typed.
+ String text = getArgumentText(dot);
+ if (text!=null) {
+ char start = pc.getProvider().getParameterListStart();
+ int startCount = getCount(text, start);
+ int endCount = getCount(text, end);
+ if (startCount>endCount) { // Just closing a paren
+ tc.replaceSelection(Character.toString(end));
+ return;
}
- //tc.setCaretPosition(maxPos.getOffset());
- tc.setCaretPosition(tc.getCaretPosition()+1);
}
+ //tc.setCaretPosition(maxPos.getOffset());
+ tc.setCaretPosition(Math.min(tc.getCaretPosition()+1,
+ tc.getDocument().getLength()));
deactivate();
@@ -1073,12 +1066,9 @@ class ParameterizedCompletionContext {
* Installs this listener onto a text component.
*
* @param tc The text component to install onto.
- * @param addParamStartList Whether or not
- * {@link CompletionProvider#getParameterListStart()} should be
- * added to the text component.
* @see #uninstall()
*/
- public void install(JTextComponent tc, boolean addParamStartList) {
+ public void install(JTextComponent tc) {
boolean replaceTabs = false;
if (tc instanceof RSyntaxTextArea) {
@@ -1094,7 +1084,7 @@ class ParameterizedCompletionContext {
// Insert the parameter text
ParameterizedCompletionInsertionInfo info =
- pc.getInsertionInfo(tc, addParamStartList, replaceTabs);
+ pc.getInsertionInfo(tc, replaceTabs);
tc.replaceSelection(info.getTextToInsert());
// Add highlights around the parameters.
diff --git a/src/org/fife/ui/autocomplete/TemplateCompletion.java b/src/org/fife/ui/autocomplete/TemplateCompletion.java
index 4e727f1..1cde2ea 100644
--- a/src/org/fife/ui/autocomplete/TemplateCompletion.java
+++ b/src/org/fife/ui/autocomplete/TemplateCompletion.java
@@ -155,8 +155,7 @@ public class TemplateCompletion extends AbstractCompletion
public ParameterizedCompletionInsertionInfo getInsertionInfo(
- JTextComponent tc, boolean addParamStartList,
- boolean replaceTabsWithSpaces) {
+ JTextComponent tc, boolean replaceTabsWithSpaces) {
ParameterizedCompletionInsertionInfo info =
new ParameterizedCompletionInsertionInfo();
--
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