From e27c365056b4bc1648c7b75f1cada554dd74aac6 Mon Sep 17 00:00:00 2001 From: Brice Dutheil Date: Sat, 11 Sep 2021 00:47:05 +0200 Subject: [PATCH] fix: Incorrect editor selected in split panes #13 Fixes #13 --- CHANGELOG.md | 4 ++++ plugin/gradle.properties | 2 +- .../src/main/kotlin/com/github/bric3/excalidraw/utils.kt | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a49ad14..3b88723 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ # excalidraw-jetbrains-plugin Changelog ## [Unreleased] +## [0.3.2-eap] - 2021-08-12 +### Fixed +- Incorrect editor selected in split panes ([#11](https://github.com/bric3/excalidraw-jetbrains-plugin/issues/13)) + ## [0.3.1-eap] - 2021-08-12 ### Fixed - Fixed compatibility issue with 2021.1.x diff --git a/plugin/gradle.properties b/plugin/gradle.properties index 6aa4bc9..a481023 100644 --- a/plugin/gradle.properties +++ b/plugin/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = com.github.bric3.excalidrawjetbrainsplugin pluginName = excalidraw-jetbrains-plugin -pluginVersion = 0.3.1-eap +pluginVersion = 0.3.2-eap # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. diff --git a/plugin/src/main/kotlin/com/github/bric3/excalidraw/utils.kt b/plugin/src/main/kotlin/com/github/bric3/excalidraw/utils.kt index dbc0be6..10d28fe 100644 --- a/plugin/src/main/kotlin/com/github/bric3/excalidraw/utils.kt +++ b/plugin/src/main/kotlin/com/github/bric3/excalidraw/utils.kt @@ -6,10 +6,12 @@ import com.intellij.notification.Notification import com.intellij.notification.NotificationType import com.intellij.notification.Notifications import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiFile import org.jetbrains.concurrency.AsyncPromise import java.io.IOException @@ -29,7 +31,12 @@ val debugMode = ProcessHandle.current().info().arguments().map { */ fun AnActionEvent.findEditor(): ExcalidrawEditor? { val project = this.project ?: return null - return FileEditorManager.getInstance(project).selectedEditor as? ExcalidrawEditor ?: return null + val psiFile = (this.dataContext.getData(CommonDataKeys.PSI_FILE) as PsiFile) + val editor = FileEditorManager.getInstance(project).selectedEditors.find { + psiFile.virtualFile.equals(it.file) + } + + return editor as? ExcalidrawEditor ?: return null }