Skip to content

Commit

Permalink
fix: fix dispose issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 1, 2023
1 parent 02f905b commit e03ebc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
16 changes: 6 additions & 10 deletions src/main/kotlin/cc/unitmesh/devti/gui/block/CodeBlockView.kt
Expand Up @@ -103,6 +103,10 @@ class CodeBlockView(private val block: CodeBlock, private val project: Project,
disposable: Disposable
): EditorEx {
val editor: Editor = EditorFactory.getInstance().createViewer(document, project, EditorKind.PREVIEW)
disposable.whenDisposed(disposable) {
EditorFactory.getInstance().releaseEditor(editor)
}

(editor as EditorEx).setFile(file)
editor.setCaretEnabled(true)
val highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, file)
Expand All @@ -129,11 +133,11 @@ class CodeBlockView(private val block: CodeBlock, private val project: Project,

editor.addFocusListener(object : FocusChangeListener {
override fun focusGained(focusEditor: Editor) {
editor.getSettings().isCaretRowShown = true
settings.isCaretRowShown = true
}

override fun focusLost(focusEditor: Editor) {
editor.getSettings().isCaretRowShown = false
settings.isCaretRowShown = false
editor.markupModel.removeAllHighlighters()
}
})
Expand All @@ -158,10 +162,6 @@ class CodeBlockView(private val block: CodeBlock, private val project: Project,
val editor: EditorEx =
createCodeViewerEditor(project, createCodeViewerFile as LightVirtualFile, document, disposable)

disposable.whenDisposed {
EditorFactory.getInstance().releaseEditor(editor)
}

val toolbarActionGroup = ActionUtil.getActionGroup("AutoDev.ToolWindow.Snippet.Toolbar")
toolbarActionGroup?.let {
val jComponent: ActionToolbarImpl =
Expand Down Expand Up @@ -201,10 +201,6 @@ fun VirtualFile.findDocument(): Document? {
return ref.element
}

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

fun Disposable.whenDisposed(
parentDisposable: Disposable,
listener: () -> Unit
Expand Down
Expand Up @@ -9,17 +9,14 @@ import com.intellij.psi.PsiFile

class CodeBlockHighlightingFilter : HighlightInfoFilter {
override fun accept(highlightInfo: HighlightInfo, file: PsiFile?): Boolean {
val hasError = highlightInfo.getSeverity().compareTo(HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING) >= 0;
val hasError = highlightInfo.severity >= HighlightSeverity.GENERIC_SERVER_ERROR_OR_WARNING;

if (file == null || !hasError) {
return true;
}

val virtualFile = file.getVirtualFile();
if (virtualFile != null && AutoDevSnippetFile.isSnippet(virtualFile)) {
return false;
}
val virtualFile = file.virtualFile;

return true;
return !(virtualFile != null && AutoDevSnippetFile.isSnippet(virtualFile));
}
}

0 comments on commit e03ebc7

Please sign in to comment.