Skip to content

Commit

Permalink
Move implementations to upper level
Browse files Browse the repository at this point in the history
It will simplify support of immutable editors in Fleet
  • Loading branch information
lippfi committed Feb 20, 2024
1 parent 0d7cfc3 commit c55050c
Showing 1 changed file with 31 additions and 37 deletions.
68 changes: 31 additions & 37 deletions vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit c55050c

Please sign in to comment.