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:
@ -1,3 +1,4 @@
|
|||||||
|
import { undo, redo } from '@codemirror/commands'
|
||||||
import ReactCodeMirror, {
|
import ReactCodeMirror, {
|
||||||
Extension,
|
Extension,
|
||||||
ViewUpdate,
|
ViewUpdate,
|
||||||
@ -31,6 +32,7 @@ import { sceneInfra } from 'clientSideScene/sceneInfra'
|
|||||||
import { copilotPlugin } from 'editor/plugins/lsp/copilot'
|
import { copilotPlugin } from 'editor/plugins/lsp/copilot'
|
||||||
import { isTauri } from 'lib/isTauri'
|
import { isTauri } from 'lib/isTauri'
|
||||||
import type * as LSP from 'vscode-languageserver-protocol'
|
import type * as LSP from 'vscode-languageserver-protocol'
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
|
|
||||||
export const editorShortcutMeta = {
|
export const editorShortcutMeta = {
|
||||||
formatCode: {
|
formatCode: {
|
||||||
@ -77,6 +79,19 @@ export const TextEditor = ({
|
|||||||
const { code, errors } = useKclContext()
|
const { code, errors } = useKclContext()
|
||||||
const lastEvent = useRef({ event: '', time: Date.now() })
|
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 {
|
const {
|
||||||
context: { selectionRanges, selectionRangeTypeMap },
|
context: { selectionRanges, selectionRangeTypeMap },
|
||||||
send,
|
send,
|
||||||
|
Reference in New Issue
Block a user