mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 10:29:48 +02:00
fix deleting across nested blocks, closes #341
This commit is contained in:
@@ -92,7 +92,8 @@ export function deleteAtRange(transform, range) {
|
||||
transform.moveNodeByKey(child.key, newKey, newIndex)
|
||||
})
|
||||
|
||||
transform.removeNodeByKey(endChild.key)
|
||||
const lonely = document.getFurthest(endBlock, p => p.nodes.size == 1) || endBlock
|
||||
transform.removeNodeByKey(lonely.key)
|
||||
transform.normalizeDocument()
|
||||
return transform
|
||||
}
|
||||
|
@@ -0,0 +1,18 @@
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTexts()
|
||||
const second = texts.get(1)
|
||||
const third = texts.get(2)
|
||||
const range = selection.merge({
|
||||
anchorKey: second.key,
|
||||
anchorOffset: second.length,
|
||||
focusKey: third.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
|
||||
return state
|
||||
.transform()
|
||||
.deleteAtRange(range)
|
||||
.apply()
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: list
|
||||
nodes:
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: one
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: two
|
||||
- kind: block
|
||||
type: list
|
||||
nodes:
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: three
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: four
|
@@ -0,0 +1,23 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: list
|
||||
nodes:
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: one
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: twothree
|
||||
- kind: block
|
||||
type: list
|
||||
nodes:
|
||||
- kind: block
|
||||
type: item
|
||||
nodes:
|
||||
- kind: text
|
||||
text: four
|
Reference in New Issue
Block a user