Added font size to text editor

This commit is contained in:
Olivier Gagnon
2021-10-04 21:06:55 -04:00
parent c47a5bc8cc
commit 48b839d68c
11 changed files with 372 additions and 306 deletions
+1
View File
@@ -1,4 +1,5 @@
export interface Options {
theme: string;
insertSpaces: boolean;
fontSize: number;
}
+12
View File
@@ -8,6 +8,7 @@ import Typography from "@mui/material/Typography";
import Select from "@mui/material/Select";
import Switch from "@mui/material/Switch";
import MenuItem from "@mui/material/MenuItem";
import TextField from "@mui/material/TextField";
interface IProps {
options: Options;
@@ -19,15 +20,23 @@ interface IProps {
export function OptionsModal(props: IProps): React.ReactElement {
const [theme, setTheme] = useState(props.options.theme);
const [insertSpaces, setInsertSpaces] = useState(props.options.insertSpaces);
const [fontSize, setFontSize] = useState(props.options.fontSize);
function save(): void {
props.save({
theme: theme,
insertSpaces: insertSpaces,
fontSize: fontSize,
});
props.onClose();
}
function onFontChange(event: React.ChangeEvent<HTMLInputElement>): void {
const f = parseFloat(event.target.value);
if (isNaN(f)) return;
setFontSize(f);
}
return (
<Modal open={props.open} onClose={props.onClose}>
<Box display="flex" flexDirection="row" alignItems="center">
@@ -42,6 +51,9 @@ export function OptionsModal(props: IProps): React.ReactElement {
<Typography>Use whitespace over tabs: </Typography>
<Switch onChange={(event) => setInsertSpaces(event.target.checked)} checked={insertSpaces} />
</Box>
<Box display="flex" flexDirection="row" alignItems="center">
<TextField type="number" label="Font size" value={fontSize} onChange={onFontChange} />
</Box>
<br />
<Button onClick={save}>Save</Button>
</Modal>
+5 -2
View File
@@ -31,7 +31,7 @@ import IconButton from "@mui/material/IconButton";
import SettingsIcon from "@mui/icons-material/Settings";
let symbols: string[] = [];
(function () {
export function SetupTextEditor(): void {
const ns = NetscriptFunctions({} as WorkerScript);
function populate(ns: any): string[] {
@@ -52,7 +52,7 @@ let symbols: string[] = [];
const exclude = ["heart", "break", "exploit", "bypass", "corporation"];
symbols = symbols.filter((symbol: string) => !exclude.includes(symbol));
})();
}
interface IProps {
filename: string;
@@ -87,6 +87,7 @@ export function Root(props: IProps): React.ReactElement {
const [options, setOptions] = useState<Options>({
theme: Settings.MonacoTheme,
insertSpaces: Settings.MonacoInsertSpaces,
fontSize: Settings.MonacoFontSize,
});
// store the last known state in case we need to restart without nano.
@@ -329,11 +330,13 @@ export function Root(props: IProps): React.ReactElement {
options={{
theme: Settings.MonacoTheme,
insertSpaces: Settings.MonacoInsertSpaces,
fontSize: Settings.MonacoFontSize,
}}
save={(options: Options) => {
setOptions(options);
Settings.MonacoTheme = options.theme;
Settings.MonacoInsertSpaces = options.insertSpaces;
Settings.MonacoFontSize = options.fontSize;
}}
/>
</>