1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

Android related improvements (#5315)

* Allow consumer handling of `onInput` event

* Avoid restoring the DOM for characterData mutations
This commit is contained in:
Claudéric Demers
2023-02-26 19:27:26 -05:00
committed by GitHub
parent c753e68c69
commit 5784a38b6b
4 changed files with 32 additions and 15 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
The `RestoreDOM` manager that is used Android no longer restores the DOM to its previous state for text mutations. This allows the editor state to be reconciled during a composition without interrupting the composition, as programatically updating the `textContent` of a text node ends the current composition.

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fixed consumer defined `onInput` event handler not being invoked when passed to the `<Editable>` component.

View File

@@ -894,7 +894,11 @@ export const Editable = (props: EditableProps) => {
}, },
[readOnly] [readOnly]
)} )}
onInput={useCallback((event: React.SyntheticEvent) => { onInput={useCallback((event: React.FormEvent<HTMLDivElement>) => {
if (isEventHandled(event, attributes.onInput)) {
return
}
if (androidInputManager) { if (androidInputManager) {
androidInputManager.handleInput() androidInputManager.handleInput()
return return

View File

@@ -31,9 +31,11 @@ export const createRestoreDomManager = (
} }
function restoreDOM() { function restoreDOM() {
if (bufferedMutations.length > 0) {
bufferedMutations.reverse().forEach(mutation => { bufferedMutations.reverse().forEach(mutation => {
if (mutation.type === 'characterData') { if (mutation.type === 'characterData') {
mutation.target.textContent = mutation.oldValue // We don't want to restore the DOM for characterData mutations
// because this interrupts the composition.
return return
} }
@@ -49,6 +51,7 @@ export const createRestoreDomManager = (
// Clear buffered mutations to ensure we don't undo them twice // Clear buffered mutations to ensure we don't undo them twice
clear() clear()
} }
}
return { return {
registerMutations, registerMutations,