mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-16 03:12:48 +02:00
Fix deletion in Chrome when inline void node is selected (#4307)
This commit is contained in:
parent
2c17e2b7f9
commit
a7e3a18187
5
.changeset/delete-inline-void.md
Normal file
5
.changeset/delete-inline-void.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
Fix deletion of selected inline void nodes in Chrome. Chrome does not fire a `beforeinput` event when deleting backwards within an inline void node, so we need to add special logic to handle this edge-case for Chrome only.
|
@ -18,6 +18,7 @@ import useChildren from '../hooks/use-children'
|
||||
import Hotkeys from '../utils/hotkeys'
|
||||
import {
|
||||
HAS_BEFORE_INPUT_SUPPORT,
|
||||
IS_CHROME,
|
||||
IS_FIREFOX,
|
||||
IS_FIREFOX_LEGACY,
|
||||
IS_SAFARI,
|
||||
@ -1057,6 +1058,33 @@ export const Editable = (props: EditableProps) => {
|
||||
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (IS_CHROME) {
|
||||
// COMPAT: Chrome supports `beforeinput` event but does not fire
|
||||
// an event when deleting backwards in a selected void inline node
|
||||
if (
|
||||
selection &&
|
||||
(Hotkeys.isDeleteBackward(nativeEvent) ||
|
||||
Hotkeys.isDeleteForward(nativeEvent)) &&
|
||||
Range.isCollapsed(selection)
|
||||
) {
|
||||
const currentNode = Node.parent(
|
||||
editor,
|
||||
selection.anchor.path
|
||||
)
|
||||
|
||||
if (
|
||||
Element.isElement(currentNode) &&
|
||||
Editor.isVoid(editor, currentNode) &&
|
||||
Editor.isInline(editor, currentNode)
|
||||
) {
|
||||
event.preventDefault()
|
||||
Transforms.delete(editor, { unit: 'block' })
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user