Skip to content

Commit

Permalink
fix: NPE: null cannot be cast to non-null type com.intellij.openapi.f…
Browse files Browse the repository at this point in the history
…ileEditor.TextEditorWithPreview

Closes #39
  • Loading branch information
develar committed Mar 10, 2024
1 parent 42a23ff commit d32ed08
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Bug Fixes

- NPE: null cannot be cast to non-null type com.intellij.openapi.fileEditor.TextEditorWithPreview ([GH-39](https://github.com/develar/d2-intellij-plugin/issues/39))

### Features

- Add block comment support (#22)
- Support block strings as shape ids (#23)
- Support line continuations in shape ids, arrows, and values (#24)
- Support line continuations in declarations and fix shape declarations (#30)

## [1.3.0] - 2024-01-08

### Added
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pluginName=D2
pluginRepositoryUrl=https://github.com/develar/d2-intellij-plugin

pluginVersion=1.3.0
pluginVersion=1.4.0
pluginSinceBuild=232
pluginUntilBuild=241.*
pluginUntilBuild=242.*

platformType=IC
platformVersion=232.8660.185
Expand Down
6 changes: 3 additions & 3 deletions src/src/action/D2ExportActions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private class D2ExportAction : AnAction(), DumbAware {
project
).save((e.getData(PlatformDataKeys.VIRTUAL_FILE) as VirtualFile).parent, defaultFileName) ?: return

val viewer = e.d2FileEditor
val viewer = e.d2FileEditor!!
val targetFile = fileWrapper.file.toPath()
convert(targetFile = targetFile, viewer = viewer)
}
Expand Down Expand Up @@ -163,12 +163,12 @@ internal fun notify(project: Project?, @NlsContexts.NotificationContent content:

private class D2LiveBrowserAction : AnAction(), DumbAware {
override fun actionPerformed(e: AnActionEvent) {
val port = e.d2FileEditor.renderManager.state?.port ?: error("port not found")
val port = e.d2FileEditor!!.renderManager.state?.port ?: error("port not found")
BrowserUtil.browse("http://localhost:$port", e.project)
}

override fun update(e: AnActionEvent) {
e.presentation.isEnabled = e.d2FileEditor.renderManager.state?.process != null
e.presentation.isEnabled = e.d2FileEditor?.renderManager?.state?.process != null
}

override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand Down
4 changes: 2 additions & 2 deletions src/src/action/D2LayoutEngineChooser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ private class D2LayoutEngineAction(private val layout: D2Layout) : ToggleAction(
},
null
), DumbAware {
override fun isSelected(e: AnActionEvent): Boolean = (e.d2FileEditor.layout ?: D2Layout.DEFAULT) == layout
override fun isSelected(e: AnActionEvent): Boolean = (e.d2FileEditor?.layout ?: D2Layout.DEFAULT) == layout

override fun setSelected(e: AnActionEvent, state: Boolean) {
e.d2FileEditor.layout = layout
e.d2FileEditor?.layout = layout
}

override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand Down
4 changes: 2 additions & 2 deletions src/src/action/exts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import org.jetbrains.plugins.d2.file.D2FileType
internal val VirtualFile.isD2: Boolean
get() = fileType == D2FileType

internal val AnActionEvent.d2FileEditor: D2Viewer
get() = (getData(PlatformDataKeys.FILE_EDITOR) as TextEditorWithPreview).previewEditor as D2Viewer
internal val AnActionEvent.d2FileEditor: D2Viewer?
get() = (getData(PlatformDataKeys.FILE_EDITOR) as TextEditorWithPreview?)?.previewEditor as D2Viewer?
2 changes: 1 addition & 1 deletion src/src/editor/D2MessagesAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private class D2MessagesAction : AnAction(), DumbAware {
val console = content.component.getComponent(0) as ConsoleViewImpl
console.clear()
messageView.contentManager.setSelectedContent(content)
val state = e.d2FileEditor.renderManager.state ?: return
val state = e.d2FileEditor?.renderManager?.state ?: return
console.print(state.log.toString(), ConsoleViewContentType.LOG_INFO_OUTPUT)

val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW)
Expand Down
4 changes: 2 additions & 2 deletions src/src/editor/D2ThemeChooser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ private class D2ThemeAction(private val theme: D2Theme) : ToggleAction(theme.nam
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT

override fun isSelected(e: AnActionEvent): Boolean {
return (e.d2FileEditor.theme ?: D2Theme.DEFAULT) == theme
return (e.d2FileEditor!!.theme ?: D2Theme.DEFAULT) == theme
}

override fun setSelected(e: AnActionEvent, state: Boolean) {
e.d2FileEditor.theme = theme
e.d2FileEditor!!.theme = theme
}
}

Expand Down

0 comments on commit d32ed08

Please sign in to comment.