Skip to content

Commit

Permalink
Merge pull request #237 from adriafarres/master
Browse files Browse the repository at this point in the history
Reset operator-pending commands on escape
  • Loading branch information
AlexPl292 committed Jul 9, 2020
2 parents a04b536 + 660b243 commit e222294
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/com/maddyhome/idea/vim/KeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ public void handleKey(@NotNull Editor editor,
handleKeyRecursionCount++;

try {
if (isEditorReset(key, editorState)) {
handleEditorReset(editor, key, context, editorState);
}

if (!allowKeyMappings || !handleKeyMapping(editor, key, context)) {
if (isCommandCountKey(chKey, editorState)) {
commandBuilder.addCountCharacter(key);
} else if (isDeleteCommandCountKey(key, editorState)) {
commandBuilder.deleteCountCharacter();
} else if (isEditorReset(key, editorState)) {
handleEditorReset(editor, key, context, editorState);
}
// If we got this far the user is entering a command or supplying an argument to an entered command.
// First let's check to see if we are at the point of expecting a single character argument to a command.
Expand Down Expand Up @@ -564,7 +566,7 @@ private boolean isCommandCountKey(char chKey, @NotNull CommandState editorState)
// Make sure to avoid handling '0' as the start of a count.
final CommandBuilder commandBuilder = editorState.getCommandBuilder();
return ((editorState.getMode() == CommandState.Mode.COMMAND
&&editorState.getSubMode()!=CommandState.SubMode.REGISTER_PENDING)
&&editorState.getSubMode()!=CommandState.SubMode.REGISTER_PENDING)
|| editorState.getMode() == CommandState.Mode.VISUAL)
&& commandBuilder.isExpectingCount() && Character.isDigit(chKey) && (commandBuilder.getCount() > 0 || chKey != '0');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ class ResetModeActionTest : VimTestCase() {
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}

fun `test reset from operator-pending mode with delete`() {
val keys = StringHelper.parseKeys("d<Esc>dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
}

0 comments on commit e222294

Please sign in to comment.