Skip to content

Commit

Permalink
Fix null pointer exception when closing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Jan 8, 2024
1 parent 5d4e9da commit e5cb2ab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,12 @@ private void renderText() throws InterruptedException {

String backend = (String) document.getAttribute("backend", "html5");

ConverterResult converterResult = asciidoctorjConverter.convert(document, textChangeEvent);
EditorPane editorPane = current.currentEditor();
if (Objects.isNull(editorPane)) {
return;
}

ConverterResult converterResult = asciidoctorjConverter.convert(document, editorPane, textChangeEvent);
this.lastConverterResult = converterResult;

if (Objects.nonNull(latestTextChangeEvent.get())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kodedu.engine;

import com.kodedu.component.EditorPane;
import com.kodedu.component.ViewPanel;
import com.kodedu.config.*;
import com.kodedu.controller.ApplicationController;
Expand Down Expand Up @@ -97,18 +98,18 @@ public String applyReplacements(String asciidoc) {
return null;
}

public ConverterResult convert(Document document, TextChangeEvent textChangeEvent) {
public ConverterResult convert(Document document, EditorPane editorPane, TextChangeEvent textChangeEvent) {
String backend = (String) document.getAttribute("backend", "html5");
Map<String, Object> attributes = document.getAttributes();
current.currentEditor().updateAttributes(attributes);
editorPane.updateAttributes(attributes);
return switch (backend) {
case "html5" -> convert(document, textChangeEvent, previewConfigBean);
case "revealjs" -> convert(document, textChangeEvent, revealjsConfigBean);
case "html5" -> convert(document, editorPane, textChangeEvent, previewConfigBean);
case "revealjs" -> convert(document, editorPane, textChangeEvent, revealjsConfigBean);
default -> throw new RuntimeException("Backend not found: " + backend);
};
}

private ConverterResult convert(Document document, TextChangeEvent textChangeEvent, AsciidoctorConfigBase<?> configBean) {
private ConverterResult convert(Document document, EditorPane editorPane, TextChangeEvent textChangeEvent, AsciidoctorConfigBase<?> configBean) {
SafeMode safe = convertSafe(configBean.getSafe());
String backend = (String) document.getAttribute("backend", "html5");
Attributes attributes = configBean.getAsciiDocAttributes(document.getAttributes());
Expand Down Expand Up @@ -139,7 +140,7 @@ private ConverterResult convert(Document document, TextChangeEvent textChangeEve
String content = textChangeEvent.getText();
String converted = asciidoctor.convert(content, options) ;
Document finalDocument = (Document) DOCUMENT_MAP.get(docUUID);
current.currentEditor().setLastDocument(finalDocument);
editorPane.setLastDocument(finalDocument);
DOCUMENT_MAP.remove(docUUID);
logger.info("Converted Asciidoc to {}", backend.toUpperCase());

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/kodedu/other/Current.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public WebView currentWebView() {
}

public EditorPane currentEditor() {
return currentTab().getEditorPane();
MyTab currentTab = currentTab();
if (Objects.isNull(currentTab)) {
return null;
}
return currentTab.getEditorPane();
}

public WebEngine currentEngine() {
Expand Down

0 comments on commit e5cb2ab

Please sign in to comment.