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, {
 | 
			
		||||
  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,
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user