Skip to content

Commit

Permalink
fix: fix internal api issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 5, 2023
1 parent 02451a5 commit 16449c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.editor.Inlay
import com.intellij.openapi.editor.InlayProperties
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.observable.util.whenDisposed
import java.awt.*
import java.awt.event.ComponentAdapter
import java.awt.event.ComponentEvent
Expand All @@ -17,6 +16,7 @@ import javax.swing.JComponent
import javax.swing.JScrollPane
import kotlin.math.max
import kotlin.math.min
import cc.unitmesh.devti.gui.block.whenDisposed

class InlayComponent<T : JComponent?> private constructor(@JvmField var component: T) : JComponent(),
EditorCustomElementRenderer {
Expand Down Expand Up @@ -71,6 +71,7 @@ class InlayComponent<T : JComponent?> private constructor(@JvmField var componen

val viewport = scrollPane.viewport
viewport.addComponentListener(componentListener)

addBlockElement.whenDisposed {
editor.getContentComponent().remove(inlayComponent)
viewport.removeComponentListener(componentListener)
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/cc/unitmesh/devti/gui/block/CodeBlockView.kt
Expand Up @@ -25,6 +25,7 @@ import com.intellij.openapi.fileTypes.PlainTextFileType
import com.intellij.openapi.fileTypes.UnknownFileType
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.observable.util.whenDisposed
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.VirtualFile
Expand Down Expand Up @@ -241,6 +242,10 @@ fun VirtualFile.findDocument(): Document? {
}
}

fun Disposable.whenDisposed(listener: () -> Unit) {
Disposer.register(this) { listener() }
}

fun Disposable.whenDisposed(
parentDisposable: Disposable,
listener: () -> Unit
Expand Down

0 comments on commit 16449c2

Please sign in to comment.