Skip to content

Commit 9d69fa7

Browse files
authored
fix: code editor action (#694)
1 parent 00b47a3 commit 9d69fa7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/components/CodeEditor.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Dispatch, useEffect, useState } from 'react'
1+
import { type Dispatch, useCallback, useEffect, useState } from 'react'
22
import { Button, Div, Flex, P } from 'honorable'
33
import { useTheme } from 'styled-components'
44

@@ -58,14 +58,19 @@ export default function CodeEditor({
5858
const [copied, setCopied] = useState<boolean>(false)
5959
const changed = current !== value
6060

61-
const onEditorMount = (editor: any) => {
62-
editor.addAction({
63-
id: 'remeasure-fonts',
64-
label: 'Remeasure Fonts',
65-
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB],
66-
run: () => monaco?.editor?.remeasureFonts(),
67-
})
68-
}
61+
const onEditorMount = useCallback(
62+
(editor: any) => {
63+
if (!monaco) return
64+
65+
editor.addAction({
66+
id: 'remeasure-fonts',
67+
label: 'Remeasure Fonts',
68+
keybindings: [monaco?.KeyMod?.CtrlCmd | monaco?.KeyCode?.KeyB],
69+
run: () => monaco?.editor?.remeasureFonts(),
70+
})
71+
},
72+
[monaco]
73+
)
6974

7075
useEffect(() => {
7176
if (copied) {

0 commit comments

Comments
 (0)