mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-10 09:13:59 +02:00
Fix behaviour where deleteBackward/Forward on empty block deleted the void block above/below (#618)
This commit is contained in:
committed by
Ian Storm Taylor
parent
2bd5bc3fa7
commit
a67a93dd42
@@ -204,12 +204,17 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the closest block is void, delete it.
|
|
||||||
const block = document.getClosestBlock(startKey)
|
const block = document.getClosestBlock(startKey)
|
||||||
|
// If the closest block is void, delete it.
|
||||||
if (block && block.isVoid) {
|
if (block && block.isVoid) {
|
||||||
transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
return
|
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.
|
// If the closest inline is void, delete it.
|
||||||
const inline = document.getClosestInline(startKey)
|
const inline = document.getClosestInline(startKey)
|
||||||
@@ -383,12 +388,17 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the closest block is void, delete it.
|
|
||||||
const block = document.getClosestBlock(startKey)
|
const block = document.getClosestBlock(startKey)
|
||||||
|
// If the closest block is void, delete it.
|
||||||
if (block && block.isVoid) {
|
if (block && block.isVoid) {
|
||||||
transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
return
|
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.
|
// If the closest inline is void, delete it.
|
||||||
const inline = document.getClosestInline(startKey)
|
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
|
Reference in New Issue
Block a user