1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-28 09:29:49 +02:00

fix deleteLine with first void inline node (#1377)

This commit is contained in:
Yifeng Wang
2017-11-12 07:49:33 +08:00
committed by Ian Storm Taylor
parent 64eb1169af
commit 9a5d97e6d1
6 changed files with 160 additions and 1 deletions

View File

@@ -296,8 +296,26 @@ Changes.deleteLineBackwardAtRange = (change, range, options) => {
const { startKey, startOffset } = range
const startBlock = document.getClosestBlock(startKey)
const offset = startBlock.getOffset(startKey)
const o = offset + startOffset
const startWithVoidInline = (
startBlock.nodes.size > 1 &&
startBlock.nodes.get(0).text == '' &&
startBlock.nodes.get(1).kind == 'inline'
)
let o = offset + startOffset
// If line starts with an void inline node, the text node inside this inline
// node disturbs the offset. Ignore this inline node and delete it afterwards.
if (startWithVoidInline) {
o -= 1
}
change.deleteBackwardAtRange(range, o, options)
// Delete the remaining first inline node if needed.
if (startWithVoidInline) {
change.deleteBackward()
}
}
/**

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.deleteLineBackward()
}
export const input = (
<value>
<document>
<paragraph>
one <link>wo📛rd</link><cursor />
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<cursor />
</paragraph>
</document>
</value>
)

View File

@@ -0,0 +1,33 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.deleteLineBackward()
}
export const input = (
<value>
<document>
<paragraph>
<emoji>😊</emoji>
one
<emoji>😊</emoji>
two
<emoji>😀</emoji>
three
<cursor />
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<cursor />
</paragraph>
</document>
</value>
)

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.deleteLineBackward()
}
export const input = (
<value>
<document>
<paragraph>
<emoji>😊</emoji>one two three<cursor />
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<cursor />
</paragraph>
</document>
</value>
)

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.deleteLineBackward()
}
export const input = (
<value>
<document>
<paragraph>
one two three<cursor />
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<cursor />
</paragraph>
</document>
</value>
)

View File

@@ -0,0 +1,27 @@
/** @jsx h */
import h from '../../../helpers/h'
export default function (change) {
change.deleteLineBackward()
}
export const input = (
<value>
<document>
<paragraph>
one two thr<cursor />ee
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<cursor />ee
</paragraph>
</document>
</value>
)