mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-07-31 20:40:19 +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:
committed by
Ian Storm Taylor
parent
727a7ece26
commit
1383b38546
@@ -334,6 +334,7 @@ Changes.deleteWordBackwardAtRange = (change, range, options) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Changes.deleteBackwardAtRange = (change, range, n = 1, options = {}) => {
|
Changes.deleteBackwardAtRange = (change, range, n = 1, options = {}) => {
|
||||||
|
if (n === 0) return
|
||||||
const normalize = change.getFlag('normalize', options)
|
const normalize = change.getFlag('normalize', options)
|
||||||
const { value } = change
|
const { value } = change
|
||||||
const { document } = value
|
const { document } = value
|
||||||
@@ -467,7 +468,7 @@ Changes.deleteLineForwardAtRange = (change, range, options) => {
|
|||||||
const startBlock = document.getClosestBlock(startKey)
|
const startBlock = document.getClosestBlock(startKey)
|
||||||
const offset = startBlock.getOffset(startKey)
|
const offset = startBlock.getOffset(startKey)
|
||||||
const o = offset + startOffset
|
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 = {}) => {
|
Changes.deleteForwardAtRange = (change, range, n = 1, options = {}) => {
|
||||||
|
if (n === 0) return
|
||||||
const normalize = change.getFlag('normalize', options)
|
const normalize = change.getFlag('normalize', options)
|
||||||
const { value } = change
|
const { value } = change
|
||||||
const { document } = value
|
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>
|
||||||
|
)
|
Reference in New Issue
Block a user