Skip to content

Commit

Permalink
Merge pull request #230 from fan-tom/VIM-1924_select_next_occurrence
Browse files Browse the repository at this point in the history
VIM-1924
  • Loading branch information
AlexPl292 authored May 8, 2020
2 parents c6cf77e + a4cd948 commit b8c22d0
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/com/maddyhome/idea/vim/group/visual/VisualMotionGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.maddyhome.idea.vim.group.visual

import com.intellij.find.FindManager
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.LogicalPosition
Expand Down Expand Up @@ -216,20 +217,22 @@ class VisualMotionGroup {
}

fun autodetectVisualSubmode(editor: Editor): CommandState.SubMode {
if (editor.caretModel.caretCount > 1 && seemsLikeBlockMode(editor)) {
return CommandState.SubMode.VISUAL_BLOCK
if (!FindManager.getInstance(editor.project).selectNextOccurrenceWasPerformed()) {
if (editor.caretModel.caretCount > 1 && seemsLikeBlockMode(editor)) {
return CommandState.SubMode.VISUAL_BLOCK
}
if (editor.caretModel.allCarets.all { caret ->
// Detect if visual mode is character wise or line wise
val selectionStart = caret.selectionStart
val selectionEnd = caret.selectionEnd
val logicalStartLine = editor.offsetToLogicalPosition(selectionStart).line
val logicalEnd = editor.offsetToLogicalPosition(selectionEnd)
val logicalEndLine = if (logicalEnd.column == 0) (logicalEnd.line - 1).coerceAtLeast(0) else logicalEnd.line
val lineStartOfSelectionStart = EditorHelper.getLineStartOffset(editor, logicalStartLine)
val lineEndOfSelectionEnd = EditorHelper.getLineEndOffset(editor, logicalEndLine, true)
lineStartOfSelectionStart == selectionStart && (lineEndOfSelectionEnd + 1 == selectionEnd || lineEndOfSelectionEnd == selectionEnd)
}) return CommandState.SubMode.VISUAL_LINE
}
if (editor.caretModel.allCarets.all { caret ->
// Detect if visual mode is character wise or line wise
val selectionStart = caret.selectionStart
val selectionEnd = caret.selectionEnd
val logicalStartLine = editor.offsetToLogicalPosition(selectionStart).line
val logicalEnd = editor.offsetToLogicalPosition(selectionEnd)
val logicalEndLine = if (logicalEnd.column == 0) (logicalEnd.line - 1).coerceAtLeast(0) else logicalEnd.line
val lineStartOfSelectionStart = EditorHelper.getLineStartOffset(editor, logicalStartLine)
val lineEndOfSelectionEnd = EditorHelper.getLineEndOffset(editor, logicalEndLine, true)
lineStartOfSelectionStart == selectionStart && (lineEndOfSelectionEnd + 1 == selectionEnd || lineEndOfSelectionEnd == selectionEnd)
}) return CommandState.SubMode.VISUAL_LINE
return CommandState.SubMode.VISUAL_CHARACTER
}

Expand Down

0 comments on commit b8c22d0

Please sign in to comment.