Skip to content

Commit

Permalink
Fix(VIM-3168): Do not switch to block caret after enter if the IdeaVi…
Browse files Browse the repository at this point in the history
…m is disabled
  • Loading branch information
AlexPl292 committed Nov 13, 2023
1 parent 41025d7 commit c13fc8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ internal val commandContinuation = Key.create<EditorActionHandler>("commandConti
*/
internal class CaretShapeEnterEditorHandler(private val nextHandler: EditorActionHandler) : EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
invokeLater {
editor.updateCaretsVisualAttributes()
if (VimPlugin.isEnabled()) {
invokeLater {
editor.updateCaretsVisualAttributes()
}
}
nextHandler.execute(editor, caret, dataContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

package com.maddyhome.idea.vim.helper

import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.CaretVisualAttributes
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.api.VimEditor
import com.maddyhome.idea.vim.api.globalOptions
import com.maddyhome.idea.vim.api.injector
Expand Down Expand Up @@ -79,13 +81,15 @@ private fun Editor.guicursorMode(): GuiCursorMode {
private fun isBlockCursorOverride() = EditorSettingsExternalizable.getInstance().isBlockCursor

private fun Editor.updatePrimaryCaretVisualAttributes() {
if (!VimPlugin.isEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
caretModel.primaryCaret.visualAttributes = AttributesCache.getCaretVisualAttributes(this)

// Make sure the caret is visible as soon as it's set. It might be invisible while blinking
(this as? EditorEx)?.setCaretVisible(true)
}

private fun Editor.updateSecondaryCaretsVisualAttributes() {
if (!VimPlugin.isEnabled()) thisLogger().error("The caret attributes should not be updated if the IdeaVim is disabled")
// IntelliJ simulates visual block with multiple carets with selections. Do our best to hide them
val attributes = if (this.vim.inBlockSelection) HIDDEN else AttributesCache.getCaretVisualAttributes(this)
this.caretModel.allCarets.forEach {
Expand Down

0 comments on commit c13fc8a

Please sign in to comment.