Skip to content

Commit c1dac1d

Browse files
authored
feat: Add themes and allow cycling thru them (#11)
1 parent 6a3640e commit c1dac1d

16 files changed

Lines changed: 103 additions & 54 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ In order to change the keyboard bindings copy your modified version of the [defa
7777
| Save as | Mod + Shift + S |
7878
| Open File | Mod + O |
7979
| Export as PDF | Mod + Alt + P |
80-
| Toggle Theme (Dark / Light) | Mod + Alt + T |
80+
| Cycle through themes | Mod + Alt + T |
8181
| Undo | Mod + Z |
8282
| Redo | Mod + Shift + Z |
8383
| Insert line break | Mod + Enter / Shift + Enter |

blank.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
"file.save_as": "Mod-Shift-s",
2424
"file.open": "Mod-o",
2525
"export.pdf": "Mod-Alt-p",
26-
"theme.toggle": "Mod-Alt-t"
26+
"theme.cycle": "Mod-Alt-t"
2727
}
2828
}

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export enum CommandIdentifier {
2626
FILE_SAVE_AS = "file.save_as",
2727
FILE_OPEN = "file.open",
2828
EXPORT_PDF = "export.pdf",
29-
THEME_TOGGLE = "theme.toggle",
29+
THEME_CYCLE = "theme.cycle",
3030
}
3131

3232
export interface Config {
@@ -58,7 +58,7 @@ const defaultConfig: Config = {
5858
[CommandIdentifier.FILE_SAVE_AS]: "Mod-Shift-s",
5959
[CommandIdentifier.FILE_OPEN]: "Mod-o",
6060
[CommandIdentifier.EXPORT_PDF]: "Mod-Alt-p",
61-
[CommandIdentifier.THEME_TOGGLE]: "Mod-Alt-t",
61+
[CommandIdentifier.THEME_CYCLE]: "Mod-Alt-t",
6262
},
6363
};
6464

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { afterEach, assert, beforeEach, describe, expect, it } from "vitest";
2+
import { EditorState } from "prosemirror-state";
3+
4+
import { clearMocks, mockWindows } from "@tauri-apps/api/mocks";
5+
6+
import { cycleTheme } from ".";
7+
import { theme, themes } from "../../state";
8+
9+
describe("command.cycleTheme", () => {
10+
beforeEach(() => {
11+
mockWindows("main");
12+
theme.value = themes[0];
13+
});
14+
15+
afterEach(() => {
16+
clearMocks();
17+
});
18+
19+
it("cycles", () => {
20+
expect(window).toBeDefined();
21+
22+
const bodyTheme = () => document.body.dataset.theme;
23+
24+
themes.forEach((currentTheme, index) => {
25+
assert.equal(theme.value, currentTheme);
26+
assert.equal(bodyTheme(), currentTheme);
27+
28+
cycleTheme()(new EditorState());
29+
30+
const nextTheme = themes[(index + 1) % themes.length];
31+
assert.equal(theme.value, nextTheme);
32+
assert.equal(bodyTheme(), nextTheme);
33+
});
34+
});
35+
});

src/editor/commands/cycleTheme.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Command } from "prosemirror-state";
2+
3+
import { theme, themes } from "../../state";
4+
5+
export default (): Command => () => {
6+
const currentIndex = themes.indexOf(theme.value);
7+
const nextIndex = (currentIndex + 1) % themes.length;
8+
theme.value = themes[nextIndex];
9+
return true;
10+
};

src/editor/commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ export { default as insertNode } from "./insertNode";
33
export { default as newFile } from "./newFile";
44
export { default as openFile } from "./openFile";
55
export { default as saveFile } from "./saveFile";
6-
export { default as toggleTheme } from "./toggleTheme";
6+
export { default as cycleTheme } from "./cycleTheme";

src/editor/commands/toggleTheme.test.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/editor/commands/toggleTheme.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/editor/plugins/keymap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
openFile,
2121
saveFile,
2222
exportAs,
23-
toggleTheme,
23+
cycleTheme,
2424
insertNode,
2525
} from "../commands";
2626

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

7878
export const keymap = () =>

src/scss/themes/_black.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[data-theme='black'] {
2+
--color: #f4f4f2;
3+
--background-color: #0a0a0f;
4+
--color-inverted: #0a0a0f;
5+
--background-inverted: #f4f4f2;
6+
--font-family: 'DejaVu Sans', system-ui, -apple-system, 'Segoe UI', 'Roboto',
7+
'Ubuntu', 'Cantarell', 'Noto Sans', sans-serif;
8+
}

0 commit comments

Comments
 (0)