Skip to content

Commit

Permalink
Remove more deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lippfi authored and AlexPl292 committed Nov 22, 2024
1 parent 3d08170 commit 94d7902
Show file tree
Hide file tree
Showing 28 changed files with 603 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,19 @@ object VimExtensionFacade {

/** Get the current contents of the given register similar to 'getreg()'. */
@JvmStatic
@Deprecated("Please use com.maddyhome.idea.vim.extension.VimExtensionFacade.getRegister(com.maddyhome.idea.vim.api.VimEditor, char)")
fun getRegister(register: Char): List<KeyStroke>? {
val reg = VimPlugin.getRegister().getRegister(register) ?: return null
return reg.keys
}

/** Get the current contents of the given register similar to 'getreg()'. */
@JvmStatic
fun getRegister(editor: VimEditor, register: Char): List<KeyStroke>? {
val reg = VimPlugin.getRegister().getRegister(editor, injector.executionContextManager.getEditorExecutionContext(editor), register) ?: return null
return reg.keys
}

@JvmStatic
fun getRegisterForCaret(register: Char, caret: VimCaret): List<KeyStroke>? {
val reg = caret.registerStorage.getRegister(register) ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ internal class VimExchangeExtension : VimExtension {
}
}

val zRegText = getRegister('z')
val unnRegText = getRegister('"')
val startRegText = getRegister('*')
val plusRegText = getRegister('+')
val zRegText = getRegister(editor.vim, 'z')
val unnRegText = getRegister(editor.vim, '"')
val startRegText = getRegister(editor.vim, '*')
val plusRegText = getRegister(editor.vim, '+')
runWriteAction {
// TODO handle:
// " Compare using =~ because "'==' != 0" returns 0
Expand Down Expand Up @@ -299,7 +299,7 @@ internal class VimExchangeExtension : VimExtension {

private fun getExchange(editor: Editor, isVisual: Boolean, selectionType: SelectionType): Exchange {
// TODO: improve KeyStroke list to sting conversion
fun getRegisterText(reg: Char): String = getRegister(reg)?.map { it.keyChar }?.joinToString("") ?: ""
fun getRegisterText(reg: Char): String = getRegister(editor.vim, reg)?.map { it.keyChar }?.joinToString("") ?: ""
fun getMarks(isVisual: Boolean): Pair<Mark, Mark> {
val (startMark, endMark) =
if (isVisual) {
Expand All @@ -313,9 +313,9 @@ internal class VimExchangeExtension : VimExtension {
return Pair(marks.getMark(vimEditor.primaryCaret(), startMark)!!, marks.getMark(vimEditor.primaryCaret(), endMark)!!)
}

val unnRegText = getRegister('"')
val starRegText = getRegister('*')
val plusRegText = getRegister('+')
val unnRegText = getRegister(editor.vim, '"')
val starRegText = getRegister(editor.vim, '*')
val plusRegText = getRegister(editor.vim, '+')

val (selectionStart, selectionEnd) = getMarks(isVisual)
if (isVisual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.intellij.idea.TestFor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
Expand Down Expand Up @@ -250,7 +251,10 @@ class CopyActionTest : VimTestCase() {
enterCommand("set clipboard=unnamed")
kotlin.test.assertEquals('*', VimPlugin.getRegister().defaultRegister)
typeText("yy")
val starRegister = VimPlugin.getRegister().getRegister('*')
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val starRegister = registerService.getRegister(vimEditor, context, '*')
assertNotNull<Any>(starRegister)
kotlin.test.assertEquals("bar\n", starRegister.text)
}
Expand All @@ -262,7 +266,10 @@ class CopyActionTest : VimTestCase() {
fun testLineWiseClipboardYankPaste() {
configureByText("<caret>foo\n")
typeText("\"*yy" + "\"*p")
val register = VimPlugin.getRegister().getRegister('*')
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val register = registerService.getRegister(vimEditor, context, '*')
assertNotNull<Any>(register)
kotlin.test.assertEquals("foo\n", register.text)
val editor = fixture.editor
Expand Down Expand Up @@ -290,7 +297,10 @@ class CopyActionTest : VimTestCase() {
""".trimIndent(),
)
typeText("<C-V>j" + "\"*y" + "\"*p")
val register = VimPlugin.getRegister().getRegister('*')
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val register = registerService.getRegister(vimEditor, context, '*')
assertNotNull<Any>(register)
kotlin.test.assertEquals(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ package org.jetbrains.plugins.ideavim.action
import com.intellij.idea.TestFor
import com.intellij.testFramework.LoggedErrorProcessor
import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.api.keys
import com.maddyhome.idea.vim.command.MappingMode
import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.ExceptionHandler
import org.jetbrains.plugins.ideavim.OnlyThrowLoggedErrorProcessor
import org.jetbrains.plugins.ideavim.SkipNeovimReason
Expand Down Expand Up @@ -58,7 +58,10 @@ class MacroActionTest : VimTestCase() {
@Test
fun testRecordMacroWithDigraph() {
typeTextInFile(injector.parser.parseKeys("qa" + "i" + "<C-K>OK<Esc>" + "q"), "")
val register = VimPlugin.getRegister().getRegister('a')
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val register = registerService.getRegister(vimEditor, context, 'a')
assertNotNull<Any>(register)
assertRegister('a', "i^KOK^[")
}
Expand Down Expand Up @@ -96,7 +99,10 @@ class MacroActionTest : VimTestCase() {
configureByText(content)
typeText(injector.parser.parseKeys("qa" + ":map x y<CR>" + "q"))

val register = VimPlugin.getRegister().getRegister('a')
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val register = registerService.getRegister(vimEditor, context, 'a')
val registerSize = register!!.keys.size
assertEquals(9, registerSize)
}
Expand Down Expand Up @@ -244,8 +250,10 @@ class MacroActionTest : VimTestCase() {
)
injector.keyGroup.putKeyMapping(MappingMode.NXO, keys("abc"), exceptionMappingOwner, ExceptionHandler(), false)

injector.registerGroup.storeText('k', "abc")
injector.registerGroup.storeText('q', "x@ky")
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, 'k', "abc")
injector.registerGroup.storeText(vimEditor, context, 'q', "x@ky")

val exception = assertThrows<Throwable> {
LoggedErrorProcessor.executeWith<Throwable>(OnlyThrowLoggedErrorProcessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package org.jetbrains.plugins.ideavim.action

import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim
import org.jetbrains.plugins.ideavim.SkipNeovimReason
import org.jetbrains.plugins.ideavim.TestWithoutNeovim
import org.jetbrains.plugins.ideavim.VimTestCase
Expand All @@ -29,7 +30,9 @@ class MacroWithEditingTest : VimTestCase() {
@Test
fun `test copy and perform macro`() {
typeTextInFile(injector.parser.parseKeys("^v\$h\"wy"), "iHello")
kotlin.test.assertEquals("iHello", VimPlugin.getRegister().getRegister('w')?.text)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
kotlin.test.assertEquals("iHello", VimPlugin.getRegister().getRegister(vimEditor, context, 'w')?.text)
setText("")
typeText(injector.parser.parseKeys("@w"))
waitAndAssert {
Expand All @@ -40,7 +43,9 @@ class MacroWithEditingTest : VimTestCase() {
@Test
fun `test copy and perform macro ctrl_a`() {
typeTextInFile(injector.parser.parseKeys("^v\$h\"wy"), "\u0001")
kotlin.test.assertEquals(injector.parser.parseKeys("<C-A>"), injector.registerGroup.getRegister('w')!!.keys)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
kotlin.test.assertEquals(injector.parser.parseKeys("<C-A>"), injector.registerGroup.getRegister(vimEditor, context, 'w')!!.keys)
setText("1")
typeText(injector.parser.parseKeys("@w"))
waitAndAssert {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2165,7 +2165,9 @@ rtyfg${c}hzxc"""
fun testPutTextBeforeCursor() {
val before = "${c}qwe asd ${c}zxc rty ${c}fgh vbn"
configureByText(before)
injector.registerGroup.storeText('*', "fgh", SelectionType.CHARACTER_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh", SelectionType.CHARACTER_WISE)
typeText(injector.parser.parseKeys("\"*P" + "3l" + "\"*P"))
val after = "fghqwfg${c}he asd fghzxfg${c}hc rty fghfgfg${c}hh vbn"
assertState(after)
Expand All @@ -2175,9 +2177,11 @@ rtyfg${c}hzxc"""
fun testPutTextBeforeCursorOverlapRange() {
val before = "${c}q${c}we asd zxc rty ${c}fgh vbn"
val editor = configureByText(before)
injector.registerGroup.storeText('*', "fgh")
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh")
VimPlugin.getRegister()
.storeText(IjVimEditor(editor), editor.vim.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
.storeText(IjVimEditor(editor), context, editor.vim.primaryCaret(), TextRange(16, 19), SelectionType.CHARACTER_WISE, false)
typeText(injector.parser.parseKeys("\"*P"))
val after = "fg${c}hqfg${c}hwe asd zxc rty fg${c}hfgh vbn"
assertState(after)
Expand All @@ -2187,7 +2191,9 @@ rtyfg${c}hzxc"""
fun testPutTextAfterCursor() {
val before = "${c}qwe asd ${c}zxc rty ${c}fgh vbn"
configureByText(before)
injector.registerGroup.storeText('*', "fgh", SelectionType.CHARACTER_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh", SelectionType.CHARACTER_WISE)
typeText(injector.parser.parseKeys("\"*p" + "3l" + "2\"*p"))
val after = "qfghwe fghfg${c}hasd zfghxc fghfg${c}hrty ffghgh fghfg${c}hvbn"
assertState(after)
Expand All @@ -2197,7 +2203,9 @@ rtyfg${c}hzxc"""
fun testPutTextAfterCursorOverlapRange() {
val before = "${c}q${c}we asd zxc rty ${c}fgh vbn"
configureByText(before)
injector.registerGroup.storeText('*', "fgh", SelectionType.CHARACTER_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh", SelectionType.CHARACTER_WISE)
typeText(injector.parser.parseKeys("2\"*p"))
val after = "qfghfg${c}hwfghfg${c}he asd zxc rty ffghfg${c}hgh vbn"
assertState(after)
Expand All @@ -2212,7 +2220,9 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
injector.registerGroup.storeText('*', "zxcvbn\n", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "zxcvbn\n", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*P"))
val after = """
${c}zxcvbn
Expand Down Expand Up @@ -2346,7 +2356,9 @@ rtyfg${c}hzxc"""

private fun testPutOverlapLine(before: String, after: String, beforeCursor: Boolean) {
configureByText(before)
injector.registerGroup.storeText('*', "zxcvbn\n", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "zxcvbn\n", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*" + if (beforeCursor) "P" else "p"))
assertState(after)
}
Expand All @@ -2360,7 +2372,9 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
injector.registerGroup.storeText('*', "zxcvbn", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "zxcvbn", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*p"))
val after = """
qwerty
Expand All @@ -2378,7 +2392,9 @@ rtyfg${c}hzxc"""
fun testPutTextBeforeCursorMoveCursor() {
val before = "qw${c}e asd z${c}xc rty ${c}fgh vbn"
configureByText(before)
injector.registerGroup.storeText('*', "fgh", SelectionType.CHARACTER_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh", SelectionType.CHARACTER_WISE)
typeText(injector.parser.parseKeys("l" + "\"*gP" + "b" + "\"*gP"))
val after = "fgh${c}qwefgh asd fgh${c}zxfghc rty fgh${c}ffghgh vbn"
assertState(after)
Expand All @@ -2388,7 +2404,9 @@ rtyfg${c}hzxc"""
fun testPutTextAfterCursorMoveCursor() {
val before = "qw${c}e asd z${c}xc rty ${c}fgh vbn"
configureByText(before)
injector.registerGroup.storeText('*', "fgh", SelectionType.CHARACTER_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "fgh", SelectionType.CHARACTER_WISE)
typeText(injector.parser.parseKeys("l" + "\"*gp" + "b" + "\"*gp"))
val after = "qwe ffgh${c}ghasd zfgh${c}xcfgh rty ffgh${c}gfghh vbn"
assertState(after)
Expand All @@ -2403,7 +2421,9 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
injector.registerGroup.storeText('*', "zxcvbn\n", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "zxcvbn\n", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*gP"))
val after = """
zxcvbn
Expand All @@ -2426,7 +2446,9 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
injector.registerGroup.storeText('*', "zxcvbn", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "zxcvbn", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*gp"))
val after = """
qwerty
Expand All @@ -2446,7 +2468,9 @@ rtyfg${c}hzxc"""
* two
"""
configureByText(before)
injector.registerGroup.storeText('*', " *\n *\n", SelectionType.BLOCK_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', " *\n *\n", SelectionType.BLOCK_WISE)
typeText(injector.parser.parseKeys("\"*p"))
val after = """ * $c *one$c *
* *two *
Expand All @@ -2460,7 +2484,9 @@ rtyfg${c}hzxc"""
* two
"""
configureByText(before)
injector.registerGroup.storeText('*', " *\n \n", SelectionType.BLOCK_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', " *\n \n", SelectionType.BLOCK_WISE)
typeText(injector.parser.parseKeys("\"*P"))
val after = """ *$c * on$c *e
* tw o
Expand All @@ -2479,7 +2505,9 @@ rtyfg${c}hzxc"""
vb${c}n
""".trimIndent()
configureByText(before)
injector.registerGroup.storeText('*', "qwe\n", SelectionType.LINE_WISE)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
injector.registerGroup.storeText(vimEditor, context, '*', "qwe\n", SelectionType.LINE_WISE)
typeText(injector.parser.parseKeys("\"*p"))
val after = """
qwe
Expand All @@ -2501,7 +2529,10 @@ rtyfg${c}hzxc"""
val before = "qwe ${c}asd ${c}zxc"
configureByText(before)
typeText(injector.parser.parseKeys("ye"))
val lastRegister = VimPlugin.getRegister().lastRegister
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val lastRegister = registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)
assertNotNull<Any>(lastRegister)
val text = lastRegister.text
assertNotNull<Any>(text)
Expand All @@ -2523,7 +2554,10 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
typeText(injector.parser.parseKeys("yj"))
val lastRegister = VimPlugin.getRegister().lastRegister
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val lastRegister = registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)
assertNotNull<Any>(lastRegister)
val text = lastRegister.text
assertNotNull<Any>(text)
Expand Down Expand Up @@ -2557,7 +2591,10 @@ rtyfg${c}hzxc"""
""".trimIndent()
configureByText(before)
typeText(injector.parser.parseKeys("2yy"))
val lastRegister = VimPlugin.getRegister().lastRegister
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val registerService = injector.registerGroup
val lastRegister = registerService.getRegister(vimEditor, context, registerService.lastRegisterChar)
assertNotNull<Any>(lastRegister)
val text = lastRegister.text
assertNotNull<Any>(text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package org.jetbrains.plugins.ideavim.action

import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.register.RegisterConstants.LAST_INSERTED_TEXT_REGISTER
import com.maddyhome.idea.vim.register.RegisterConstants.LAST_SEARCH_REGISTER
import com.maddyhome.idea.vim.register.RegisterConstants.SMALL_DELETION_REGISTER
Expand Down Expand Up @@ -210,7 +211,9 @@ class SpecialRegistersTest : VimTestCase() {

private fun getRegisterText(registerName: Char): String? {
val registerGroup = VimPlugin.getRegister()
val register = registerGroup.getRegister(registerName)
val vimEditor = fixture.editor.vim
val context = injector.executionContextManager.getEditorExecutionContext(vimEditor)
val register = registerGroup.getRegister(vimEditor, context, registerName)
assertNotNull<Any>(register)
return register!!.text
}
Expand Down
Loading

0 comments on commit 94d7902

Please sign in to comment.