mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 12:14:14 +02:00
Fix deletion in Chrome when inline void node is selected (#4307)
This commit is contained in:
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 Hotkeys from '../utils/hotkeys'
|
||||||
import {
|
import {
|
||||||
HAS_BEFORE_INPUT_SUPPORT,
|
HAS_BEFORE_INPUT_SUPPORT,
|
||||||
|
IS_CHROME,
|
||||||
IS_FIREFOX,
|
IS_FIREFOX,
|
||||||
IS_FIREFOX_LEGACY,
|
IS_FIREFOX_LEGACY,
|
||||||
IS_SAFARI,
|
IS_SAFARI,
|
||||||
@@ -1057,6 +1058,33 @@ export const Editable = (props: EditableProps) => {
|
|||||||
|
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user