mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 14:41:23 +02:00
This commit is contained in:
committed by
Ian Storm Taylor
parent
86f4844d5d
commit
86cbb0d49a
@@ -211,7 +211,7 @@ export function deleteBackwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If the closest is not void, but empty, remove it
|
// If the closest is not void, but empty, remove it
|
||||||
if (block && !block.isVoid && block.isEmpty) {
|
if (block && !block.isVoid && block.isEmpty && document.nodes.size !== 1) {
|
||||||
transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -395,7 +395,7 @@ export function deleteForwardAtRange(transform, range, n = 1, options = {}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If the closest is not void, but empty, remove it
|
// If the closest is not void, but empty, remove it
|
||||||
if (block && !block.isVoid && block.isEmpty) {
|
if (block && !block.isVoid && block.isEmpty && document.nodes.size !== 1) {
|
||||||
transform.removeNodeByKey(block.key, { normalize })
|
transform.removeNodeByKey(block.key, { normalize })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -60,16 +60,24 @@ export function normalizeNodeByKey(transform, key, schema) {
|
|||||||
export function normalizeSelection(transform) {
|
export function normalizeSelection(transform) {
|
||||||
let { state } = transform
|
let { state } = transform
|
||||||
let { document, selection } = state
|
let { document, selection } = state
|
||||||
|
|
||||||
|
// If document is empty, return
|
||||||
|
if (document.nodes.size === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
selection = selection.normalize(document)
|
selection = selection.normalize(document)
|
||||||
|
|
||||||
// If the selection is unset, or the anchor or focus key in the selection are
|
// If the selection is unset, or the anchor or focus key in the selection are
|
||||||
// pointing to nodes that no longer exist, warn and reset the selection.
|
// pointing to nodes that no longer exist, warn (if not unset) and reset the selection.
|
||||||
if (
|
if (
|
||||||
selection.isUnset ||
|
selection.isUnset ||
|
||||||
!document.hasDescendant(selection.anchorKey) ||
|
!document.hasDescendant(selection.anchorKey) ||
|
||||||
!document.hasDescendant(selection.focusKey)
|
!document.hasDescendant(selection.focusKey)
|
||||||
) {
|
) {
|
||||||
|
if (!selection.isUnset) {
|
||||||
warn('The selection was invalid and was reset to start of the document. The selection in question was:', selection)
|
warn('The selection was invalid and was reset to start of the document. The selection in question was:', selection)
|
||||||
|
}
|
||||||
|
|
||||||
const firstText = document.getFirstText()
|
const firstText = document.getFirstText()
|
||||||
selection = selection.merge({
|
selection = selection.merge({
|
||||||
|
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
export default function (state) {
|
||||||
|
const { document } = state
|
||||||
|
const nodeToBeFocused = document.nodes.first()
|
||||||
|
return state
|
||||||
|
.transform()
|
||||||
|
.collapseToEndOf(nodeToBeFocused)
|
||||||
|
.deleteBackward()
|
||||||
|
.apply()
|
||||||
|
}
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
export default function (state) {
|
||||||
|
const { document } = state
|
||||||
|
const nodeToBeFocused = document.nodes.first()
|
||||||
|
return state
|
||||||
|
.transform()
|
||||||
|
.collapseToEndOf(nodeToBeFocused)
|
||||||
|
.deleteBackward()
|
||||||
|
.apply()
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: image
|
||||||
|
isVoid: true
|
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
nodes: []
|
@@ -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,7 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: paragraph
|
||||||
|
nodes:
|
||||||
|
- kind: text
|
||||||
|
text: ""
|
@@ -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,5 @@
|
|||||||
|
|
||||||
|
nodes:
|
||||||
|
- kind: block
|
||||||
|
type: image
|
||||||
|
isVoid: true
|
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
nodes: []
|
Reference in New Issue
Block a user