Skip to content

Commit e7273e0

Browse files
authored
feat(editor): Add configurable font size (#188)
This commit introduces a new local setting to allow users to customize the font size in the Monaco editor. - Adds an editor_font_size setting to the local store with a default of 14. - Implements a number input with increment/decrement buttons in the Local Settings panel to modify the font size. - The MonacoEditor component now reads this value to set its font size and updates dynamically when the setting is changed.
1 parent 355b737 commit e7273e0

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/components/MonacoEditor.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MaybeLoading } from "./FullLoading"
44
import loader from "@monaco-editor/loader"
55
import { useCDN } from "~/hooks"
66
import type * as monacoType from "monaco-editor/esm/vs/editor/editor.api"
7+
import { local } from "~/store"
78

89
export interface MonacoEditorProps {
910
value: string
@@ -42,6 +43,7 @@ export const MonacoEditor = (props: MonacoEditorProps) => {
4243
monacoEditor = monaco.editor.create(monacoEditorDiv!, {
4344
value: props.value,
4445
theme: props.theme,
46+
fontSize: parseInt(local.editor_font_size),
4547
})
4648
model = monaco.editor.createModel(
4749
props.value,
@@ -60,6 +62,13 @@ export const MonacoEditor = (props: MonacoEditorProps) => {
6062
createEffect(() => {
6163
monaco.editor.setTheme(props.theme)
6264
})
65+
66+
createEffect(() => {
67+
monacoEditor?.updateOptions({
68+
fontSize: parseInt(local.editor_font_size),
69+
})
70+
})
71+
6372
onCleanup(() => {
6473
model && model.dispose()
6574
monacoEditor && monacoEditor.dispose()

src/pages/home/toolbar/LocalSettings.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import {
2323
SelectValue,
2424
VStack,
2525
Switch as HopeSwitch,
26+
IconButton,
2627
} from "@hope-ui/solid"
2728
import { For, Match, onCleanup, Switch } from "solid-js"
29+
import { FaSolidMinus, FaSolidPlus } from "solid-icons/fa"
2830
import { SwitchLanguageWhite, SwitchColorMode } from "~/components"
2931
import { useT } from "~/hooks"
3032
import { initialLocalSettings, local, LocalSetting, setLocal } from "~/store"
@@ -80,6 +82,40 @@ function LocalSettingEdit(props: LocalSetting) {
8082
}}
8183
/>
8284
</Match>
85+
<Match when={props.type === "number"}>
86+
<HStack>
87+
<IconButton
88+
aria-label="decrease"
89+
icon={<FaSolidMinus />}
90+
onClick={() => {
91+
setLocal(
92+
props.key,
93+
Math.max(1, parseInt(local[props.key]) - 1).toString(),
94+
)
95+
}}
96+
/>
97+
<Input
98+
type="number"
99+
value={local[props.key]}
100+
onInput={(e) => {
101+
setLocal(props.key, e.currentTarget.value)
102+
}}
103+
style={{
104+
"-moz-appearance": "textfield",
105+
"::-webkit-inner-spin-button": { display: "none" },
106+
"::-webkit-outer-spin-button": { display: "none" },
107+
}}
108+
class="hide-spin"
109+
/>
110+
<IconButton
111+
aria-label="increase"
112+
icon={<FaSolidPlus />}
113+
onClick={() => {
114+
setLocal(props.key, (parseInt(local[props.key]) + 1).toString())
115+
}}
116+
/>
117+
</HStack>
118+
</Match>
83119
</Switch>
84120
</FormControl>
85121
)

src/store/local_settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const initialLocalSettings = [
6666
options: ["direct", "dblclick", "disable_while_checked"],
6767
hidden: false,
6868
},
69+
{
70+
key: "editor_font_size",
71+
default: "14",
72+
type: "number",
73+
},
6974
]
7075
export type LocalSetting = (typeof initialLocalSettings)[number]
7176
for (const setting of initialLocalSettings) {

0 commit comments

Comments
 (0)