Skip to content

Commit fa3e441

Browse files
committed
Change default theme from vs-dark-plus to vs-dark-modern. Add vs-light-modern and add actions to switch. Automatically add themes from $Appdata/themes.
1 parent bb36ca0 commit fa3e441

File tree

9 files changed

+1556
-222
lines changed

9 files changed

+1556
-222
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@ It is technically a continuation of [VSCode Git Diff Stepper](https://github.com
1212
- `cmd / ctrl` + `alt / option` + `left` or `right` arrow keys move through iterations.
1313
- `f1` to launch the command palette.
1414

15-
## Language Support
15+
## Custom Language Support
1616

17+
We have support for textmate `.tmLanguage` files!
1718

19+
- Drop a `.tmLanguage` file into `$AppData/de.ivorius.gitdiffstepper/tmlanguages`.
20+
- The file name should be equivalent to the file ending (e.g. `css.tmLanguage` for `.css` files).
21+
- Relaunch the App.
1822

19-
We have support for textmate `.tmLanguage` files! Drop a `.tmLanguage` file into `$AppData/de.ivorius.gitdiffstepper/tmlanguages` and relaunch the app. The file name should be equivalent to the file ending (e.g. `css.tmLanguage` for `.css` files).
23+
To switch the language manually, use the command palette.
2024

21-
To switch to the language manually, use the command palette.
25+
## Custom Theme Support
26+
27+
We have support for vscode themes!
28+
- In VSCode, run the command "Developer: Generate Color Theme From Current Settings".
29+
- Convert the resulting `.jsonc` file to regular `.json` (removing comments and trailing commas).
30+
- Drop the file into `$AppData/de.ivorius.gitdiffstepper/themes`.
31+
- Relaunch the App.
32+
33+
To switch the theme, use the command palette.
2234

2335
## Dev Setup
2436

src-tauri/tauri.conf.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
"scope": [
2828
"$APPDATA/*",
2929
"$APPDATA/tmlanguages/*",
30+
"$APPDATA/themes/*",
3031
"$RESOURCE/onigasm.wasm",
31-
"$RESOURCE/themes/*"
32+
"$RESOURCE/themes/*",
33+
"$RESOURCE/themes/"
3234
]
3335
},
3436
"dialog": {

src-tauri/themes/vs-dark-plus.json renamed to src-tauri/themes/vs-dark-modern.json

Lines changed: 228 additions & 203 deletions
Large diffs are not rendered by default.

src-tauri/themes/vs-light-modern.json

Lines changed: 1259 additions & 0 deletions
Large diffs are not rendered by default.

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as TextMate from "./monaco/TextMate";
66
import * as Themes from "./monaco/Themes";
77

88
await TextMate.setup();
9-
await Themes.load();
9+
export const customThemes = await Themes.load();
1010

1111
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
1212
root.render(

src/monaco/TextMate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function setup() {
1616

1717
for (const entry of entries) {
1818
if (!entry.name?.endsWith(".tmLanguage")) {
19-
console.log(`Did not read file: ${entry.name}`)
19+
console.log(`Did not read tmlanguage file (unknown suffix): ${entry.name}`)
2020
continue;
2121
}
2222

src/monaco/Themes.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseDirectory, readTextFile } from '@tauri-apps/api/fs';
1+
import { BaseDirectory, createDir, readDir, readTextFile } from '@tauri-apps/api/fs';
22
import * as monaco from 'monaco-editor';
33

44
export interface IVSCodeTheme {
@@ -65,9 +65,44 @@ export function convert(theme: IVSCodeTheme): monaco.editor.IStandaloneThemeData
6565
return returnTheme;
6666
}
6767

68-
export async function load() {
69-
const vs_dark_plus = await readTextFile("themes/vs-dark-plus.json", { dir: BaseDirectory.Resource });
70-
const parsed: IVSCodeTheme = JSON.parse(vs_dark_plus);
71-
const converted = convert(parsed);
72-
monaco.editor.defineTheme('vs-dark-plus', converted);
68+
export async function load(): Promise<string[]> {
69+
await createDir("themes", { dir: BaseDirectory.AppData, recursive: true });
70+
var entries = await readDir("themes", { dir: BaseDirectory.AppData });
71+
entries.push(...await readDir("themes", { dir: BaseDirectory.Resource }));
72+
73+
let addedThemes: string[] = [];
74+
for (const entry of entries) {
75+
if (!entry.name?.endsWith(".json")) {
76+
console.log(`Did not read theme (unknown suffix): ${entry.name}`)
77+
continue;
78+
}
79+
80+
const text = await readTextFile(entry.path);
81+
const parsed: IVSCodeTheme = JSON.parse(text);
82+
const converted = convert(parsed);
83+
84+
const themeID = entry.name.substring(0, entry.name.length - 5);
85+
monaco.editor.defineTheme(themeID, converted);
86+
addedThemes.push(themeID);
87+
}
88+
89+
return addedThemes;
90+
}
91+
92+
export function addSetThemeActions(editor: monaco.editor.IStandaloneCodeEditor, themes: string[], callback?: () => void) {
93+
for (let themeID of themes) {
94+
editor.addAction({
95+
id: `setTheme-${themeID}`,
96+
label: `Set theme to ${themeID}`,
97+
run: (editor: monaco.editor.ICodeEditor, arg: string) => {
98+
monaco.editor.setTheme(themeID);
99+
callback?.();
100+
}
101+
});
102+
}
103+
}
104+
105+
export function getBackgroundColor(editor: monaco.editor.IStandaloneCodeEditor): string {
106+
return getComputedStyle(editor.getDomNode()!)
107+
.getPropertyValue('--vscode-editor-background')
73108
}

src/view/App.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
body {
2-
background-color: #1e1e1e;
3-
}
4-
51
#root > * {
62
justify-content: center;
73
padding: 15px;
@@ -12,7 +8,7 @@ body {
128
max-width: 1024px;
139
}
1410

15-
.editor{
11+
.editor {
1612
height: 100%;
1713
}
1814

src/view/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { useEffect } from 'react';
1010
import Editor from "@monaco-editor/react";
1111
import { TextZone } from '../monaco/ViewZones';
1212
import { addSetLanguageActions } from '../monaco/SetLanguage';
13+
import { addSetThemeActions, getBackgroundColor } from '../monaco/Themes';
14+
import { customThemes } from '../main';
1315

1416
loader.config({ monaco });
1517

@@ -37,7 +39,7 @@ function createPatchEditor(language: string, textZone: TextZone) {
3739

3840
const secondEditor = <Editor
3941
onMount={handleEditorDidMount}
40-
theme="vs-dark-plus"
42+
theme="vs-dark-modern"
4143

4244
// language / value inputs are tracked, "default" versions are only for the initial value
4345
defaultLanguage={language}
@@ -91,17 +93,20 @@ function App() {
9193
});
9294

9395
async function handleEditorDidMount(editor: monaco.editor.IStandaloneCodeEditor, monaco: any) {
96+
document.body.style.backgroundColor = getBackgroundColor(editor);
97+
9498
let logController_ = new MonacoLogController(editor, createPatchEditor);
9599
logController = logController_;
96100

97101
addSetLanguageActions(editor);
102+
addSetThemeActions(editor, customThemes, () => document.body.style.backgroundColor = getBackgroundColor(editor));
98103
}
99104

100105
return <Editor
101106
height="calc(100vh - 30px)" // TODO This shouldn't be here but otherwise the size is 5px
102107
width="calc(100vw - 30px)"
103108
onMount={handleEditorDidMount}
104-
theme="vs-dark-plus"
109+
theme="vs-dark-modern"
105110
options={{
106111
minimap: { enabled: false },
107112
renderLineHighlight: "none",

0 commit comments

Comments
 (0)