Skip to content

Commit aaca301

Browse files
authored
Feat add editor fontsize (#2088)
I added editor fontsize configuration. I found an issue that had related requirements, so I added it. I hope I can be of some help. ![feat-editorFontsize](https://github.com/user-attachments/assets/e6b4567b-384f-4132-861d-6675ff5543de)
1 parent cf55519 commit aaca301

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

frontend/app/view/codeeditor/codeeditor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { useOverrideConfigAtom } from "@/app/store/global";
5-
import { boundNumber } from "@/util/util";
65
import loader from "@monaco-editor/loader";
76
import { Editor, Monaco } from "@monaco-editor/react";
87
import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api";
@@ -11,7 +10,7 @@ import React, { useMemo, useRef } from "react";
1110

1211
import { RpcApi } from "@/app/store/wshclientapi";
1312
import { TabRpcClient } from "@/app/store/wshrpcutil";
14-
import { makeConnRoute } from "@/util/util";
13+
import { boundNumber, makeConnRoute } from "@/util/util";
1514
import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
1615
import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker";
1716
import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker";

frontend/app/view/preview/preview.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ export class PreviewModel implements ViewModel {
686686
}
687687

688688
getSettingsMenuItems(): ContextMenuItem[] {
689+
const defaultFontSize = globalStore.get(getSettingsKeyAtom("editor:fontsize")) ?? 12;
690+
const blockData = globalStore.get(this.blockAtom);
691+
const overrideFontSize = blockData?.meta?.["editor:fontsize"];
689692
const menuItems: ContextMenuItem[] = [];
690693
menuItems.push({
691694
label: "Copy Full Path",
@@ -716,6 +719,37 @@ export class PreviewModel implements ViewModel {
716719
await navigator.clipboard.writeText(fileInfo.name);
717720
}),
718721
});
722+
menuItems.push({ type: "separator" });
723+
const fontSizeSubMenu: ContextMenuItem[] = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18].map(
724+
(fontSize: number) => {
725+
return {
726+
label: fontSize.toString() + "px",
727+
type: "checkbox",
728+
checked: overrideFontSize == fontSize,
729+
click: () => {
730+
RpcApi.SetMetaCommand(TabRpcClient, {
731+
oref: WOS.makeORef("block", this.blockId),
732+
meta: { "editor:fontsize": fontSize },
733+
});
734+
},
735+
};
736+
}
737+
);
738+
fontSizeSubMenu.unshift({
739+
label: "Default (" + defaultFontSize + "px)",
740+
type: "checkbox",
741+
checked: overrideFontSize == null,
742+
click: () => {
743+
RpcApi.SetMetaCommand(TabRpcClient, {
744+
oref: WOS.makeORef("block", this.blockId),
745+
meta: { "editor:fontsize": null },
746+
});
747+
},
748+
});
749+
menuItems.push({
750+
label: "Editor Font Size",
751+
submenu: fontSizeSubMenu,
752+
});
719753
const finfo = jotaiLoadableValue(globalStore.get(this.loadableFileInfo), null);
720754
addOpenMenuItems(menuItems, globalStore.get(this.connectionImmediate), finfo);
721755
const loadableSV = globalStore.get(this.loadableSpecializedView);

frontend/types/gotypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ declare global {
559559
"editor:minimapenabled"?: boolean;
560560
"editor:stickyscrollenabled"?: boolean;
561561
"editor:wordwrap"?: boolean;
562+
"editor:fontsize"?: number;
562563
"graph:*"?: boolean;
563564
"graph:numpoints"?: number;
564565
"graph:metrics"?: string[];

0 commit comments

Comments
 (0)