From 893c3d214a37e7cd350a31c02aee23d3bf2d1ae7 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Sat, 10 Jul 2021 17:28:44 +0100 Subject: [PATCH] Clean up metakey in code editor events --- components/code-panel/code-editor.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/code-panel/code-editor.tsx b/components/code-panel/code-editor.tsx index 557945027..7c960aec3 100644 --- a/components/code-panel/code-editor.tsx +++ b/components/code-panel/code-editor.tsx @@ -6,6 +6,7 @@ import React, { useCallback, useEffect, useRef } from 'react' import styled from 'styles' import * as monaco from 'monaco-editor/esm/vs/editor/editor.api' import { getFormattedCode } from 'utils/code' +import { metaKey } from 'utils' export type IMonaco = typeof monaco @@ -136,11 +137,14 @@ export default function CodeEditor({ const handleKeydown = useCallback( (e: React.KeyboardEvent) => { e.stopPropagation() + !modifierKeys.includes(e.key) && onKey?.() - const metaKey = navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey - if (e.key === 's' && metaKey) { + + if ((e.key === 's' || e.key === 'Enter') && metaKey(e)) { const editor = rEditor.current + if (!editor) return + editor .getAction('editor.action.formatDocument') .run() @@ -150,10 +154,11 @@ export default function CodeEditor({ e.preventDefault() } - if (e.key === 'p' && metaKey) { + if (e.key === 'p' && metaKey(e)) { e.preventDefault() } - if (e.key === 'd' && metaKey) { + + if (e.key === 'd' && metaKey(e)) { e.preventDefault() } },