kopia lustrzana https://github.com/Tldraw/Tldraw
Clean up metakey in code editor events
rodzic
6fb1822467
commit
893c3d214a
|
@ -6,6 +6,7 @@ import React, { useCallback, useEffect, useRef } from 'react'
|
||||||
import styled from 'styles'
|
import styled from 'styles'
|
||||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
|
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
|
||||||
import { getFormattedCode } from 'utils/code'
|
import { getFormattedCode } from 'utils/code'
|
||||||
|
import { metaKey } from 'utils'
|
||||||
|
|
||||||
export type IMonaco = typeof monaco
|
export type IMonaco = typeof monaco
|
||||||
|
|
||||||
|
@ -136,11 +137,14 @@ export default function CodeEditor({
|
||||||
const handleKeydown = useCallback(
|
const handleKeydown = useCallback(
|
||||||
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
(e: React.KeyboardEvent<HTMLDivElement>) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
!modifierKeys.includes(e.key) && onKey?.()
|
!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
|
const editor = rEditor.current
|
||||||
|
|
||||||
if (!editor) return
|
if (!editor) return
|
||||||
|
|
||||||
editor
|
editor
|
||||||
.getAction('editor.action.formatDocument')
|
.getAction('editor.action.formatDocument')
|
||||||
.run()
|
.run()
|
||||||
|
@ -150,10 +154,11 @@ export default function CodeEditor({
|
||||||
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
if (e.key === 'p' && metaKey) {
|
if (e.key === 'p' && metaKey(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
if (e.key === 'd' && metaKey) {
|
|
||||||
|
if (e.key === 'd' && metaKey(e)) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Ładowanie…
Reference in New Issue