Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ In order to change the keyboard bindings copy your modified version of the [defa
| Save as | Mod + Shift + S |
| Open File | Mod + O |
| Export as PDF | Mod + Alt + P |
| Toggle Theme (Dark / Light) | Mod + Alt + T |
| Cycle through themes | Mod + Alt + T |
| Undo | Mod + Z |
| Redo | Mod + Shift + Z |
| Insert line break | Mod + Enter / Shift + Enter |
Expand Down
2 changes: 1 addition & 1 deletion blank.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"file.save_as": "Mod-Shift-s",
"file.open": "Mod-o",
"export.pdf": "Mod-Alt-p",
"theme.toggle": "Mod-Alt-t"
"theme.cycle": "Mod-Alt-t"
}
}
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum CommandIdentifier {
FILE_SAVE_AS = "file.save_as",
FILE_OPEN = "file.open",
EXPORT_PDF = "export.pdf",
THEME_TOGGLE = "theme.toggle",
THEME_CYCLE = "theme.cycle",
}

export interface Config {
Expand Down Expand Up @@ -58,7 +58,7 @@ const defaultConfig: Config = {
[CommandIdentifier.FILE_SAVE_AS]: "Mod-Shift-s",
[CommandIdentifier.FILE_OPEN]: "Mod-o",
[CommandIdentifier.EXPORT_PDF]: "Mod-Alt-p",
[CommandIdentifier.THEME_TOGGLE]: "Mod-Alt-t",
[CommandIdentifier.THEME_CYCLE]: "Mod-Alt-t",
},
};

Expand Down
35 changes: 35 additions & 0 deletions src/editor/commands/cycleTheme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { afterEach, assert, beforeEach, describe, expect, it } from "vitest";
import { EditorState } from "prosemirror-state";

import { clearMocks, mockWindows } from "@tauri-apps/api/mocks";

import { cycleTheme } from ".";
import { theme, themes } from "../../state";

describe("command.cycleTheme", () => {
beforeEach(() => {
mockWindows("main");
theme.value = themes[0];
});

afterEach(() => {
clearMocks();
});

it("cycles", () => {
expect(window).toBeDefined();

const bodyTheme = () => document.body.dataset.theme;

themes.forEach((currentTheme, index) => {
assert.equal(theme.value, currentTheme);
assert.equal(bodyTheme(), currentTheme);

cycleTheme()(new EditorState());

const nextTheme = themes[(index + 1) % themes.length];
assert.equal(theme.value, nextTheme);
assert.equal(bodyTheme(), nextTheme);
});
});
});
10 changes: 10 additions & 0 deletions src/editor/commands/cycleTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Command } from "prosemirror-state";

import { theme, themes } from "../../state";

export default (): Command => () => {
const currentIndex = themes.indexOf(theme.value);
const nextIndex = (currentIndex + 1) % themes.length;
theme.value = themes[nextIndex];
return true;
};
2 changes: 1 addition & 1 deletion src/editor/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { default as insertNode } from "./insertNode";
export { default as newFile } from "./newFile";
export { default as openFile } from "./openFile";
export { default as saveFile } from "./saveFile";
export { default as toggleTheme } from "./toggleTheme";
export { default as cycleTheme } from "./cycleTheme";
35 changes: 0 additions & 35 deletions src/editor/commands/toggleTheme.test.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/editor/commands/toggleTheme.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/editor/plugins/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
openFile,
saveFile,
exportAs,
toggleTheme,
cycleTheme,
insertNode,
} from "../commands";

Expand Down Expand Up @@ -72,7 +72,7 @@ const commandMap: { [key in CommandIdentifier]: Command } = {
[CommandIdentifier.EXPORT_PDF]: exportAs("PDF-Export", exporters.toPDF, [
{ name: "PDF-File", extensions: ["pdf"] },
]),
[CommandIdentifier.THEME_TOGGLE]: toggleTheme(),
[CommandIdentifier.THEME_CYCLE]: cycleTheme(),
};

export const keymap = () =>
Expand Down
8 changes: 8 additions & 0 deletions src/scss/themes/_black.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[data-theme='black'] {
--color: #f4f4f2;
--background-color: #0a0a0f;
--color-inverted: #0a0a0f;
--background-inverted: #f4f4f2;
--font-family: 'DejaVu Sans', system-ui, -apple-system, 'Segoe UI', 'Roboto',
'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
}
8 changes: 8 additions & 0 deletions src/scss/themes/_blue.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[data-theme='blue'] {
--color: #fbc572;
--background-color: #25324c;
--color-inverted: #25324c;
--background-inverted: #fbc572;
--font-family: 'DejaVu Sans', system-ui, -apple-system, 'Segoe UI', 'Roboto',
'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
}
8 changes: 8 additions & 0 deletions src/scss/themes/_green.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[data-theme='green'] {
--color: #c6c7b3;
--background-color: #323f37;
--color-inverted: #323f37;
--background-inverted: #c6c7b3;
--font-family: 'DejaVu Sans', system-ui, -apple-system, 'Segoe UI', 'Roboto',
'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
}
4 changes: 4 additions & 0 deletions src/scss/themes/_index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@use 'light';
@use 'dark';
@use 'black';
@use 'red';
@use 'green';
@use 'blue';

body {
color: var(--color);
Expand Down
8 changes: 8 additions & 0 deletions src/scss/themes/_red.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[data-theme='red'] {
--color: #ede1c5;
--background-color: #532728;
--color-inverted: #daa9aa;
--background-inverted: #2f1414;
--font-family: 'DejaVu Sans', system-ui, -apple-system, 'Segoe UI', 'Roboto',
'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
}
13 changes: 11 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ transaction.subscribe(
}, 50),
);

export type themeType = "light" | "dark";
export const theme = new Observable<themeType>("dark");
export const themes: string[] = [
"light",
"dark",
"black",
"red",
"green",
"blue",
];

export type themeType = (typeof themes)[number];
export const theme = new Observable<themeType>("light");
theme.subscribe((value: themeType) => {
document.body.dataset.theme = value;
});
6 changes: 4 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Transaction } from "prosemirror-state";
import { Node } from "prosemirror-model";

import { debounce } from "observable.ts";
import { path, transaction, theme, themeType } from "./state";
import { path, transaction, theme, themeType, themes } from "./state";
import { schema } from "prosemirror-markdown";

localforage.config({
Expand All @@ -19,7 +19,9 @@ export const bootStorage = async () => {
});

const _theme = await localforage.getItem("theme");
theme.value = _theme === "dark" ? "dark" : "light";
theme.value = themes.includes(_theme as string)
? (_theme as themeType)
: themes[0];

theme.subscribe((value: themeType) => {
localforage.setItem("theme", value).catch(console.warn);
Expand Down