Skip to content

Commit

Permalink
Stop further keymap state traversal after a miss.
Browse files Browse the repository at this point in the history
In theory this further traversal can only lead to trouble when an
operator is forgotten in the keymap states. In practice this might
occur, so stop this from happening as extra foolproofing.

Added extra test, though this isn't for the problem described above.

Fixes #415.
  • Loading branch information
albertdev committed May 15, 2014
1 parent 2b753e0 commit ce43b3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Expand Up @@ -224,6 +224,19 @@ public void testMotionsWithoutOMap() {
checkCommand(forKeySeq("dams"),
"so old", ' ', "McDonnaLD had some $LLaz",
"", 'o', "me $LLaz");

// sanity check
checkCommand(forKeySeq("df0"),
"so old", ' ', "McD0nnaLD had some $LLaz",
"so old", 'n', "naLD had some $LLaz");

type(parseKeyStrokes(":onoremap 0 0x<CR>"));
checkCommand(forKeySeq("d0"),
"so old", ' ', "McD0nnaLD had some $LLaz",
"", 'M', "cD0nnaLD had some $LLaz");
checkCommand(forKeySeq("df0"),
"so old", ' ', "McD0nnaLD had some $LLaz",
"so old", 'n', "naLD had some $LLaz");
}

@Test
Expand Down
Expand Up @@ -30,17 +30,16 @@ public final class KeyMapResolver {
public void press(KeyStroke key) {
if (currentState != null) {
Transition<String> trans = currentState.press(key);
if (trans != null) {
if (trans == null) {
currentState = null;
lastValue = null;
} else {
currentState = trans.getNextState();
lastValue = trans.getValue();
}
lastValue = getValue(trans);
}
}

private String getValue(Transition<String> trans) {
return trans != null ? trans.getValue() : null;
}

public String getKeyMapName() {
return lastValue;
}
Expand Down

0 comments on commit ce43b3d

Please sign in to comment.