With split panes, toolbar action apply to the selected / active editor
Answered
Suppose two diagrams are displayed side-to-side. Eg
Here, the right editor is selected (notice the blue line on the editor tab).
When toolbar icon is interacted on the right editor, the action will apply on the left editor which is the selected editor.
My code to find the editor is quite simple
fun AnActionEvent.findEditor(): ExcalidrawEditor? {
val project = this.project ?: return null
return FileEditorManager.getInstance(project).selectedEditor as? ExcalidrawEditor ?: return null
}
I supposed that getSelectedEditor would return the selected editor.
If someone can advise on what I can do to improve the situation.
Please sign in to leave a comment.
Please specify your IDE version. Do you set com.intellij.openapi.actionSystem.ActionToolbar#setTargetComponent in your action toolbar registration?
Yann Cebron Hi Yes sorry for that
I'm developing the plugin against version 2020.3.
Yes, here's the relevant (simplified) code.
`viewController.component` is a `MultiPanel` that has a `JCEFHtmlPanel`.
This might be caused by JCEF/Focus issues. Could you please debug around com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl#getActiveSplittersSync ?
Hi Yann Cebron
Sorry for the late reply, I took some time away from the keyboard, then just started another job, and postponed on this issue.
So what debug showed me at this point in FileEditorManagerImpl#getActiveSplittersSync is that these lines seems to bring the JCEF component of the right pane instead of the left pane.
When following the getFocusOwner method up to com.intellij.openapi.wm.impl.FocusManagerImpl#getFocusOwner, I noticed that this code brings the JCEF component.
Technically this is not erroneous as the right pane is indeed the one that is selected and active, when the toolbar action icon is clicked on the right editor.
Maybe the current code may miss another piece to be able to find the relevant editor or, I need to use a different way to get the relevant editor than getSelectedEditor
After some debugging, I noticed there's some interesting contextual data in the event, in particular psi.File. Using this information it is possible to find the correct editor from selectedEditors (Notice the s). So I replaced this code
By
This code works well however I wonder if the psi.File (or CommonDataKeys.PSI_FILE) as contextual data of such event will last.
Anyway, thank you for looking into this problem.
Hi, Brice, have you tried
in your toolbar actions?
Hi @...
This returns `null`.
The only values in `myDataContext.myCachedData` are :
If you're interested, the code is here : https://github.com/bric3/excalidraw-jetbrains-plugin
In particular the toolbar creation code is here :