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:
committed by
Ian Storm Taylor
parent
1aa1783c9c
commit
9c2d55e800
@@ -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
|
||||
|
@@ -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>
|
||||
)
|
Reference in New Issue
Block a user