How do I locate the currently focused editor in popups and other IDE panels?
I am one of the developers of a plugin that accesses the primary editor, but cannot seem to find a reliable API endpoint that enables us to access other editors where the caret can be placed. Can you suggest a way to locate the currently focused editor based on the caret? As suggested by the developer documentation, we are currently using AnActionEvent.getData(CommonDataKeys.EDITOR)
to retrieve the editor, but it does not return the correct editor when the cursor is placed inside the commit message editor, or diff viewer editor. I have tried several methods, including,
AnActionEvent.getData(CommonDataKeys.HOST_EDITOR)
FileEditorManager.getInstance(project).selectedTextEditor
(IdeFocusManager.getInstance(it)?.focusOwner as? EditorComponentImpl)?.editor
getData(VcsDataKeys.COMMIT_MESSAGE_DOCUMENT)
-
com.intellij.openapi.vcs.ui.CommitMessage#getEditor(Document)
but none of them seem to retrieve the correct editor instance. Is there another API endpoint to access the relevant editor? This would enable us to toggle the plugin for example, in the search bar, terminal, settings menu or other selectable text areas using a single endpoint (without specifying which editor specifically).
请先登录再写评论。
Researching, there is no clear/obvious solution to that...
Please try
com.intellij.openapi.actionSystem.PlatformDataKeys#LAST_ACTIVE_FILE_EDITOR
Thank you for looking into this. I tried the suggested data key, but when I tried activating it in the commit message editor. `git clone git@github.com:acejump/AceJump.git && cd AceJump && git checkout 3c89cd07b93f1fdad596bfc7f4bf3bb3142b30ba && ./gradlew runIde` and try to activate the plugin in the main editor it works, but when I activate it in the commit editor via [Ctrl]+[;], it does not seem to do anything. Maybe I'm just doing it completely wrong. Is there a better way to get an `Editor` from a `FileEditor`?
Is the data null or does the cast fail?
Hmm, in the old commit message editor, it seems the action never gets invoked, so neither. The new non modal commit interface, it partly works but fails the cast. But `LAST_ACTIVE_FILE_EDITOR` is a good start, I just need to figure out how to get an Editor / TextEditor from a FileEditor but I should be able to sort that out on my own. Thanks!