This commit is contained in:
nickofolas 2022-04-13 14:42:07 -05:00
parent 1f9414fd0e
commit 567fcf8fb6
4 changed files with 79 additions and 68 deletions

@ -9,8 +9,8 @@ import Select from "@mui/material/Select";
import Switch from "@mui/material/Switch";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
import EditIcon from '@mui/icons-material/Edit';
import SaveIcon from '@mui/icons-material/Save';
import EditIcon from "@mui/icons-material/Edit";
import SaveIcon from "@mui/icons-material/Save";
import { ThemeEditorModal } from "./ThemeEditorModal";
@ -48,10 +48,7 @@ export function OptionsModal(props: IProps): React.ReactElement {
return (
<Modal open={props.open} onClose={props.onClose}>
<ThemeEditorModal
open={themeEditorOpen}
onClose={() => setThemeEditorOpen(false)}
/>
<ThemeEditorModal open={themeEditorOpen} onClose={() => setThemeEditorOpen(false)} />
<Box display="flex" flexDirection="row" alignItems="center">
<Typography>Theme: </Typography>
<Select onChange={(event) => setTheme(event.target.value)} value={theme}>
@ -93,7 +90,9 @@ export function OptionsModal(props: IProps): React.ReactElement {
<TextField type="number" label="Font size" value={fontSize} onChange={onFontChange} />
</Box>
<br />
<Button onClick={save} startIcon={<SaveIcon />}>Save</Button>
<Button onClick={save} startIcon={<SaveIcon />}>
Save
</Button>
</Modal>
);
}

@ -10,8 +10,8 @@ import TextField from "@mui/material/TextField";
import Paper from "@mui/material/Paper";
import IconButton from "@mui/material/IconButton";
import ReplyIcon from "@mui/icons-material/Reply";
import HistoryIcon from '@mui/icons-material/History';
import SaveIcon from '@mui/icons-material/Save';
import HistoryIcon from "@mui/icons-material/History";
import SaveIcon from "@mui/icons-material/Save";
import { Settings } from "../../Settings/Settings";
import { OptionSwitch } from "../../ui/React/OptionSwitch";
@ -99,10 +99,13 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
}
return (
<Modal open={props.open} onClose={() => {
setThemeCopy(Settings.EditorTheme);
props.onClose();
}}>
<Modal
open={props.open}
onClose={() => {
setThemeCopy(Settings.EditorTheme);
props.onClose();
}}
>
<Typography variant="h4">Customize Editor theme</Typography>
<Typography>Hover over input boxes for more information</Typography>
<Paper sx={{ p: 1, my: 1 }}>
@ -115,8 +118,8 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
text="Use light theme as base"
tooltip={
<>
If enabled, the <code>vs</code> light theme will be used as the
theme base, otherwise, <code>vs-dark</code> will be used.
If enabled, the <code>vs</code> light theme will be used as the theme base, otherwise,{" "}
<code>vs-dark</code> will be used.
</>
}
/>
@ -258,19 +261,26 @@ export function ThemeEditorModal(props: IProps): React.ReactElement {
onChange={onThemeChange}
/>
<Box sx={{ mt: 1 }}>
<Button onClick={() => {
Settings.EditorTheme = { ...themeCopy };
props.onClose()
}} startIcon={<SaveIcon />}>Save</Button>
<Button
onClick={() => {
Settings.EditorTheme = { ...themeCopy };
props.onClose();
}}
startIcon={<SaveIcon />}
>
Save
</Button>
<Button
onClick={() => {
setThemeCopy(defaultMonacoTheme);
rerender();
}}
startIcon={<HistoryIcon />}
>Reset to default</Button>
>
Reset to default
</Button>
</Box>
</Paper>
</Modal>
)
);
}

@ -53,20 +53,20 @@ export const defaultMonacoTheme: IScriptEditorTheme = {
keyword: "569CD6",
comment: "6A9955",
constant: "569CD6",
error: "F44747"
error: "F44747",
},
ui: {
line: "1E1E1E",
panel: {
bg: "252526",
selected: "252526",
border: "1E1E1E"
border: "1E1E1E",
},
selection: {
bg: "ADD6FF26"
}
}
}
bg: "ADD6FF26",
},
},
};
// Regex used for token color validation
// https://github.com/microsoft/vscode/blob/973684056e67153952f495fce93bf50d0ec0b892/src/vs/editor/common/languages/supports/tokenization.ts#L153
@ -93,122 +93,124 @@ export const sanitizeTheme = (theme: IScriptEditorTheme): void => {
if (!v.match(colorRegExp)) block[k] = "FF0000";
}
}
}
};
repairBlock(v);
}
}
};
export function makeTheme(theme: IScriptEditorTheme): any {
const themeRules = [
{
token: "",
background: theme.ui.line,
foreground: theme.common.fg
foreground: theme.common.fg,
},
{
token: "identifier",
foreground: theme.common.accent
foreground: theme.common.accent,
},
{
token: "keyword",
foreground: theme.syntax.keyword
foreground: theme.syntax.keyword,
},
{
token: "string",
foreground: theme.syntax.string
foreground: theme.syntax.string,
},
{
token: "string.escape",
foreground: theme.syntax.regexp
foreground: theme.syntax.regexp,
},
{
token: "comment",
foreground: theme.syntax.comment
foreground: theme.syntax.comment,
},
{
token: "constant",
foreground: theme.syntax.constant
foreground: theme.syntax.constant,
},
{
token: "entity",
foreground: theme.syntax.entity
foreground: theme.syntax.entity,
},
{
token: "type",
foreground: theme.syntax.tag
foreground: theme.syntax.tag,
},
{
token: "tag",
foreground: theme.syntax.tag
foreground: theme.syntax.tag,
},
{
token: "regexp",
foreground: theme.syntax.regexp
foreground: theme.syntax.regexp,
},
{
token: "attribute",
foreground: theme.syntax.tag
foreground: theme.syntax.tag,
},
{
token: "constructor",
foreground: theme.syntax.markup
foreground: theme.syntax.markup,
},
{
token: "invalid",
foreground: theme.syntax.error
foreground: theme.syntax.error,
},
{
token: "number",
foreground: theme.common.accent
foreground: theme.common.accent,
},
{
token: "delimiter",
foreground: theme.common.fg
foreground: theme.common.fg,
},
// Custom tokens
{
token: "ns",
foreground: theme.syntax.tag
foreground: theme.syntax.tag,
},
{
token: "netscriptfunction",
foreground: theme.syntax.markup
foreground: theme.syntax.markup,
},
{
token: "otherkeywords",
foreground: theme.syntax.keyword
foreground: theme.syntax.keyword,
},
{
token: "otherkeyvars",
foreground: theme.common.accent
foreground: theme.common.accent,
},
{
token: "this",
foreground: theme.syntax.tag
}
foreground: theme.syntax.tag,
},
];
const themeColors = Object.fromEntries([
["editor.background", theme.common.bg],
["editor.foreground", theme.common.fg],
["editor.lineHighlightBackground", theme.ui.line],
["editor.selectionBackground", theme.ui.selection.bg],
const themeColors = Object.fromEntries(
[
["editor.background", theme.common.bg],
["editor.foreground", theme.common.fg],
["editor.lineHighlightBackground", theme.ui.line],
["editor.selectionBackground", theme.ui.selection.bg],
["editorSuggestWidget.background", theme.ui.panel.bg],
["editorSuggestWidget.border", theme.ui.panel.border],
["editorSuggestWidget.selectedBackground", theme.ui.panel.selected],
["editorSuggestWidget.background", theme.ui.panel.bg],
["editorSuggestWidget.border", theme.ui.panel.border],
["editorSuggestWidget.selectedBackground", theme.ui.panel.selected],
["editorHoverWidget.background", theme.ui.panel.bg],
["editorHoverWidget.border", theme.ui.panel.border],
["editorHoverWidget.background", theme.ui.panel.bg],
["editorHoverWidget.border", theme.ui.panel.border],
["editorWidget.background", theme.ui.panel.bg],
["editorWidget.border", theme.ui.panel.border],
["editorWidget.background", theme.ui.panel.bg],
["editorWidget.border", theme.ui.panel.border],
["input.background", theme.ui.panel.bg],
["input.border", theme.ui.panel.border]
].map(([k, v]) => [k, "#" + v]));
["input.background", theme.ui.panel.bg],
["input.border", theme.ui.panel.border],
].map(([k, v]) => [k, "#" + v]),
);
return { base: theme.base, inherit: theme.inherit, rules: themeRules, colors: themeColors }
return { base: theme.base, inherit: theme.inherit, rules: themeRules, colors: themeColors };
}
export async function loadThemes(monaco: { editor: any }): Promise<void> {

@ -266,7 +266,7 @@ export const Settings: ISettings & ISelfInitializer & ISelfLoading = {
MonacoFontSize: 20,
MonacoVim: false,
MonacoWordWrap: "off",
theme: { ...defaultTheme },
styles: { ...defaultStyles },
overview: defaultSettings.overview,