Skip to content

Commit

Permalink
fix npe on setting theme
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillp committed Apr 24, 2024
1 parent 6da0396 commit 5be61c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo-edit-es-module/module/samples/loadFromCDN.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cdn = "https://cdn.jsdelivr.net/npm/[email protected]beta12"
const cdn = "https://cdn.jsdelivr.net/npm/[email protected]beta17"
const editorJs = "/src/editor.js";
const workerJS = "/src/worker.js"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void setFontSize(float fontSize) {

@Override
public void setTheme(JSString theme) {
ThemeControl themeControl = folderDiff.themeControl();
themeControl.setTheme(theme.stringValue());
folderDiff.setTheme(theme.stringValue());
}

public static Promise<JsFolderDiff> newDiff(EditArgs arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ public String[] menuFonts() {
return Fonts.editorFonts(false);
}

public ThemeControl themeControl() { return w; }
public void setTheme(String t) {
EditorColorScheme tm = ThemeControl.resolveTheme(t);
if (tm != null) {
theme = tm;
if (w != null) w.applyTheme(tm);
}
}

@Override
public void onResize(V2i newSize, float newDpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ public interface ThemeControl {
void applyTheme(EditorColorScheme theme);

default void setTheme(String theme) {
switch (theme) {
case "light" -> toggleLight();
case "darcula" -> toggleDarcula();
case "dark" -> toggleDark();
default -> Debug.consoleInfo("unknown theme: " + theme);
var t = resolveTheme(theme);
if (t != null) {
applyTheme(t);
} else {
Debug.consoleInfo("unknown theme: " + theme);
}
}

static EditorColorScheme resolveTheme(String name) {
return switch (name) {
case "light" -> EditorColorScheme.lightIdeaColorScheme();
case "darcula" -> EditorColorScheme.darculaIdeaColorScheme();
case "dark" -> EditorColorScheme.darkIdeaColorScheme();
default -> null;
};
}

default void toggleDarcula() {
applyTheme(EditorColorScheme.darculaIdeaColorScheme());
}
Expand Down

0 comments on commit 5be61c1

Please sign in to comment.