1
0
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:
Per-Kristian Nordnes 2017-02-23 17:51:59 +01:00 committed by Ian Storm Taylor
parent 2bd5bc3fa7
commit a67a93dd42
7 changed files with 62 additions and 2 deletions

View File

@ -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)

View File

@ -0,0 +1,10 @@
export default function (state) {
const { document } = state
const nodeToBeFocused = document.nodes.last()
return state
.transform()
.collapseToStartOf(nodeToBeFocused)
.deleteBackward()
.apply()
}

View File

@ -0,0 +1,10 @@
nodes:
- kind: block
type: image
isVoid: true
- kind: block
type: paragraph
nodes:
- kind: text
text: ""

View File

@ -0,0 +1,5 @@
nodes:
- kind: block
type: image
isVoid: true

View File

@ -0,0 +1,10 @@
export default function (state) {
const { document } = state
const nodeToBeFocused = document.nodes.first()
return state
.transform()
.collapseToStartOf(nodeToBeFocused)
.deleteForward()
.apply()
}

View File

@ -0,0 +1,10 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: ""
- kind: block
type: image
isVoid: true

View File

@ -0,0 +1,5 @@
nodes:
- kind: block
type: image
isVoid: true