From 0756bb94fde87bd2bf8806d3a4323a2335478306 Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 27 Jul 2022 11:49:41 +0200 Subject: [PATCH] added zoomin and zoomout to context menu of editor --- .../editor/src/lib/remix-ui-editor.tsx | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 46a5e76d9b..0b5b950180 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -245,7 +245,6 @@ export const EditorUI = (props: EditorUIProps) => { defineAndSetTheme(monacoRef.current) }) - useEffect(() => { if (!editorRef.current || !props.currentFile) return currentFileRef.current = props.currentFile @@ -410,6 +409,8 @@ export const EditorUI = (props: EditorUIProps) => { (window as any).addRemixBreakpoint(e.target.position) } }) + + // zoomin zoomout editor.addCommand(monacoRef.current.KeyMod.CtrlCmd | monacoRef.current.KeyCode.US_EQUAL, () => { editor.updateOptions({ fontSize: editor.getOption(43).fontSize + 1 }) }) @@ -417,6 +418,32 @@ export const EditorUI = (props: EditorUIProps) => { editor.updateOptions({ fontSize: editor.getOption(43).fontSize - 1 }) }) + // add context menu items + const zoominAction = { + id: "zoomIn", + label: "Zoom In", + contextMenuOrder: 0, // choose the order + contextMenuGroupId: "zooming", // create a new grouping + keybindings: [ + // eslint-disable-next-line no-bitwise + monacoRef.current.KeyMod.CtrlCmd | monacoRef.current.KeyCode.Equal, + ], + run: () => { editor.updateOptions({ fontSize: editor.getOption(43).fontSize + 1 }) }, + } + const zoomOutAction = { + id: "zoomOut", + label: "Zoom Out", + contextMenuOrder: 0, // choose the order + contextMenuGroupId: "zooming", // create a new grouping + keybindings: [ + // eslint-disable-next-line no-bitwise + monacoRef.current.KeyMod.CtrlCmd | monacoRef.current.KeyCode.Minus, + ], + run: () => { editor.updateOptions({ fontSize: editor.getOption(43).fontSize - 1 }) }, + } + editor.addAction(zoomOutAction) + editor.addAction(zoominAction) + const editorService = editor._codeEditorService; const openEditorBase = editorService.openCodeEditor.bind(editorService); editorService.openCodeEditor = async (input, source) => {