I’m currently using:
val editorActionManager = EditorActionManager.getInstance()
val escapeAction = IdeActions.ACTION_EDITOR_ESCAPE
val originalEscapeHandler = editorActionManager.getActionHandler(escapeAction)
editorActionManager.setActionHandler(escapeAction, MyAction(originalEscapeHandler).handler)
and
/**
* We are overriding the ESC handler's behavior to remove our inlay component if it exists. Otherwise,
* we will execute the original handler.
*/
class MyAction(originalHandler: EditorActionHandler) :
EditorAction(MyActionHandler(originalHandler)), InlineChatAction {
private class MyActionHandler(val originalHandler: EditorActionHandler) :
EditorActionHandler() {
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext) {
val sameEditorAsInlay = MyManager.getInlayComponent()?.editor == editor
if (sameEditorAsInlay) {
MyManager.dispose()
} else {
originalHandler.execute(editor, caret, dataContext)
}
}
override fun isEnabledForCaret(
editor: Editor,
caret: Caret,
dataContext: DataContext?
): Boolean {
val sameEditorAsInlay = MyManager.getInlayComponent()?.editor == editor
if (sameEditorAsInlay) return true
return originalHandler.isEnabled(editor, caret, dataContext)
}
}
}
… but somehow this doesn’t always work.
I suspect it’s because other handlers in the chain intercept the execution and stop it.
Is there a way to simply always ensure this gets run?