1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2024-11-25 07:42:59 +01: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)
}
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) {
assertMode(modeAfter)
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 commandState = editor.vim.vimStateMachine
kotlin.test.assertFalse(commandState.isRecording)
val registerGroup = VimPlugin.getRegister()
val register = registerGroup.getRegister('a')
assertNotNull<Any>(register)
kotlin.test.assertEquals("3l", register.text)
assertRegister('a', "3l")
}
@Test
@ -58,9 +55,7 @@ class MacroActionTest : VimTestCase() {
configureByText("")
enterCommand("imap pp hello")
typeText(injector.parser.parseKeys("qa" + "i" + "pp<Esc>" + "q"))
val register = VimPlugin.getRegister().getRegister('a')
assertNotNull<Any>(register)
kotlin.test.assertEquals("ipp<Esc>", injector.parser.toKeyNotation(register.keys))
assertRegister('a', "ipp<Esc>")
}
@Test
@ -68,7 +63,7 @@ class MacroActionTest : VimTestCase() {
typeTextInFile(injector.parser.parseKeys("qa" + "i" + "<C-K>OK<Esc>" + "q"), "")
val register = VimPlugin.getRegister().getRegister('a')
assertNotNull<Any>(register)
kotlin.test.assertEquals("i<C-K>OK<Esc>", injector.parser.toKeyNotation(register.keys))
assertRegister('a', "i<C-K>OK<Esc>")
}
@Test
@ -141,8 +136,8 @@ class MacroActionTest : VimTestCase() {
assertState("4\n5\n")
}
// Broken, see the resulting text
fun `ignore test macro with macro`() {
@Test
fun `test macro with macro`() {
val content = """
Lorem Ipsum
@ -152,16 +147,55 @@ class MacroActionTest : VimTestCase() {
Cras id tellus in ex imperdiet egestas.
""".trimIndent()
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 {
println(fixture.editor.caretModel.offset)
println(startOffset)
println()
startOffset == fixture.editor.caretModel.offset
}
Lorem ipsum dolor ${c}sit amet,
consectetur adipiscing elit
Sed in orci mauris.
Cras id tellus in ex imperdiet egestas.
""".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

View File

@ -102,8 +102,9 @@ public class KeyHandler {
// If this is a "regular" character keystroke, get the character
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.
var shouldRecord = handleKeyRecursionCount == 0 && editorState.isRecording
// We only record unmapped keystrokes.
// 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++
try {
LOG.trace("Start key processing...")