From c55050c796d7e9c911ce600305e7a9b84ec45eda Mon Sep 17 00:00:00 2001 From: Filipp Vakhitov Date: Tue, 20 Feb 2024 14:57:28 +0200 Subject: [PATCH] Move implementations to upper level It will simplify support of immutable editors in Fleet --- .../com/maddyhome/idea/vim/api/VimEditor.kt | 68 +++++++++---------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimEditor.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimEditor.kt index 4921d96a71d..f6f78770133 100644 --- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimEditor.kt +++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimEditor.kt @@ -130,7 +130,23 @@ import com.maddyhome.idea.vim.state.mode.returnTo */ public interface VimEditor { public var mode: Mode - public var isReplaceCharacter: Boolean + get() = vimStateMachine.mode + set(value) { + if (vimStateMachine.mode == value) return + + val oldValue = vimStateMachine.mode + (vimStateMachine as VimStateMachineImpl).mode = value + injector.listenersNotifier.notifyModeChanged(this, oldValue) + } + + public var isReplaceCharacter: Boolean + get() = vimStateMachine.isReplaceCharacter + set(value) { + if (value != vimStateMachine.isReplaceCharacter) { + (vimStateMachine as VimStateMachineImpl).isReplaceCharacter = value + injector.listenersNotifier.notifyIsReplaceCharChanged(this) + } + } public val lfMakesNewLine: Boolean public var vimChangeActionSwitchMode: Mode? @@ -284,35 +300,16 @@ public interface VimEditor { /** * Resets the command, mode, visual mode, and mapping mode to initial values. */ - public fun resetState() - public fun resetOpPending() -} - -public interface MutableVimEditor : VimEditor { - public fun addLine(atPosition: EditorLine.Offset): EditorLine.Pointer? - public fun insertText(atPosition: Offset, text: CharSequence) - public fun replaceString(start: Int, end: Int, newString: String) - - override var mode: Mode - get() = vimStateMachine.mode - set(value) { - if (vimStateMachine.mode == value) return - - val oldValue = vimStateMachine.mode - (vimStateMachine as VimStateMachineImpl).mode = value - injector.listenersNotifier.notifyModeChanged(this, oldValue) - } - - override var isReplaceCharacter: Boolean - get() = vimStateMachine.isReplaceCharacter - set(value) { - if (value != vimStateMachine.isReplaceCharacter) { - (vimStateMachine as VimStateMachineImpl).isReplaceCharacter = value - injector.listenersNotifier.notifyIsReplaceCharChanged(this) - } - } + public fun resetState() { + mode = Mode.NORMAL() + vimStateMachine.executingCommand = null + vimStateMachine.digraphSequence.reset() + vimStateMachine.commandBuilder.resetInProgressCommandPart( + injector.keyGroup.getKeyRoot(mode.toMappingMode()) + ) + } - public override fun resetOpPending() { + public fun resetOpPending() { if (this.mode is Mode.OP_PENDING) { val returnTo = this.mode.returnTo mode = when (returnTo) { @@ -322,15 +319,12 @@ public interface MutableVimEditor : VimEditor { } } } +} - override fun resetState() { - mode = Mode.NORMAL() - vimStateMachine.executingCommand = null - vimStateMachine.digraphSequence.reset() - vimStateMachine.commandBuilder.resetInProgressCommandPart( - injector.keyGroup.getKeyRoot(mode.toMappingMode()) - ) - } +public interface MutableVimEditor : VimEditor { + public fun addLine(atPosition: EditorLine.Offset): EditorLine.Pointer? + public fun insertText(atPosition: Offset, text: CharSequence) + public fun replaceString(start: Int, end: Int, newString: String) } public abstract class LinearEditor : VimEditor {