Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 2e5b3ab

Browse files
authored
[JetBrains] Fix an issue with exiting the multi-caret mode (#8179)
My [fix](https://github.com/sourcegraph/cody/pull/8071) broke exiting from multiline caret mode 🥲 This PR fixes the issue by using the built-in chain of responsibility responsibly 😅 ## Test Plan ### Test Case 1: Multiline Mode + Auto-edit Dismissal **Setup:** - No Vim extension enabled - Open any file in editor - Add multiple cursors (Ctrl/Cmd + Alt + Click or similar) - Enter multiline editing mode **Steps:** 1. Trigger auto-edit suggestion (type code that generates autocomplete) 2. Verify popup/inlay appears 3. Press `Escape` key **Expected Result:** - Auto-edit popup/inlay is dismissed - Multiline cursor mode is exited (returns to single cursor) - Editor returns to normal single-cursor state ### Test Case 2: Vim Insert Mode + Auto-edit Dismissal **Setup:** - Vim extension (IdeaVim) enabled - Open any file in editor - Enter Vim insert mode (`i`, `a`, `o`, etc.) **Steps:** 1. While in insert mode, trigger auto-edit suggestion 2. Verify popup/inlay appears 3. Press `Escape` key **Expected Result:** - Auto-edit popup/inlay is dismissed - Vim exits insert mode and returns to normal mode - Cursor behavior follows Vim normal mode conventions ### Test Case 3: Baseline - No Special Mode **Setup:** - No Vim extension - Single cursor, normal editing mode **Steps:** 1. Trigger auto-edit suggestion 2. Verify popup/inlay appears 3. Press `Escape` key **Expected Result:** - Auto-edit popup/inlay is dismissed - Editor remains in normal editing state - No unexpected mode changes --- **Note:** These test cases verify that the handler properly participates in IntelliJ's action chain, allowing both autocomplete dismissal AND the underlying editor action (multiline exit, vim mode change) to execute correctly. <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. -->
1 parent ce48776 commit 2e5b3ab

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

jetbrains/src/main/kotlin/com/sourcegraph/cody/autocomplete/action/DisposeAutocompleteSuggestionActionHandler.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ package com.sourcegraph.cody.autocomplete.action
33
import com.intellij.openapi.actionSystem.DataContext
44
import com.intellij.openapi.editor.Caret
55
import com.intellij.openapi.editor.Editor
6+
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
67
import com.sourcegraph.cody.autocomplete.CodyAutocompleteManager
78
import com.sourcegraph.cody.autoedit.AutoeditManager
89

9-
class DisposeAutocompleteSuggestionActionHandler : AutocompleteActionHandler() {
10+
class DisposeAutocompleteSuggestionActionHandler(private val originalHandler: EditorActionHandler) :
11+
AutocompleteActionHandler() {
1012
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
11-
val project = editor.project ?: return
12-
CodyAutocompleteManager.getInstance(project).disposeInlays(editor)
13-
AutoeditManager.getInstance(project).hide()
13+
editor.project?.let {
14+
CodyAutocompleteManager.getInstance(it).disposeInlays(editor)
15+
AutoeditManager.getInstance(it).hide()
16+
}
17+
18+
originalHandler.execute(editor, caret, dataContext)
1419
}
20+
21+
override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?) =
22+
if (super.isEnabledForCaret(editor, caret, dataContext)) true
23+
else originalHandler.isEnabled(editor, caret, dataContext)
1524
}

jetbrains/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<editorActionHandler
5454
id="cody.disposeAutocompleteSuggestionHandler" action="EditorEscape"
5555
implementationClass="com.sourcegraph.cody.autocomplete.action.DisposeAutocompleteSuggestionActionHandler"
56-
order="after ideavim-esc"/>
56+
/>
5757

5858
<applicationService
5959
serviceImplementation="com.sourcegraph.cody.auth.deprecated.DeprecatedCodyPersistentAccounts"/>

0 commit comments

Comments
 (0)