mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-16 11:22:15 +02:00
Fix behaviour where deleteBackward/Forward on empty block deleted the void block above/below (#618)
This commit is contained in:
parent
2bd5bc3fa7
commit
a67a93dd42
@ -204,12 +204,17 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
||||
return
|
||||
}
|
||||
|
||||
// If the closest block is void, delete it.
|
||||
const block = document.getClosestBlock(startKey)
|
||||
// If the closest block is void, delete it.
|
||||
if (block && block.isVoid) {
|
||||
transform.removeNodeByKey(block.key, { normalize })
|
||||
return
|
||||
}
|
||||
// If the closest is not void, but empty, remove it
|
||||
if (block && !block.isVoid && block.isEmpty) {
|
||||
transform.removeNodeByKey(block.key, { normalize })
|
||||
return
|
||||
}
|
||||
|
||||
// If the closest inline is void, delete it.
|
||||
const inline = document.getClosestInline(startKey)
|
||||
@ -383,12 +388,17 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
||||
return
|
||||
}
|
||||
|
||||
// If the closest block is void, delete it.
|
||||
const block = document.getClosestBlock(startKey)
|
||||
// If the closest block is void, delete it.
|
||||
if (block && block.isVoid) {
|
||||
transform.removeNodeByKey(block.key, { normalize })
|
||||
return
|
||||
}
|
||||
// If the closest is not void, but empty, remove it
|
||||
if (block && !block.isVoid && block.isEmpty) {
|
||||
transform.removeNodeByKey(block.key, { normalize })
|
||||
return
|
||||
}
|
||||
|
||||
// If the closest inline is void, delete it.
|
||||
const inline = document.getClosestInline(startKey)
|
||||
|
@ -0,0 +1,10 @@
|
||||
|
||||
export default function (state) {
|
||||
const { document } = state
|
||||
const nodeToBeFocused = document.nodes.last()
|
||||
return state
|
||||
.transform()
|
||||
.collapseToStartOf(nodeToBeFocused)
|
||||
.deleteBackward()
|
||||
.apply()
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
@ -0,0 +1,5 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
@ -0,0 +1,10 @@
|
||||
|
||||
export default function (state) {
|
||||
const { document } = state
|
||||
const nodeToBeFocused = document.nodes.first()
|
||||
return state
|
||||
.transform()
|
||||
.collapseToStartOf(nodeToBeFocused)
|
||||
.deleteForward()
|
||||
.apply()
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: ""
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
@ -0,0 +1,5 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
isVoid: true
|
Loading…
x
Reference in New Issue
Block a user