mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 13:51:59 +02:00
Fix the characters count in deleteForward (#1864)
* Fix the characters bug in deleteForward * Adding tests * Fix void positions in tests * add tests for n===0
This commit is contained in:
parent
727a7ece26
commit
1383b38546
@ -334,6 +334,7 @@ Changes.deleteWordBackwardAtRange = (change, range, options) => {
|
||||
*/
|
||||
|
||||
Changes.deleteBackwardAtRange = (change, range, n = 1, options = {}) => {
|
||||
if (n === 0) return
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
const { value } = change
|
||||
const { document } = value
|
||||
@ -467,7 +468,7 @@ Changes.deleteLineForwardAtRange = (change, range, options) => {
|
||||
const startBlock = document.getClosestBlock(startKey)
|
||||
const offset = startBlock.getOffset(startKey)
|
||||
const o = offset + startOffset
|
||||
change.deleteForwardAtRange(range, o, options)
|
||||
change.deleteForwardAtRange(range, startBlock.text.length - o, options)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -502,6 +503,7 @@ Changes.deleteWordForwardAtRange = (change, range, options) => {
|
||||
*/
|
||||
|
||||
Changes.deleteForwardAtRange = (change, range, n = 1, options = {}) => {
|
||||
if (n === 0) return
|
||||
const normalize = change.getFlag('normalize', options)
|
||||
const { value } = change
|
||||
const { document } = value
|
||||
|
@ -0,0 +1,20 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineBackward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
one two three
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = input
|
@ -0,0 +1,28 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
one <link>wo📛rd</link>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@ -0,0 +1,33 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
one
|
||||
<emoji>😊</emoji>
|
||||
two
|
||||
<emoji>😊</emoji>
|
||||
three
|
||||
<emoji>😀</emoji>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@ -0,0 +1,28 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
one two three<emoji>😊</emoji>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@ -0,0 +1,20 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
one two three
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = input
|
@ -0,0 +1,28 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
one two three
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function(change) {
|
||||
change.deleteLineForward()
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
one two thr<cursor />ee
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
one two thr<cursor />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user