Skip to content

Commit

Permalink
Add write action in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPl292 committed Feb 21, 2025
1 parent c9189ed commit 42d80f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package com.maddyhome.idea.vim.extension.exchange

import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
import com.intellij.openapi.editor.colors.EditorColors
Expand Down Expand Up @@ -111,12 +110,10 @@ internal class VimExchangeExtension : VimExtension {

private class VExchangeHandler : ExtensionHandler {
override fun execute(editor: VimEditor, context: ExecutionContext, operatorArguments: OperatorArguments) {
runWriteAction {
val mode = editor.mode
// Leave visual mode to create selection marks
executeNormalWithoutMapping(injector.parser.parseKeys("<Esc>"), editor.ij)
Operator(true).apply(editor, context, mode.selectionType ?: SelectionType.CHARACTER_WISE)
}
val mode = editor.mode
// Leave visual mode to create selection marks
executeNormalWithoutMapping(injector.parser.parseKeys("<Esc>"), editor.ij)
Operator(true).apply(editor, context, mode.selectionType ?: SelectionType.CHARACTER_WISE)
}
}

Expand Down Expand Up @@ -226,23 +223,22 @@ internal class VimExchangeExtension : VimExtension {
val unnRegText = getRegister(editor.vim, '"')
val startRegText = getRegister(editor.vim, '*')
val plusRegText = getRegister(editor.vim, '+')
runWriteAction {
// TODO handle:
// " Compare using =~ because "'==' != 0" returns 0
// let indent = s:get_setting('exchange_indent', 1) !~ 0 && a:x.type ==# 'V' && a:y.type ==# 'V'
pasteExchange(ex1, ex2)
if (!expand) {
pasteExchange(ex2, ex1)
}
// TODO: handle: if ident
if (!expand) {
fixCursor(ex1, ex2, reverse)
}
setRegister('z', zRegText)
setRegister('"', unnRegText)
setRegister('*', startRegText)
setRegister('+', plusRegText)

// TODO handle:
// " Compare using =~ because "'==' != 0" returns 0
// let indent = s:get_setting('exchange_indent', 1) !~ 0 && a:x.type ==# 'V' && a:y.type ==# 'V'
pasteExchange(ex1, ex2)
if (!expand) {
pasteExchange(ex2, ex1)
}
// TODO: handle: if ident
if (!expand) {
fixCursor(ex1, ex2, reverse)
}
setRegister('z', zRegText)
setRegister('"', unnRegText)
setRegister('*', startRegText)
setRegister('+', plusRegText)
}

private fun compareExchanges(x: Exchange, y: Exchange): ExchangeCompareResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,7 @@ abstract class VimPutBase : VimPut {
logger.debug("Perform put via plugin")
val myCarets = visualSelection?.caretsAndSelections?.keys?.sortedByDescending { it.getBufferPosition() }
?: 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 {
Expand Down

0 comments on commit 42d80f6

Please sign in to comment.