Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset caret shape when disabling plugin #401

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/com/maddyhome/idea/vim/group/EditorGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener;
import com.intellij.openapi.editor.ex.EditorGutterComponentEx;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.project.Project;
import com.maddyhome.idea.vim.KeyHandler;
import com.maddyhome.idea.vim.VimPlugin;
Expand Down Expand Up @@ -230,9 +229,9 @@ public void editorDeinit(@NotNull Editor editor, boolean isReleased) {
deinitLineNumbers(editor, isReleased);
UserDataManager.unInitializeEditor(editor);
VimPlugin.getKey().unregisterShortcutKeys(editor);
editor.getSettings().setBlockCursor(EditorSettingsExternalizable.getInstance().isBlockCursor());
editor.getSettings().setRefrainFromScrolling(isRefrainFromScrolling);
DocumentManager.INSTANCE.removeListeners(editor.getDocument());
CaretVisualAttributesHelperKt.removeCaretsVisualAttributes(editor);
}

public void notifyIdeaJoin(@Nullable Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ fun Editor.updateCaretsVisualAttributes() {
updateSecondaryCaretsVisualAttributes()
}

/**
* Remove custom visual attributes and reset to defaults
*
* Used when Vim emulation is disabled
*/
fun removeCaretsVisualAttributes(editor: Editor) {
editor.caretModel.allCarets.forEach { it.visualAttributes = CaretVisualAttributes.DEFAULT }
editor.settings.isBlockCursor = EditorSettingsExternalizable.getInstance().isBlockCursor
}

fun Editor.guicursorMode(): GuiCursorMode {
if (subMode == CommandState.SubMode.REPLACE_CHARACTER) {
// Can be true for NORMAL and VISUAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.jetbrains.plugins.ideavim.helper

import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
import com.maddyhome.idea.vim.VimPlugin
import com.maddyhome.idea.vim.helper.StringHelper.parseKeys
import com.maddyhome.idea.vim.helper.VimBehaviorDiffers
import com.maddyhome.idea.vim.helper.buildGreater212
Expand Down Expand Up @@ -239,6 +240,30 @@ class CaretVisualAttributesHelperTest : VimTestCase() {
}
}

@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
fun `test reset caret shape when disable plugin`() {
configureByText("I found it in a legendary land")
typeText(parseKeys("i"))
VimPlugin.setEnabled(false)
assertCaretVisualAttributes("DEFAULT", 1.0f)
}

@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
fun `test reset caret shape when disable plugin 2`() {
configureByText("I found it in a legendary land")
typeText(parseKeys("v2e"))
VimPlugin.setEnabled(false)
assertCaretVisualAttributes("DEFAULT", 1.0f)
}

@TestWithoutNeovim(SkipNeovimReason.NOT_VIM_TESTING)
fun `test reset caret shape when disable plugin 3`() {
configureByText("I found it in a legendary land")
typeText(parseKeys("r"))
VimPlugin.setEnabled(false)
assertCaretVisualAttributes("DEFAULT", 1.0f)
}

private fun assertCaretVisualAttributes(expectedShape: String, expectedThickness: Float) {
assertCaretVisualAttributes(myFixture.editor.caretModel.primaryCaret, expectedShape, expectedThickness)
}
Expand Down