1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2024-10-19 04:42:46 +02:00

Compare commits

...

1 Commits

Author SHA1 Message Date
ea703bce69
VIM-3238 Fix recording a macro that replays another macro 2024-01-24 23:02:35 +01:00
3 changed files with 60 additions and 20 deletions

View File

@ -448,6 +448,11 @@ abstract class VimTestCase {
return NeovimTesting.getMark(char) return NeovimTesting.getMark(char)
} }
protected fun assertRegister(char: Char, expected: String?) {
val actual = injector.registerGroup.getRegister(char)?.keys?.let(injector.parser::toKeyNotation)
assertEquals(expected, actual, "Wrong register contents")
}
protected fun assertState(modeAfter: Mode) { protected fun assertState(modeAfter: Mode) {
assertMode(modeAfter) assertMode(modeAfter)
assertCaretsVisualAttributes() assertCaretsVisualAttributes()

View File

@ -47,10 +47,7 @@ class MacroActionTest : VimTestCase() {
val editor = typeTextInFile(injector.parser.parseKeys("qa" + "3l" + "q"), "on<caret>e two three\n") val editor = typeTextInFile(injector.parser.parseKeys("qa" + "3l" + "q"), "on<caret>e two three\n")
val commandState = editor.vim.vimStateMachine val commandState = editor.vim.vimStateMachine
kotlin.test.assertFalse(commandState.isRecording) kotlin.test.assertFalse(commandState.isRecording)
val registerGroup = VimPlugin.getRegister() assertRegister('a', "3l")
val register = registerGroup.getRegister('a')
assertNotNull<Any>(register)
kotlin.test.assertEquals("3l", register.text)
} }
@Test @Test
@ -58,9 +55,7 @@ class MacroActionTest : VimTestCase() {
configureByText("") configureByText("")
enterCommand("imap pp hello") enterCommand("imap pp hello")
typeText(injector.parser.parseKeys("qa" + "i" + "pp<Esc>" + "q")) typeText(injector.parser.parseKeys("qa" + "i" + "pp<Esc>" + "q"))
val register = VimPlugin.getRegister().getRegister('a') assertRegister('a', "ipp<Esc>")
assertNotNull<Any>(register)
kotlin.test.assertEquals("ipp<Esc>", injector.parser.toKeyNotation(register.keys))
} }
@Test @Test
@ -68,7 +63,7 @@ class MacroActionTest : VimTestCase() {
typeTextInFile(injector.parser.parseKeys("qa" + "i" + "<C-K>OK<Esc>" + "q"), "") typeTextInFile(injector.parser.parseKeys("qa" + "i" + "<C-K>OK<Esc>" + "q"), "")
val register = VimPlugin.getRegister().getRegister('a') val register = VimPlugin.getRegister().getRegister('a')
assertNotNull<Any>(register) assertNotNull<Any>(register)
kotlin.test.assertEquals("i<C-K>OK<Esc>", injector.parser.toKeyNotation(register.keys)) assertRegister('a', "i<C-K>OK<Esc>")
} }
@Test @Test
@ -141,8 +136,8 @@ class MacroActionTest : VimTestCase() {
assertState("4\n5\n") assertState("4\n5\n")
} }
// Broken, see the resulting text @Test
fun `ignore test macro with macro`() { fun `test macro with macro`() {
val content = """ val content = """
Lorem Ipsum Lorem Ipsum
@ -152,16 +147,55 @@ class MacroActionTest : VimTestCase() {
Cras id tellus in ex imperdiet egestas. Cras id tellus in ex imperdiet egestas.
""".trimIndent() """.trimIndent()
configureByText(content) configureByText(content)
typeText(injector.parser.parseKeys("qa" + "l" + "q" + "qb" + "10@a" + "q" + "2@b")) typeText(
injector.parser.parseKeys(
"qa" + "l" + "q" +
"qb" + "6@a" + "q" +
"^" + "3@b"
)
)
val startOffset = content.rangeOf("rocks").startOffset assertRegister('b', "6@a")
assertState("""
Lorem Ipsum
waitAndAssert { Lorem ipsum dolor ${c}sit amet,
println(fixture.editor.caretModel.offset) consectetur adipiscing elit
println(startOffset) Sed in orci mauris.
println() Cras id tellus in ex imperdiet egestas.
startOffset == fixture.editor.caretModel.offset """.trimIndent())
} }
@Test
fun `test macro with macro with macro`() {
val content = """
Lorem Ipsum
${c}Lorem ipsum dolor sit amet,
consectetur adipiscing elit
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent()
configureByText(content)
typeText(
injector.parser.parseKeys(
"qa" + "l" + "q" +
"qb" + "3@a" + "q" +
"qc" + "2@b" + "q" +
"^" + "3@c"
)
)
assertRegister('b', "3@a")
assertRegister('c', "2@b")
assertState("""
Lorem Ipsum
Lorem ipsum dolor ${c}sit amet,
consectetur adipiscing elit
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".trimIndent())
} }
@Test @Test

View File

@ -102,8 +102,9 @@ public class KeyHandler {
// If this is a "regular" character keystroke, get the character // If this is a "regular" character keystroke, get the character
val chKey: Char = if (key.keyChar == KeyEvent.CHAR_UNDEFINED) 0.toChar() else key.keyChar val chKey: Char = if (key.keyChar == KeyEvent.CHAR_UNDEFINED) 0.toChar() else key.keyChar
// We only record unmapped keystrokes. If we've recursed to handle mapping, don't record anything. // We only record unmapped keystrokes.
var shouldRecord = handleKeyRecursionCount == 0 && editorState.isRecording // If we've recursed to handle mapping, or executing a macro, don't record anything.
var shouldRecord = handleKeyRecursionCount == 0 && editorState.isRecording && !injector.macro.isExecutingMacro
handleKeyRecursionCount++ handleKeyRecursionCount++
try { try {
LOG.trace("Start key processing...") LOG.trace("Start key processing...")