diff --git a/idea-plugin/build.gradle.kts b/idea-plugin/build.gradle.kts index 8e7fdb866e..0030b61e88 100644 --- a/idea-plugin/build.gradle.kts +++ b/idea-plugin/build.gradle.kts @@ -1,9 +1,9 @@ -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.5.10" - id("org.jetbrains.intellij") version "1.10.1" + id("org.jetbrains.intellij") version "1.12.0" id("org.jetbrains.changelog") version "1.3.1" } @@ -44,11 +44,11 @@ tasks.buildSearchableOptions { tasks { // Set the compatibility versions to 1.8 withType { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" + sourceCompatibility = "11" + targetCompatibility = "11" } withType { - kotlinOptions.jvmTarget = "1.8" + kotlinOptions.jvmTarget = "11" } publishPlugin { diff --git a/idea-plugin/gradle.properties b/idea-plugin/gradle.properties index 0755c4f3e8..0ee97128d8 100644 --- a/idea-plugin/gradle.properties +++ b/idea-plugin/gradle.properties @@ -7,8 +7,8 @@ deploy.version=0.1-SNAPSHOT plugin.channels=snapshots # Intellij since-build should be updated directly in src/main/resources/META-INF/plugin.xml # See https://jb.gg/intellij-platform-builds-list for available build versions. -plugin.verifier.ide.versions=2021.3, 2022.1, 2022.2 +plugin.verifier.ide.versions=2022.1, 2022.2, 2022.3 platform.type=IC -platform.version=2021.3 +platform.version=2022.1.1 platform.download.sources=true diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt index 0a05eb0a6f..e8a8f3543c 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewFloatingToolbarProvider.kt @@ -8,13 +8,17 @@ package org.jetbrains.compose.desktop.ide.preview import com.intellij.openapi.Disposable import com.intellij.openapi.actionSystem.CommonDataKeys import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.diff.impl.DiffUtil import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.event.CaretEvent import com.intellij.openapi.editor.event.CaretListener import com.intellij.openapi.editor.toolbar.floating.AbstractFloatingToolbarProvider import com.intellij.openapi.editor.toolbar.floating.FloatingToolbarComponent +import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.project.Project +import com.intellij.testFramework.LightVirtualFileBase import com.intellij.util.concurrency.AppExecutorUtil +import org.jetbrains.kotlin.idea.KotlinFileType class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_EDITOR_TOOLBAR_GROUP_ID) { override val autoHideable = false @@ -22,7 +26,9 @@ class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_E // todo: disable if not in Compose JVM module override fun register(dataContext: DataContext, component: FloatingToolbarComponent, parentDisposable: Disposable) { val editor = dataContext.getData(CommonDataKeys.EDITOR) ?: return - registerComponent(component, editor, parentDisposable) + if (isInsideMainKtEditor(editor)) { + registerComponent(component, editor, parentDisposable) + } } private fun registerComponent( @@ -50,11 +56,24 @@ internal class PreviewEditorToolbarVisibilityUpdater( } private fun updateVisibility() { - val parentPreviewFun = parentPreviewAtCaretOrNull(editor) - if (parentPreviewFun != null) { - toolbar.scheduleShow() - } else { - toolbar.scheduleHide() + if (!editor.isDisposed) { + val parentPreviewFun = parentPreviewAtCaretOrNull(editor) + if (parentPreviewFun != null) { + toolbar.scheduleShow() + } else { + toolbar.scheduleHide() + } } } +} + +private fun isInsideMainKtEditor(editor: Editor): Boolean = + !DiffUtil.isDiffEditor(editor) && editor.isKtFileEditor() + +private fun Editor.isKtFileEditor(): Boolean { + val documentManager = FileDocumentManager.getInstance() + val virtualFile = documentManager.getFile(document) ?: return false + return virtualFile !is LightVirtualFileBase + && virtualFile.isValid + && virtualFile.fileType == KotlinFileType.INSTANCE } \ No newline at end of file