mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 12:14:14 +02:00
Allow deleteAtRange with a zero-length range on the first character (#2800)
deleteAtRange will consider a zero-length range on the first character of a text node as a hanging selection, which is incorrect. This should not be considered hanging. It's still possible to hit the `startKey === endKey && isHanging` conditional if endKey is in a void node, since we will bump the selection to the previous node and update endKey (but then endOffset is no longer 0, so it's not _really_ hanging anymore). We have an existing test for that, and it still passes after this change.
This commit is contained in:
committed by
Ian Storm Taylor
parent
09f4662d31
commit
559bde9a21
@@ -114,7 +114,8 @@ Commands.deleteAtRange = (editor, range) => {
|
|||||||
endOffset === 0 &&
|
endOffset === 0 &&
|
||||||
isStartVoid === false &&
|
isStartVoid === false &&
|
||||||
startKey === startBlock.getFirstText().key &&
|
startKey === startBlock.getFirstText().key &&
|
||||||
endKey === endBlock.getFirstText().key
|
endKey === endBlock.getFirstText().key &&
|
||||||
|
startKey !== endKey
|
||||||
|
|
||||||
// If it's a hanging selection, nudge it back to end in the previous text.
|
// If it's a hanging selection, nudge it back to end in the previous text.
|
||||||
if (isHanging && isEndVoid) {
|
if (isHanging && isEndVoid) {
|
||||||
|
@@ -0,0 +1,29 @@
|
|||||||
|
/** @jsx h */
|
||||||
|
|
||||||
|
import h from '../../../helpers/h'
|
||||||
|
|
||||||
|
export default function(editor) {
|
||||||
|
editor.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
<cursor />
|
||||||
|
word
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<value>
|
||||||
|
<document>
|
||||||
|
<paragraph>
|
||||||
|
<cursor />
|
||||||
|
word
|
||||||
|
</paragraph>
|
||||||
|
</document>
|
||||||
|
</value>
|
||||||
|
)
|
Reference in New Issue
Block a user