Skip to content

Commit be8c75f

Browse files
committed
Add auto-complete suggestion to input variable
Use the lowest-level name of the last attribute. There was already logic for doing auto-insertion when the user enters a <, so this works as John requested.
1 parent 88d6ab0 commit be8c75f

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/main/java/edu/umich/soar/visualsoar/ruleeditor/RuleEditor.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,18 +1587,15 @@ public void actionPerformed(ActionEvent e) {
15871587
}
15881588
}
15891589

1590-
/**
1591-
* A simplified version of the TabCompleteAction that only displays
1592-
* the next possible attribute in the feedback window following the user
1593-
* typing a dot/period.
1594-
* Unlike the TabCompleteAction, this action does not ever insert anything
1595-
* into the rule editor, it only displays the attribute options in the feedback window.
1596-
* It also runs auto-justification.
1597-
*/
1598-
class AutoSoarCompleteAction extends AbstractAction {
1599-
private static final long serialVersionUID = 20221225L;
1600-
private final EditorPane editorPane;
1601-
private final Toolkit toolkit;
1590+
/**
1591+
* Similar to TabCompleteAction, but it never auto-inserts text, and it auto-justifies the text.
1592+
* This is run automatically when the user types a dot or left angle bracket. It also runs
1593+
* auto-justification.
1594+
*/
1595+
class AutoSoarCompleteAction extends AbstractAction {
1596+
private static final long serialVersionUID = 20221225L;
1597+
private final EditorPane editorPane;
1598+
private final Toolkit toolkit;
16021599

16031600
public AutoSoarCompleteAction(EditorPane editorPane, Toolkit toolkit) {
16041601
super("Auto Soar Complete");

src/main/java/edu/umich/soar/visualsoar/ruleeditor/SoarAutocomplete.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import org.jetbrains.annotations.Nullable;
1414

1515
import java.io.StringReader;
16+
import java.util.ArrayList;
1617
import java.util.Collections;
1718
import java.util.Iterator;
1819
import java.util.LinkedList;
1920
import java.util.List;
2021

22+
// TODO: Next: Write some tests. For variables, be sure to test "^ " (empty attribute name).
2123
public class SoarAutocomplete {
2224

2325
/**
@@ -87,7 +89,8 @@ else if (!periodMustBeMostSignificant
8789
private static AutocompleteContext valueComplete(
8890
String userType, String prodSoFar, String fullText, OperatorNode associatedNode)
8991
throws ParseException {
90-
List<String> completeMatches = getValueMatches(prodSoFar, fullText, associatedNode);
92+
List<String> completeMatches = getVariableMatches(prodSoFar);
93+
completeMatches.addAll(getValueMatches(prodSoFar, fullText, associatedNode));
9194
return new AutocompleteContext(userType, completeMatches);
9295
}
9396

@@ -132,6 +135,24 @@ private static List<String> getAttributeMatches(
132135
return completeMatches;
133136
}
134137

138+
private static List<String> getVariableMatches(String prodSoFar) {
139+
// given logic in caller, we know for a fact that there is a caret and a space, maybe a period
140+
int attStart = prodSoFar.lastIndexOf("^");
141+
int period = prodSoFar.lastIndexOf(".");
142+
if (period > attStart) {
143+
attStart = period;
144+
}
145+
attStart += 1;
146+
int attEnd = prodSoFar.lastIndexOf(" <$$>");
147+
148+
String attName = prodSoFar.substring(attStart, attEnd);
149+
List<String> variableMatches = new ArrayList<>();
150+
if (!attName.isEmpty()) {
151+
variableMatches.add("<" + attName + ">");
152+
}
153+
return variableMatches;
154+
}
155+
135156
/**
136157
* Retrieves the strings associated with entries in the datamap with values that match the user's
137158
* current production.

0 commit comments

Comments
 (0)