1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-09 07:34:03 +02:00

Add write action in several places

This commit is contained in:
Alex Plate 2025-02-21 19:32:47 +02:00
parent c9189ed7cb
commit 42d80f6866
No known key found for this signature in database
GPG Key ID: 0B97153C8FFEC09F
2 changed files with 20 additions and 26 deletions
src/main/java/com/maddyhome/idea/vim/extension/exchange
vim-engine/src/main/kotlin/com/maddyhome/idea/vim/put

View File

@ -8,7 +8,6 @@
package com.maddyhome.idea.vim.extension.exchange package com.maddyhome.idea.vim.extension.exchange
import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColors
@ -111,14 +110,12 @@ internal class VimExchangeExtension : VimExtension {
private class VExchangeHandler : ExtensionHandler { private class VExchangeHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) { override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
runWriteAction {
val mode = editor.mode val mode = editor.mode
// Leave visual mode to create selection marks // Leave visual mode to create selection marks
executeNormalWithoutMapping(injector.parser.parseKeys("<Esc>"), editor.ij) executeNormalWithoutMapping(injector.parser.parseKeys("<Esc>"), editor.ij)
Operator(true).apply(editor, context, mode.selectionType ?: SelectionType.CHARACTER_WISE) Operator(true).apply(editor, context, mode.selectionType ?: SelectionType.CHARACTER_WISE)
} }
} }
}
private class Operator(private val isVisual: Boolean = false) : OperatorFunction { private class Operator(private val isVisual: Boolean = false) : OperatorFunction {
fun Editor.getMarkOffset(mark: Mark) = IjVimEditor(this).getOffset(mark.line, mark.col) fun Editor.getMarkOffset(mark: Mark) = IjVimEditor(this).getOffset(mark.line, mark.col)
@ -226,7 +223,7 @@ internal class VimExchangeExtension : VimExtension {
val unnRegText = getRegister(editor.vim, '"') val unnRegText = getRegister(editor.vim, '"')
val startRegText = getRegister(editor.vim, '*') val startRegText = getRegister(editor.vim, '*')
val plusRegText = getRegister(editor.vim, '+') val plusRegText = getRegister(editor.vim, '+')
runWriteAction {
// TODO handle: // TODO handle:
// " Compare using =~ because "'==' != 0" returns 0 // " Compare using =~ because "'==' != 0" returns 0
// let indent = s:get_setting('exchange_indent', 1) !~ 0 && a:x.type ==# 'V' && a:y.type ==# 'V' // let indent = s:get_setting('exchange_indent', 1) !~ 0 && a:x.type ==# 'V' && a:y.type ==# 'V'
@ -243,7 +240,6 @@ internal class VimExchangeExtension : VimExtension {
setRegister('*', startRegText) setRegister('*', startRegText)
setRegister('+', plusRegText) setRegister('+', plusRegText)
} }
}
private fun compareExchanges(x: Exchange, y: Exchange): ExchangeCompareResult { private fun compareExchanges(x: Exchange, y: Exchange): ExchangeCompareResult {
fun intersects(x: Exchange, y: Exchange) = fun intersects(x: Exchange, y: Exchange) =

View File

@ -580,10 +580,8 @@ abstract class VimPutBase : VimPut {
logger.debug("Perform put via plugin") logger.debug("Perform put via plugin")
val myCarets = visualSelection?.caretsAndSelections?.keys?.sortedByDescending { it.getBufferPosition() } val myCarets = visualSelection?.caretsAndSelections?.keys?.sortedByDescending { it.getBufferPosition() }
?: editor.sortedNativeCarets().reversed() ?: editor.sortedNativeCarets().reversed()
injector.application.runWriteAction {
myCarets.forEach { caret -> putForCaret(editor, caret, data, additionalData, context, text) } myCarets.forEach { caret -> putForCaret(editor, caret, data, additionalData, context, text) }
} }
}
companion object { companion object {
val logger: VimLogger by lazy { vimLogger<VimPutBase>() } val logger: VimLogger by lazy { vimLogger<VimPutBase>() }