1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +02:00

Unset isComposing on keydown with isCompsing false (#4979)

This commit is contained in:
Eric Meier
2022-04-29 22:15:49 -04:00
committed by GitHub
parent d8da50f761
commit 6afa9f6a71
2 changed files with 22 additions and 7 deletions

View File

@@ -1090,15 +1090,25 @@ export const Editable = (props: EditableProps) => {
)}
onKeyDown={useCallback(
(event: React.KeyboardEvent<HTMLDivElement>) => {
if (
!readOnly &&
hasEditableTarget(editor, event.target) &&
!isEventHandled(event, attributes.onKeyDown) &&
!state.isComposing
) {
if (!readOnly && hasEditableTarget(editor, event.target)) {
const { nativeEvent } = event
const { selection } = editor
// COMPAT: The composition end event isn't fired reliably in all browsers,
// so we sometimes might end up stuck in a composition state even though we
// aren't composing any more.
if (state.isComposing && nativeEvent.isComposing === false) {
state.isComposing = false
setIsComposing(false)
}
if (
isEventHandled(event, attributes.onKeyDown) ||
state.isComposing
) {
return
}
const { selection } = editor
const element =
editor.children[
selection !== null ? selection.focus.path[0] : 0