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

deleteBackwardAtRange now works when offset is equal to n (#2966)

* deleteBackwardAtRange now works when offset is equal to n
Closes #2965

* Adds test to verify behaviour of `deleteBackwardAtRange` when offset===length
This commit is contained in:
kay delaney
2019-08-22 03:41:21 +01:00
committed by Ian Storm Taylor
parent 1aa1783c9c
commit 9c2d55e800
2 changed files with 39 additions and 1 deletions

View File

@@ -367,7 +367,7 @@ Commands.deleteBackwardAtRange = (editor, range, n = 1) => {
// If the focus offset is farther than the number of characters to delete,
// just remove the characters backwards inside the current node.
if (n < focus.offset) {
if (n <= focus.offset) {
range = range.moveFocusBackward(n)
editor.deleteAtRange(range)
return

View File

@@ -0,0 +1,38 @@
/** @jsx h */
import { Point, Range } from 'slate'
import h from '../../../helpers/h'
export default function(editor) {
const { key } = editor.value.document.getFirstText()
const range = new Range({
anchor: new Point({ key, offset: 2, path: [key] }),
focus: new Point({ key, offset: 2, path: [key] }),
})
editor.deleteBackwardAtRange(range, 2)
}
export const input = (
<value>
<document>
<paragraph>
<paragraph>
Sample <cursor />Text
</paragraph>
</paragraph>
</document>
</value>
)
export const output = (
<value>
<document>
<paragraph>
<paragraph>
mple <cursor />Text
</paragraph>
</paragraph>
</document>
</value>
)