1
0
mirror of https://github.com/chylex/IntelliJ-IdeaVim.git synced 2025-04-30 22:34:04 +02:00

Refactor improper usages of toggleVisual

This commit is contained in:
Matt Ellis 2025-01-01 11:05:46 +00:00 committed by Alex Pláte
parent bfa271b089
commit eb19d9fb11
3 changed files with 20 additions and 7 deletions
vim-engine/src/main/kotlin/com/maddyhome/idea/vim

View File

@ -19,8 +19,21 @@ interface VimVisualMotionGroup {
* Enters Visual mode, ensuring that the caret's selection start offset is correctly set
*
* Use this to programmatically enter Visual mode. Note that it does not modify the editor's selection.
*
* This overload needs to remain for compatibility with external IdeaVim extensions
*/
fun enterVisualMode(editor: VimEditor, selectionType: SelectionType): Boolean
fun enterVisualMode(editor: VimEditor, selectionType: SelectionType): Boolean {
return enterVisualMode(editor, selectionType, Mode.NORMAL())
}
/**
* Enters Visual mode, ensuring that the caret's selection start offset is correctly set
*
* Use this to programmatically enter Visual mode. Note that it does not modify the editor's selection. You can
* specify the mode to return to when Visual command exits. Typically, this is [Mode.NORMAL], but can be [Mode.INSERT]
* or [Mode.REPLACE] for "Insert Visual" or [Mode.SELECT] when processing a single Visual command in Select mode.
*/
fun enterVisualMode(editor: VimEditor, selectionType: SelectionType, returnTo: Mode): Boolean
/**
* Enter Select mode with the given selection type

View File

@ -31,8 +31,8 @@ abstract class VimVisualMotionGroupBase : VimVisualMotionGroup {
*
* Use this to programmatically enter Visual mode. Note that it does not modify the editor's selection.
*/
override fun enterVisualMode(editor: VimEditor, selectionType: SelectionType): Boolean {
editor.mode = Mode.VISUAL(selectionType)
override fun enterVisualMode(editor: VimEditor, selectionType: SelectionType, returnTo: Mode): Boolean {
editor.mode = Mode.VISUAL(selectionType, returnTo)
// vimLeadSelectionOffset requires read action
injector.application.runReadAction {

View File

@ -61,7 +61,7 @@ abstract class ShiftedSpecialKeyHandler : VimActionHandler.ConditionalMulticaret
if (injector.globalOptions().selectmode.contains(OptionConstants.selectmode_key)) {
injector.visualMotionGroup.enterSelectMode(editor, SelectionType.CHARACTER_WISE)
} else {
injector.visualMotionGroup.toggleVisual(editor, 1, 0, SelectionType.CHARACTER_WISE)
injector.visualMotionGroup.enterVisualMode(editor, SelectionType.CHARACTER_WISE)
}
}
return true
@ -97,10 +97,10 @@ abstract class ShiftedArrowKeyHandler(private val runBothCommandsAsMulticaret: B
injector.visualMotionGroup.enterSelectMode(editor, SelectionType.CHARACTER_WISE)
} else {
if (editor.isInsertionAllowed) {
// Enter Insert/Replace Visual mode
injector.visualMotionGroup.toggleVisual(editor, 1, 0, SelectionType.CHARACTER_WISE, editor.mode)
// Enter Insert/Replace Visual mode, passing in the current Insert/Replace mode as pending
injector.visualMotionGroup.enterVisualMode(editor, SelectionType.CHARACTER_WISE, editor.mode)
} else {
injector.visualMotionGroup.toggleVisual(editor, 1, 0, SelectionType.CHARACTER_WISE)
injector.visualMotionGroup.enterVisualMode(editor, SelectionType.CHARACTER_WISE)
}
}
}