Skip to content

Commit

Permalink
Fix(VIM-3601): The escape characters in IdeaVim's configuration file …
Browse files Browse the repository at this point in the history
…are invalid
  • Loading branch information
lippfi committed Aug 14, 2024
1 parent ea2222f commit 2189b70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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|
Expand All @@ -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|
Expand Down Expand Up @@ -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<CR> \\| :echo 42<CR>"))
assertNull(injector.outputPanel.getCurrentOutputPanel())
typeText("k")
assertEquals("4\n42", injector.outputPanel.getCurrentOutputPanel()!!.text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ data class MapCommand(val range: Range, val argument: String, val cmd: String) :
val specialArguments = HashSet<SpecialArgument>()
val toKeysBuilder = StringBuilder()
var fromKeys: List<KeyStroke>? = 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)
Expand All @@ -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 {
Expand Down

0 comments on commit 2189b70

Please sign in to comment.