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:
5
.changeset/android-text-mutations.md
Normal file
5
.changeset/android-text-mutations.md
Normal 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.
|
5
.changeset/consumer-oninput-event.md
Normal file
5
.changeset/consumer-oninput-event.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed consumer defined `onInput` event handler not being invoked when passed to the `<Editable>` component.
|
@@ -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
|
||||||
|
@@ -31,23 +31,26 @@ export const createRestoreDomManager = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restoreDOM() {
|
function restoreDOM() {
|
||||||
bufferedMutations.reverse().forEach(mutation => {
|
if (bufferedMutations.length > 0) {
|
||||||
if (mutation.type === 'characterData') {
|
bufferedMutations.reverse().forEach(mutation => {
|
||||||
mutation.target.textContent = mutation.oldValue
|
if (mutation.type === 'characterData') {
|
||||||
return
|
// We don't want to restore the DOM for characterData mutations
|
||||||
}
|
// because this interrupts the composition.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
mutation.removedNodes.forEach(node => {
|
mutation.removedNodes.forEach(node => {
|
||||||
mutation.target.insertBefore(node, mutation.nextSibling)
|
mutation.target.insertBefore(node, mutation.nextSibling)
|
||||||
|
})
|
||||||
|
|
||||||
|
mutation.addedNodes.forEach(node => {
|
||||||
|
mutation.target.removeChild(node)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
mutation.addedNodes.forEach(node => {
|
// Clear buffered mutations to ensure we don't undo them twice
|
||||||
mutation.target.removeChild(node)
|
clear()
|
||||||
})
|
}
|
||||||
})
|
|
||||||
|
|
||||||
// Clear buffered mutations to ensure we don't undo them twice
|
|
||||||
clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user