Honor mod+z and mod+shift+z even with editor not in focus (#1513)

Resolves #1504 and was way easier than I thought when I tried it a while back!
This commit is contained in:
Frank Noirot
2024-02-23 17:37:05 -05:00
committed by GitHub
parent 8f5034f997
commit a2455832e7

View File

@ -1,3 +1,4 @@
import { undo, redo } from '@codemirror/commands'
import ReactCodeMirror, {
Extension,
ViewUpdate,
@ -31,6 +32,7 @@ import { sceneInfra } from 'clientSideScene/sceneInfra'
import { copilotPlugin } from 'editor/plugins/lsp/copilot'
import { isTauri } from 'lib/isTauri'
import type * as LSP from 'vscode-languageserver-protocol'
import { useHotkeys } from 'react-hotkeys-hook'
export const editorShortcutMeta = {
formatCode: {
@ -77,6 +79,19 @@ export const TextEditor = ({
const { code, errors } = useKclContext()
const lastEvent = useRef({ event: '', time: Date.now() })
useHotkeys('mod+z', (e) => {
e.preventDefault()
if (editorView) {
undo(editorView)
}
})
useHotkeys('mod+shift+z', (e) => {
e.preventDefault()
if (editorView) {
redo(editorView)
}
})
const {
context: { selectionRanges, selectionRangeTypeMap },
send,