mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-07-30 00:59:08 +02:00
Create KeyHandlerState
We do not need multiple commandBuilder, digraphSequence or mappingState and this class will be a singleton containing them
This commit is contained in:
parent
5fc2f04224
commit
7966a6dc91
src/testFixtures/kotlin/org/jetbrains/plugins/ideavim
vim-engine/src/main/kotlin/com/maddyhome/idea/vim
@ -73,7 +73,6 @@ import com.maddyhome.idea.vim.options.helpers.GuiCursorOptionHelper
|
|||||||
import com.maddyhome.idea.vim.options.helpers.GuiCursorType
|
import com.maddyhome.idea.vim.options.helpers.GuiCursorType
|
||||||
import com.maddyhome.idea.vim.state.mode.Mode
|
import com.maddyhome.idea.vim.state.mode.Mode
|
||||||
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
import com.maddyhome.idea.vim.state.mode.inBlockSelection
|
||||||
import com.maddyhome.idea.vim.state.mode.mode
|
|
||||||
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
import com.maddyhome.idea.vim.ui.ex.ExEntryPanel
|
||||||
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext
|
import com.maddyhome.idea.vim.vimscript.model.CommandLineVimLContext
|
||||||
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimFuncref
|
import com.maddyhome.idea.vim.vimscript.model.datatypes.VimFuncref
|
||||||
@ -119,6 +118,7 @@ abstract class VimTestCase {
|
|||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
KeyHandler.getInstance().fullReset(editor.vim)
|
KeyHandler.getInstance().fullReset(editor.vim)
|
||||||
}
|
}
|
||||||
|
KeyHandler.getInstance().keyState.reset(Mode.NORMAL())
|
||||||
VimPlugin.getOptionGroup().resetAllOptionsForTesting()
|
VimPlugin.getOptionGroup().resetAllOptionsForTesting()
|
||||||
VimPlugin.getKey().resetKeyMappings()
|
VimPlugin.getKey().resetKeyMappings()
|
||||||
VimPlugin.getSearch().resetState()
|
VimPlugin.getSearch().resetState()
|
||||||
|
@ -34,6 +34,7 @@ import com.maddyhome.idea.vim.key.CommandNode
|
|||||||
import com.maddyhome.idea.vim.key.CommandPartNode
|
import com.maddyhome.idea.vim.key.CommandPartNode
|
||||||
import com.maddyhome.idea.vim.key.KeyStack
|
import com.maddyhome.idea.vim.key.KeyStack
|
||||||
import com.maddyhome.idea.vim.key.Node
|
import com.maddyhome.idea.vim.key.Node
|
||||||
|
import com.maddyhome.idea.vim.state.KeyHandlerState
|
||||||
import com.maddyhome.idea.vim.state.VimStateMachine
|
import com.maddyhome.idea.vim.state.VimStateMachine
|
||||||
import com.maddyhome.idea.vim.state.mode.Mode
|
import com.maddyhome.idea.vim.state.mode.Mode
|
||||||
import com.maddyhome.idea.vim.state.mode.ReturnTo
|
import com.maddyhome.idea.vim.state.mode.ReturnTo
|
||||||
@ -48,6 +49,7 @@ import javax.swing.KeyStroke
|
|||||||
* actions. This is a singleton.
|
* actions. This is a singleton.
|
||||||
*/
|
*/
|
||||||
public class KeyHandler {
|
public class KeyHandler {
|
||||||
|
public val keyState: KeyHandlerState = KeyHandlerState()
|
||||||
|
|
||||||
private var handleKeyRecursionCount = 0
|
private var handleKeyRecursionCount = 0
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.maddyhome.idea.vim.impl.state
|
package com.maddyhome.idea.vim.impl.state
|
||||||
|
|
||||||
|
import com.maddyhome.idea.vim.KeyHandler
|
||||||
import com.maddyhome.idea.vim.api.VimEditor
|
import com.maddyhome.idea.vim.api.VimEditor
|
||||||
import com.maddyhome.idea.vim.api.injector
|
|
||||||
import com.maddyhome.idea.vim.command.Command
|
import com.maddyhome.idea.vim.command.Command
|
||||||
import com.maddyhome.idea.vim.command.CommandBuilder
|
import com.maddyhome.idea.vim.command.CommandBuilder
|
||||||
import com.maddyhome.idea.vim.command.CommandFlags
|
import com.maddyhome.idea.vim.command.CommandFlags
|
||||||
@ -27,10 +27,10 @@ import javax.swing.KeyStroke
|
|||||||
* Used to maintain state before and while entering a Vim command (operator, motion, text object, etc.)
|
* Used to maintain state before and while entering a Vim command (operator, motion, text object, etc.)
|
||||||
*/
|
*/
|
||||||
public class VimStateMachineImpl : VimStateMachine {
|
public class VimStateMachineImpl : VimStateMachine {
|
||||||
override val commandBuilder: CommandBuilder = CommandBuilder(injector.keyGroup.getKeyRoot(MappingMode.NORMAL))
|
override val commandBuilder: CommandBuilder = KeyHandler.getInstance().keyState.commandBuilder
|
||||||
override var mode: Mode = Mode.NORMAL()
|
override var mode: Mode = Mode.NORMAL()
|
||||||
override val mappingState: MappingState = MappingState()
|
override val mappingState: MappingState = KeyHandler.getInstance().keyState.mappingState
|
||||||
override val digraphSequence: DigraphSequence = DigraphSequence()
|
override val digraphSequence: DigraphSequence = KeyHandler.getInstance().keyState.digraphSequence
|
||||||
override var isDotRepeatInProgress: Boolean = false
|
override var isDotRepeatInProgress: Boolean = false
|
||||||
override var isRegisterPending: Boolean = false
|
override var isRegisterPending: Boolean = false
|
||||||
override var isReplaceCharacter: Boolean = false
|
override var isReplaceCharacter: Boolean = false
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2024 The IdeaVim authors
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE.txt file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.maddyhome.idea.vim.state
|
||||||
|
|
||||||
|
import com.maddyhome.idea.vim.api.injector
|
||||||
|
import com.maddyhome.idea.vim.command.CommandBuilder
|
||||||
|
import com.maddyhome.idea.vim.command.MappingMode
|
||||||
|
import com.maddyhome.idea.vim.command.MappingState
|
||||||
|
import com.maddyhome.idea.vim.common.DigraphSequence
|
||||||
|
import com.maddyhome.idea.vim.impl.state.toMappingMode
|
||||||
|
import com.maddyhome.idea.vim.state.mode.Mode
|
||||||
|
|
||||||
|
public class KeyHandlerState {
|
||||||
|
public val mappingState: MappingState = MappingState()
|
||||||
|
public val digraphSequence: DigraphSequence = DigraphSequence()
|
||||||
|
public val commandBuilder: CommandBuilder = CommandBuilder(injector.keyGroup.getKeyRoot(MappingMode.NORMAL))
|
||||||
|
|
||||||
|
public fun partialReset(mode: Mode) {
|
||||||
|
digraphSequence.reset()
|
||||||
|
mappingState.resetMappingSequence()
|
||||||
|
commandBuilder.resetInProgressCommandPart(injector.keyGroup.getKeyRoot(mode.toMappingMode()))
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun reset(mode: Mode) {
|
||||||
|
digraphSequence.reset()
|
||||||
|
mappingState.resetMappingSequence()
|
||||||
|
commandBuilder.resetAll(injector.keyGroup.getKeyRoot(mode.toMappingMode()))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user