1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-02 13:34:07 +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.VimCaretBase
import com.maddyhome.idea.vim.api.VimEditor import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.VimVisualPosition 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.EditorLine
import com.maddyhome.idea.vim.common.LiveRange import com.maddyhome.idea.vim.common.LiveRange
import com.maddyhome.idea.vim.common.Offset import com.maddyhome.idea.vim.common.Offset
@ -88,7 +89,7 @@ internal class IjVimCaret(val caret: Caret) : VimCaretBase() {
override val editor: VimEditor override val editor: VimEditor
get() = IjVimEditor(caret.editor) get() = IjVimEditor(caret.editor)
override val offset: Offset override val offset: Offset
get() = caret.offset.offset get() = injector.application.runReadAction { caret.offset.offset }
override var vimLastColumn: Int override var vimLastColumn: Int
get() = caret.vimLastColumn get() = caret.vimLastColumn
set(value) { 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.VimSelectionModel
import com.maddyhome.idea.vim.api.VimVisualPosition import com.maddyhome.idea.vim.api.VimVisualPosition
import com.maddyhome.idea.vim.api.VirtualFile 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.command.OperatorArguments
import com.maddyhome.idea.vim.common.EditorLine import com.maddyhome.idea.vim.common.EditorLine
import com.maddyhome.idea.vim.common.IndentConfig 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 { 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 * @param mode The mode - indicate insert or replace
*/ */
override fun initInsert(editor: VimEditor, context: ExecutionContext, mode: Mode) { override fun initInsert(editor: VimEditor, context: ExecutionContext, mode: Mode) {
val state = getInstance(editor) injector.application.invokeAndWait {
for (caret in editor.nativeCarets()) { val state = getInstance(editor)
caret.vimInsertStart = editor.createLiveMarker(caret.offset, caret.offset) for (caret in editor.nativeCarets()) {
injector.markService.setMark(caret, MARK_CHANGE_START, caret.offset.point) 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
} }
if (cmd.flags.contains(CommandFlags.FLAG_NO_REPEAT_INSERT)) { val cmd = state.executingCommand
val commandState = getInstance(editor) if (cmd != null && state.isDotRepeatInProgress) {
repeatInsert( state.mode = mode
editor, if (mode == Mode.REPLACE) {
context, editor.insertMode = false
1, }
false, if (cmd.flags.contains(CommandFlags.FLAG_NO_REPEAT_INSERT)) {
OperatorArguments(false, 1, commandState.mode), 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 { } else {
val commandState = getInstance(editor) lastInsert = cmd
repeatInsert( strokes.clear()
editor, repeatCharsCount = 0
context, val myVimDocument = vimDocument
cmd.count, if (myVimDocument != null && vimDocumentListener != null) {
false, myVimDocument.removeChangeListener(vimDocumentListener!!)
OperatorArguments(false, cmd.count, commandState.mode), }
) 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) { notifyListeners(editor)
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)
} }
override fun runEnterAction(editor: VimEditor, context: ExecutionContext) { override fun runEnterAction(editor: VimEditor, context: ExecutionContext) {