From 362c61a38b31ec2de51ce7a8cf53cca8acacdc8c Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Thu, 21 Apr 2022 19:35:26 +0300 Subject: [PATCH] Avoid interfering with Intellij Light Edit mode (#2027) Resolves #1816 --- .../desktop/ide/preview/PreviewFloatingToolbarProvider.kt | 8 +++++--- .../compose/desktop/ide/preview/PreviewToolWindow.kt | 6 ++---- .../compose/desktop/ide/preview/ijCompatibilityUtils.kt | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) 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 f029ea8a68..91ae5afca9 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 @@ -45,9 +45,11 @@ class PreviewFloatingToolbarProvider : AbstractFloatingToolbarProvider(PREVIEW_E editor: Editor, parentDisposable: Disposable ) { - val project = editor.project ?: return - val listener = PreviewEditorToolbarVisibilityUpdater(component, project, editor) - editor.caretModel.addCaretListener(listener, parentDisposable) + val project = editor.project + if (project != null && isPreviewCompatible(project)) { + val listener = PreviewEditorToolbarVisibilityUpdater(component, project, editor) + editor.caretModel.addCaretListener(listener, parentDisposable) + } } } diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt index b5f6beb5fc..dc1546e0d6 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/PreviewToolWindow.kt @@ -14,10 +14,8 @@ import org.jetbrains.compose.desktop.ide.preview.ui.PreviewPanel import java.awt.BorderLayout class PreviewToolWindow : ToolWindowFactory, DumbAware { - override fun isApplicable(project: Project): Boolean { - // todo: filter only Compose projects - return true - } + override fun isApplicable(project: Project): Boolean = + isPreviewCompatible(project) override fun init(toolWindow: ToolWindow) { toolWindow.setIcon(PreviewIcons.COMPOSE) diff --git a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt index 2f52a60774..a5925bdc53 100644 --- a/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt +++ b/idea-plugin/src/main/kotlin/org/jetbrains/compose/desktop/ide/preview/ijCompatibilityUtils.kt @@ -5,10 +5,16 @@ package org.jetbrains.compose.desktop.ide.preview +import com.intellij.ide.lightEdit.LightEdit import com.intellij.openapi.externalSystem.model.Key import com.intellij.openapi.externalSystem.model.project.AbstractNamedData +import com.intellij.openapi.project.Project import java.lang.reflect.Modifier +// todo: filter only Compose projects +internal fun isPreviewCompatible(project: Project): Boolean = + !LightEdit.owns(project) + internal val kotlinTargetDataKey: Key = run { val kotlinTargetDataClass = try { Class.forName("org.jetbrains.kotlin.idea.gradle.configuration.KotlinTargetData")