1
0
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:
Ian Storm Taylor
2016-09-22 16:08:52 -07:00
parent 785bd3e82e
commit 1aba4b9f94
7 changed files with 71 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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