[fix] Focus events (actually) (#2015)

This PR restores the controlled nature of focus. Focus allows keyboard
shortcuts and other interactions to occur. The editor's focus should
always / entirely be controlled via the autoFocus prop or by manually
setting `editor.instanceState.isFocused`.

Design note: I'm starting to think that focus is the wrong abstraction,
and that we should instead use a kind of "disabled" state for editors
that the user isn't interacting with directly. In a page where multiple
editors exit (e.g. a notion page), a developer could switch from
disabled to enabled using a first interaction.

### Change Type

- [x] `patch` — Bug fix

### Test Plan

- [x] End to end tests
This commit is contained in:
Steve Ruiz 2023-10-04 10:01:48 +01:00 committed by GitHub
parent 6b19d70a9e
commit d715fa3a2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 236 additions and 122 deletions

View file

@ -1,5 +1,10 @@
import React, { useMemo } from 'react'
import { preventDefault, releasePointerCapture, setPointerCapture } from '../utils/dom'
import {
preventDefault,
releasePointerCapture,
setPointerCapture,
stopEventPropagation,
} from '../utils/dom'
import { getPointerInfo } from '../utils/getPointerInfo'
import { useEditor } from './useEditor'
@ -12,6 +17,8 @@ export function useCanvasEvents() {
let lastX: number, lastY: number
function onPointerDown(e: React.PointerEvent) {
stopEventPropagation(e)
if ((e as any).isKilled) return
if (e.button === 2) {
@ -103,6 +110,10 @@ export function useCanvasEvents() {
})
}
function onClick(e: React.MouseEvent) {
stopEventPropagation(e)
}
return {
onPointerDown,
onPointerMove,
@ -111,6 +122,7 @@ export function useCanvasEvents() {
onDrop,
onTouchStart,
onTouchEnd,
onClick,
}
},
[editor]