Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly reset when pressing Esc in the middle of command #241

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions test/org/jetbrains/plugins/ideavim/action/ResetModeActionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@

package org.jetbrains.plugins.ideavim.action

import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.command.CommandState
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.helper.StringHelper
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.key.MappingOwner
import junit.framework.TestCase
import org.jetbrains.plugins.ideavim.VimTestCase

class ResetModeActionTest : VimTestCase() {
private val owner = MappingOwner.Plugin.get("ResetModeActionTest")

fun `test reset from normal mode`() {
val keys = StringHelper.parseKeys("<C-\\><C-N>")
val before = "A Discovery"
Expand Down Expand Up @@ -71,4 +77,47 @@ class ResetModeActionTest : VimTestCase() {
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}

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

fun `test delete command after resetting operator-pending mode with esc`() {
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())
}

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

fun `test delete command after resetting operator-pending mode with mapping`() {
VimPlugin.getKey()
.putKeyMapping(MappingMode.NVO, parseKeys("<C-D>"), owner, parseKeys("<Esc>"), false)

val keys = StringHelper.parseKeys("d", "<C-D>", "dw")
val before = "A Discovery"
val after = "Discovery"
doTest(keys, before, after, CommandState.Mode.COMMAND, CommandState.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}

fun `test non-delete commands after resetting operator-pending mode`() {
val keys = StringHelper.parseKeys("c", "<C-\\><C-N>", "another")
val before = "A Discovery"
val after = "Another Discovery"
doTest(keys, before, after, CommandState.Mode.INSERT, CommandState.SubMode.NONE)
TestCase.assertFalse(myFixture.editor.selectionModel.hasSelection())
}
}