From 2189b70b877f3d756151db460b3fe7a205411499 Mon Sep 17 00:00:00 2001 From: Filipp Vakhitov Date: Wed, 14 Aug 2024 18:18:44 +0300 Subject: [PATCH] Fix(VIM-3601): The escape characters in IdeaVim's configuration file are invalid --- .../implementation/commands/MapCommandTest.kt | 24 +++++++++++++++++-- .../model/commands/mapping/MapCommand.kt | 8 ++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/MapCommandTest.kt b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/MapCommandTest.kt index 9876503962..159d80c881 100644 --- a/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/MapCommandTest.kt +++ b/src/test/java/org/jetbrains/plugins/ideavim/ex/implementation/commands/MapCommandTest.kt @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import kotlin.test.assertEquals +import kotlin.test.assertNull import kotlin.test.assertTrue /** @@ -267,7 +268,7 @@ class MapCommandTest : VimTestCase() { configureByText("${c}foo\n") typeText(commandToKeys("imap a b \\| c")) typeText(injector.parser.parseKeys("ia")) - assertState("b \\| cfoo\n") + assertState("b | cfoo\n") } // VIM-666 |:imap| @@ -277,7 +278,7 @@ class MapCommandTest : VimTestCase() { configureByText("${c}foo\n") typeText(commandToKeys("imap a b \\| c |")) typeText(injector.parser.parseKeys("ia")) - assertState("b \\| c foo\n") + assertState("b | c foo\n") } // VIM-670 |:map| @@ -754,4 +755,23 @@ class MapCommandTest : VimTestCase() { assertTrue(KeyHandler.getInstance().keyStack.isEmpty()) } + + @TestFor(issues = ["VIM-3601"]) + @Test + fun `mapping to something with bars`() { + configureByText( + """ + Lorem Ipsum + + Lorem ipsum dolor sit amet, + ${c}consectetur adipiscing elit + Sed in orci mauris. + Cras id tellus in ex imperdiet egestas. + """.trimIndent() + ) + typeText(commandToKeys("map k :echo 4 \\| :echo 42")) + assertNull(injector.outputPanel.getCurrentOutputPanel()) + typeText("k") + assertEquals("4\n42", injector.outputPanel.getCurrentOutputPanel()!!.text) + } } diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/mapping/MapCommand.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/mapping/MapCommand.kt index 729903ecd1..fe3eb48175 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/mapping/MapCommand.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/commands/mapping/MapCommand.kt @@ -160,7 +160,9 @@ data class MapCommand(val range: Range, val argument: String, val cmd: String) : val specialArguments = HashSet() val toKeysBuilder = StringBuilder() var fromKeys: List? = null - input.split(" ").dropLastWhile { it.isEmpty() }.forEach { part -> + + val preprocessedInput = processBars(input) + preprocessedInput.split(" ").dropLastWhile { it.isEmpty() }.forEach { part -> if (fromKeys != null) { toKeysBuilder.append(" ") toKeysBuilder.append(part) @@ -173,8 +175,8 @@ data class MapCommand(val range: Range, val argument: String, val cmd: String) : } } } - for (i in input.length - 1 downTo 0) { - val c = input[i] + for (i in preprocessedInput.length - 1 downTo 0) { + val c = preprocessedInput[i] if (c == ' ') { toKeysBuilder.append(c) } else {