Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete on Android with a deep document #3095

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/slate-react/src/plugins/android/composition-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,22 @@ function CompositionManager(editor) {

const firstMutation = mutations[0]

// Here we want to filter BR nodes out.
// When the content editable choose to remove a node instead of
// a 'characterData' mutation, it is usually the only mutation, unless
// it's the last node. When it's the last node, the browser also adds a BR.
// We want to filter it out so we match the mutation correctly and call `removeNode`
const filterBr = () => {
return mutations.filter(m => {
return !(m.addedNodes[0] && m.addedNodes[0].nodeName === 'BR')
})
}

if (firstMutation.type === 'characterData') {
resolveDOMNode(firstMutation.target.parentNode)
} else if (firstMutation.type === 'childList') {
if (firstMutation.removedNodes.length > 0) {
if (mutations.length === 1) {
if (filterBr().length === 1) {
removeNode(firstMutation.removedNodes[0])
} else {
mergeBlock()
Expand Down
9 changes: 8 additions & 1 deletion packages/slate-react/src/plugins/react/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ function CommandsPlugin() {
function reconcileDOMNode(editor, domNode) {
const domElement = domNode.parentElement.closest('[data-key]')
const node = editor.findNode(domElement)
editor.reconcileNode(node)

if (node.object === 'text') {
editor.reconcileNode(node)
} else {
node.getTexts().forEach(textNode => {
editor.reconcileNode(textNode)
})
}
}

return {
Expand Down