1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-31 16:34:06 +02:00

Clean up code

This commit is contained in:
Alex Plate 2025-01-10 12:15:22 +03:00
parent aaba0a09c2
commit ef16181ba2
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
8 changed files with 12 additions and 35 deletions
src/main/java/com/maddyhome/idea/vim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim

View File

@ -12,12 +12,14 @@ import com.intellij.openapi.editor.Editor
import com.maddyhome.idea.vim.KeyHandler import com.maddyhome.idea.vim.KeyHandler
import com.maddyhome.idea.vim.api.injector import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.state.VimStateMachine import com.maddyhome.idea.vim.state.VimStateMachine
import org.jetbrains.annotations.ApiStatus
/** /**
* COMPATIBILITY-LAYER: Additional class * COMPATIBILITY-LAYER: Additional class
* Please see: https://jb.gg/zo8n0r * Please see: https://jb.gg/zo8n0r
*/ */
@Deprecated("Use `injector.vimState`") @Deprecated("Use `injector.vimState`")
@ApiStatus.ScheduledForRemoval
class CommandState(private val machine: VimStateMachine) { class CommandState(private val machine: VimStateMachine) {
val mode: Mode val mode: Mode
@ -34,11 +36,12 @@ class CommandState(private val machine: VimStateMachine) {
} }
} }
@Deprecated("Use `KeyHandler.keyHandlerState.commandBuilder", ReplaceWith( @get:Deprecated("Use `KeyHandler.keyHandlerState.commandBuilder", ReplaceWith(
"KeyHandler.getInstance().keyHandlerState.commandBuilder", "KeyHandler.getInstance().keyHandlerState.commandBuilder",
"com.maddyhome.idea.vim.KeyHandler" "com.maddyhome.idea.vim.KeyHandler"
) )
) )
@get:ApiStatus.ScheduledForRemoval
val commandBuilder: CommandBuilder val commandBuilder: CommandBuilder
get() = KeyHandler.getInstance().keyHandlerState.commandBuilder get() = KeyHandler.getInstance().keyHandlerState.commandBuilder
@ -65,6 +68,7 @@ class CommandState(private val machine: VimStateMachine) {
companion object { companion object {
@JvmStatic @JvmStatic
@Deprecated("Use `injector.vimState`") @Deprecated("Use `injector.vimState`")
@ApiStatus.ScheduledForRemoval
fun getInstance(editor: Editor): CommandState { fun getInstance(editor: Editor): CommandState {
return CommandState(injector.vimState) return CommandState(injector.vimState)
} }

View File

@ -186,14 +186,6 @@ object VimExtensionFacade {
return (injector.commandLine as ExEntryPanelService).inputString(editor.vim, context.vim, prompt, finishOn) ?: "" return (injector.commandLine as ExEntryPanelService).inputString(editor.vim, context.vim, prompt, finishOn) ?: ""
} }
/** 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()'. */ /** Get the current contents of the given register similar to 'getreg()'. */
@JvmStatic @JvmStatic
fun getRegister(editor: VimEditor, register: Char): List<KeyStroke>? { fun getRegister(editor: VimEditor, register: Char): List<KeyStroke>? {
@ -202,8 +194,8 @@ object VimExtensionFacade {
} }
@JvmStatic @JvmStatic
fun getRegisterForCaret(register: Char, caret: VimCaret): List<KeyStroke>? { fun getRegisterForCaret(editor: VimEditor, context: ExecutionContext, register: Char, caret: VimCaret): List<KeyStroke>? {
val reg = caret.registerStorage.getRegister(register) ?: return null val reg = caret.registerStorage.getRegister(editor, context, register) ?: return null
return reg.keys return reg.keys
} }

View File

@ -144,7 +144,7 @@ internal class ReplaceWithRegister : VimExtension {
private fun doReplace(editor: Editor, context: DataContext, caret: ImmutableVimCaret, visualSelection: PutData.VisualSelection) { private fun doReplace(editor: Editor, context: DataContext, caret: ImmutableVimCaret, visualSelection: PutData.VisualSelection) {
val registerGroup = injector.registerGroup val registerGroup = injector.registerGroup
val lastRegisterChar = if (editor.caretModel.caretCount == 1) registerGroup.currentRegister else registerGroup.getCurrentRegisterForMulticaret() val lastRegisterChar = if (editor.caretModel.caretCount == 1) registerGroup.currentRegister else registerGroup.getCurrentRegisterForMulticaret()
val savedRegister = caret.registerStorage.getRegister(lastRegisterChar) ?: return val savedRegister = caret.registerStorage.getRegister(editor.vim, context.vim, lastRegisterChar) ?: return
var usedType = savedRegister.type var usedType = savedRegister.type
var usedText = savedRegister.text var usedText = savedRegister.text

View File

@ -162,7 +162,7 @@ internal class VimSurroundExtension : VimExtension {
// Save old register values for carets // Save old register values for carets
val surroundings = editor.sortedCarets() val surroundings = editor.sortedCarets()
.map { .map {
val oldValue: List<KeyStroke>? = getRegisterForCaret(REGISTER, it) val oldValue: List<KeyStroke>? = getRegisterForCaret(editor, context, REGISTER, it)
setRegisterForCaret(REGISTER, it, null) setRegisterForCaret(REGISTER, it, null)
SurroundingInfo(it, null, oldValue, false) SurroundingInfo(it, null, oldValue, false)
} }
@ -179,7 +179,7 @@ internal class VimSurroundExtension : VimExtension {
editor.deleteString(currentSurrounding) editor.deleteString(currentSurrounding)
} }
val registerValue = getRegisterForCaret(REGISTER, it.caret) val registerValue = getRegisterForCaret(editor, context, REGISTER, it.caret)
val innerValue = if (registerValue.isNullOrEmpty()) emptyList() else registerValue val innerValue = if (registerValue.isNullOrEmpty()) emptyList() else registerValue
it.innerText = innerValue it.innerText = innerValue

View File

@ -23,7 +23,7 @@ class InsertExitModeAction : VimActionHandler.SingleExecution() {
override val type: Command.Type = Command.Type.INSERT override val type: Command.Type = Command.Type.INSERT
override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean { override fun execute(editor: VimEditor, context: ExecutionContext, cmd: Command, operatorArguments: OperatorArguments): Boolean {
editor.exitInsertMode(context, operatorArguments) editor.exitInsertMode(context)
return true return true
} }
} }

View File

@ -8,7 +8,6 @@
package com.maddyhome.idea.vim.api package com.maddyhome.idea.vim.api
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.common.LiveRange import com.maddyhome.idea.vim.common.LiveRange
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.common.VimEditorReplaceMask import com.maddyhome.idea.vim.common.VimEditorReplaceMask
@ -243,8 +242,6 @@ interface VimEditor {
// Can be used as a key to store something for specific project // Can be used as a key to store something for specific project
val projectId: String val projectId: String
@Deprecated("Use overload without OperatorArguments", replaceWith = ReplaceWith("exitInsertMode(context)"))
fun exitInsertMode(context: ExecutionContext, operatorArguments: OperatorArguments) { exitInsertMode(context) }
fun exitInsertMode(context: ExecutionContext) fun exitInsertMode(context: ExecutionContext)
fun exitSelectModeNative(adjustCaret: Boolean) fun exitSelectModeNative(adjustCaret: Boolean)

View File

@ -10,20 +10,13 @@ package com.maddyhome.idea.vim.register
import com.maddyhome.idea.vim.api.ExecutionContext import com.maddyhome.idea.vim.api.ExecutionContext
import com.maddyhome.idea.vim.api.ImmutableVimCaret import com.maddyhome.idea.vim.api.ImmutableVimCaret
import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.state.mode.SelectionType
import com.maddyhome.idea.vim.common.TextRange import com.maddyhome.idea.vim.common.TextRange
import com.maddyhome.idea.vim.state.mode.SelectionType
import org.jetbrains.annotations.TestOnly import org.jetbrains.annotations.TestOnly
import javax.swing.KeyStroke import javax.swing.KeyStroke
interface VimRegisterGroup { interface VimRegisterGroup {
/**
* Get the last register selected by the user
*
* @return The register, null if no such register
*/
@Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getLastRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
val lastRegister: Register?
var lastRegisterChar: Char var lastRegisterChar: Char
val currentRegister: Char val currentRegister: Char

View File

@ -79,15 +79,6 @@ abstract class VimRegisterGroupBase : VimRegisterGroup {
return getRegister(editor, context, lastRegisterChar) return getRegister(editor, context, lastRegisterChar)
} }
/**
* Get the last register selected by the user
*
* @return The register, null if no such register
*/
@Deprecated("Please use com.maddyhome.idea.vim.register.VimRegisterGroup#getLastRegister(com.maddyhome.idea.vim.api.VimEditor, com.maddyhome.idea.vim.api.ExecutionContext)")
override val lastRegister: Register?
get() = getRegister(lastRegisterChar)
private val onClipboardChanged: () -> Unit = { private val onClipboardChanged: () -> Unit = {
val clipboardOptionValue = injector.globalOptions().clipboard val clipboardOptionValue = injector.globalOptions().clipboard
defaultRegisterChar = when { defaultRegisterChar = when {