1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 06:31:28 +02:00

fix delete when end block has inline nodes

This commit is contained in:
Ian Storm Taylor
2016-08-15 16:21:41 -07:00
parent 01a00cb028
commit 31924c5314
19 changed files with 344 additions and 6 deletions

View File

@@ -108,23 +108,23 @@ const Transforms = {
ancestor = ancestor.merge({ nodes })
// Take the end edge's split text and move it to the start edge.
// Take the end edge's inline nodes and move them to the start edge.
let startBlock = ancestor.getClosestBlock(startText)
let endChild = ancestor.getFurthestInline(endText) || endText
let endBlock = ancestor.getClosestBlock(endText)
const startNodes = startBlock.nodes.push(endChild)
const startNodes = startBlock.nodes.concat(endBlock.nodes)
startBlock = startBlock.merge({ nodes: startNodes })
ancestor = ancestor.updateDescendant(startBlock)
// While the end child is an only child, remove the block it's in.
let endParent = ancestor.getClosestBlock(endChild)
let endParent = ancestor.getClosestBlock(endBlock)
while (endParent && endParent.nodes.size == 1) {
endChild = endParent
endBlock = endParent
endParent = ancestor.getClosestBlock(endParent)
}
ancestor = ancestor.removeDescendant(endChild)
ancestor = ancestor.removeDescendant(endBlock)
// Update the node.
node = isAncestor

View File

@@ -0,0 +1,18 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.get(0)
const second = texts.get(1)
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: second.key,
focusOffset: 0
})
return state
.transform()
.deleteAtRange(range)
.apply()
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const second = texts.get(1)
const range = selection.merge({
anchorKey: second.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
})
return state
.transform()
.deleteBackwardAtRange(range)
.apply()
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,33 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.get(0)
const second = texts.get(1)
const range = selection.merge({
anchorKey: second.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.deleteBackward()
.apply()
assert.deepEqual(
next.selection.toJS(),
range.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
}).toJS()
)
return next
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,17 @@
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
return state
.transform()
.deleteForwardAtRange(range)
.apply()
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,27 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.first()
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: first.key,
focusOffset: first.length
})
const next = state
.transform()
.moveTo(range)
.deleteForward()
.apply()
assert.deepEqual(
next.selection.toJS(),
range.collapseToStart().toJS()
)
return next
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,28 @@
import assert from 'assert'
export default function (state) {
const { document, selection } = state
const texts = document.getTexts()
const first = texts.get(0)
const second = texts.get(1)
const range = selection.merge({
anchorKey: first.key,
anchorOffset: first.length,
focusKey: second.key,
focusOffset: 0
})
const next = state
.transform()
.moveTo(range)
.delete()
.apply()
assert.deepEqual(
next.selection.toJS(),
range.collapseToStart().toJS()
)
return next
}

View File

@@ -0,0 +1,19 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one
- kind: block
type: paragraph
nodes:
- kind: text
text: two
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four

View File

@@ -0,0 +1,14 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: onetwo
- kind: inline
type: link
nodes:
- kind: text
text: three
- kind: text
text: four