1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-06-17 15:39:56 +02:00

Better multiple caret support for surround

This commit is contained in:
filipp 2023-03-14 00:10:05 +02:00
parent bef57f75c0
commit a78f66fd36

View File

@ -239,19 +239,19 @@ internal class VimSurroundExtension : VimExtension {
val pair = getOrInputPair(c, ijEditor) ?: return false val pair = getOrInputPair(c, ijEditor) ?: return false
// XXX: Will it work with line-wise or block-wise selections? // XXX: Will it work with line-wise or block-wise selections?
val range = getSurroundRange(ijEditor) ?: return false val range = getSurroundRange(editor.currentCaret()) ?: return false
performSurround(pair, range, editor.currentCaret()) performSurround(pair, range, editor.currentCaret())
// Jump back to start // Jump back to start
executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor) executeNormalWithoutMapping(injector.parser.parseKeys("`["), ijEditor)
return true return true
} }
// todo make it multicaret private fun getSurroundRange(caret: VimCaret): TextRange? {
private fun getSurroundRange(editor: Editor): TextRange? { val editor = caret.editor
val vimEditor = editor.vim val ijEditor = editor.ij
return when (editor.editorMode) { return when (ijEditor.editorMode) {
VimStateMachine.Mode.COMMAND -> injector.markService.getChangeMarks(vimEditor.primaryCaret()) VimStateMachine.Mode.COMMAND -> injector.markService.getChangeMarks(caret)
VimStateMachine.Mode.VISUAL -> editor.caretModel.primaryCaret.run { TextRange(selectionStart, selectionEnd) } VimStateMachine.Mode.VISUAL -> caret.run { TextRange(selectionStart, selectionEnd) }
else -> null else -> null
} }
} }