Skip to content
Browse files

Add support for partial comman names. For example, "tabprevious" can

now be accessed with "tabprev".
  • Loading branch information...
1 parent 63ecb2c commit 4e85b3e69f0da9e081454e23adfe77794a02425e @keforbes keforbes committed Mar 9, 2013
View
22 ...rge.vrapper.core/src/net/sourceforge/vrapper/vim/modes/commandline/CommandLineParser.java
@@ -396,16 +396,32 @@ public Command parseAndExecute(String first, String command) {
//tokenize based on whitespace
StringTokenizer nizer = new StringTokenizer(command);
- Queue<String> tokens = new LinkedList<String>();
+ LinkedList<String> tokens = new LinkedList<String>();
while(nizer.hasMoreTokens())
tokens.add(nizer.nextToken().trim());
//see if a command is defined for the first token
EvaluatorMapping platformCommands = editor.getPlatformSpecificStateProvider().getCommands();
- if(platformCommands != null && platformCommands.contains(tokens.peek()))
+ if(platformCommands != null && platformCommands.contains(tokens.peek())) {
platformCommands.evaluate(editor, tokens);
- else
+ }
+ else if(mapping != null && mapping.contains(tokens.peek())) {
mapping.evaluate(editor, tokens);
+ }
+ else { //see if there is a partial match
+ String commandName = platformCommands.getNameFromPartial(tokens.peek());
+ if(commandName != null) {
+ tokens.set(0, commandName);
+ platformCommands.evaluate(editor, tokens);
+ }
+ else {
+ commandName = mapping.getNameFromPartial(tokens.peek());
+ if(commandName != null) {
+ tokens.set(0, commandName);
+ mapping.evaluate(editor, tokens);
+ }
+ }
+ }
return null;
}
View
28 ...orge.vrapper.core/src/net/sourceforge/vrapper/vim/modes/commandline/EvaluatorMapping.java
@@ -53,6 +53,34 @@ public boolean contains(String key) {
public Evaluator getDefaultCase() {
return defaultCase;
}
+
+ /**
+ * Check to see if this partial name matches exactly one
+ * command name. If it does, return the full name of that
+ * command. If no match is found, or if multiple matches
+ * are found, return null.
+ * For example, getNameFromPartial("tabprev") returns "tabprevious"
+ * @param partial - String which may or may not be a subset of a command name
+ * @return Full command name if exactly one match, otherwise null
+ */
+ public String getNameFromPartial(String partial) {
+ String commandName = null;
+ for(String name : actions.keySet()) {
+ if(name.startsWith(partial)) {
+ if(commandName == null) {
+ //this is our first match
+ //(but keep looping in case there are more)
+ commandName = name;
+ }
+ else {
+ //multiple matches
+ return null;
+ }
+ }
+ }
+
+ return commandName;
+ }
/** Adds all actions from other EvaluatorMapping.
*

0 comments on commit 4e85b3e

Please sign in to comment.
Something went wrong with that request. Please try again.