1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-05-23 13:34:03 +02:00

Add readActions & EDT

This commit is contained in:
Filipp Vakhitov 2024-01-31 14:43:23 +02:00
parent 0e03151505
commit 45a2eadc58
3 changed files with 55 additions and 49 deletions
src/main/java/com/maddyhome/idea/vim/newapi
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api

View File

@ -22,6 +22,7 @@ import com.maddyhome.idea.vim.api.VimCaret
import com.maddyhome.idea.vim.api.VimCaretBase
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimVisualPosition
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.common.EditorLine
import com.maddyhome.idea.vim.common.LiveRange
import com.maddyhome.idea.vim.common.Offset
@ -88,7 +89,7 @@ internal class IjVimCaret(val caret: Caret) : VimCaretBase() {
override val editor: VimEditor
get() = IjVimEditor(caret.editor)
override val offset: Offset
get() = caret.offset.offset
get() = injector.application.runReadAction { caret.offset.offset }
override var vimLastColumn: Int
get() = caret.vimLastColumn
set(value) {

View File

@ -35,6 +35,7 @@ import com.maddyhome.idea.vim.api.VimScrollingModel
import com.maddyhome.idea.vim.api.VimSelectionModel
import com.maddyhome.idea.vim.api.VimVisualPosition
import com.maddyhome.idea.vim.api.VirtualFile
import com.maddyhome.idea.vim.api.injector
import com.maddyhome.idea.vim.command.OperatorArguments
import com.maddyhome.idea.vim.common.EditorLine
import com.maddyhome.idea.vim.common.IndentConfig
@ -428,7 +429,9 @@ internal class IjVimEditor(editor: Editor) : MutableLinearEditor() {
}
override fun createLiveMarker(start: Offset, end: Offset): LiveRange {
return editor.document.createRangeMarker(start.point, end.point).vim
return injector.application.runReadAction {
editor.document.createRangeMarker(start.point, end.point).vim
}
}
/**

View File

@ -432,57 +432,59 @@ public abstract class VimChangeGroupBase : VimChangeGroup {
* @param mode The mode - indicate insert or replace
*/
override fun initInsert(editor: VimEditor, context: ExecutionContext, mode: Mode) {
val state = getInstance(editor)
for (caret in editor.nativeCarets()) {
caret.vimInsertStart = editor.createLiveMarker(caret.offset, caret.offset)
injector.markService.setMark(caret, MARK_CHANGE_START, caret.offset.point)
}
val cmd = state.executingCommand
if (cmd != null && state.isDotRepeatInProgress) {
state.mode = mode
if (mode == Mode.REPLACE) {
editor.insertMode = false
injector.application.invokeAndWait {
val state = getInstance(editor)
for (caret in editor.nativeCarets()) {
caret.vimInsertStart = editor.createLiveMarker(caret.offset, caret.offset)
injector.markService.setMark(caret, MARK_CHANGE_START, caret.offset.point)
}
if (cmd.flags.contains(CommandFlags.FLAG_NO_REPEAT_INSERT)) {
val commandState = getInstance(editor)
repeatInsert(
editor,
context,
1,
false,
OperatorArguments(false, 1, commandState.mode),
)
val cmd = state.executingCommand
if (cmd != null && state.isDotRepeatInProgress) {
state.mode = mode
if (mode == Mode.REPLACE) {
editor.insertMode = false
}
if (cmd.flags.contains(CommandFlags.FLAG_NO_REPEAT_INSERT)) {
val commandState = getInstance(editor)
repeatInsert(
editor,
context,
1,
false,
OperatorArguments(false, 1, commandState.mode),
)
} else {
val commandState = getInstance(editor)
repeatInsert(
editor,
context,
cmd.count,
false,
OperatorArguments(false, cmd.count, commandState.mode),
)
}
if (mode == Mode.REPLACE) {
editor.insertMode = true
}
state.mode = Mode.NORMAL()
} else {
val commandState = getInstance(editor)
repeatInsert(
editor,
context,
cmd.count,
false,
OperatorArguments(false, cmd.count, commandState.mode),
)
lastInsert = cmd
strokes.clear()
repeatCharsCount = 0
val myVimDocument = vimDocument
if (myVimDocument != null && vimDocumentListener != null) {
myVimDocument.removeChangeListener(vimDocumentListener!!)
}
vimDocument = editor.document
val myChangeListener = VimChangesListener()
vimDocumentListener = myChangeListener
vimDocument!!.addChangeListener(myChangeListener)
oldOffset = editor.currentCaret().offset.point
editor.insertMode = mode == Mode.INSERT
state.mode = mode
}
if (mode == Mode.REPLACE) {
editor.insertMode = true
}
state.mode = Mode.NORMAL()
} else {
lastInsert = cmd
strokes.clear()
repeatCharsCount = 0
val myVimDocument = vimDocument
if (myVimDocument != null && vimDocumentListener != null) {
myVimDocument.removeChangeListener(vimDocumentListener!!)
}
vimDocument = editor.document
val myChangeListener = VimChangesListener()
vimDocumentListener = myChangeListener
vimDocument!!.addChangeListener(myChangeListener)
oldOffset = editor.currentCaret().offset.point
editor.insertMode = mode == Mode.INSERT
state.mode = mode
notifyListeners(editor)
}
notifyListeners(editor)
}
override fun runEnterAction(editor: VimEditor, context: ExecutionContext) {