From 559bde9a213547a643e103b5de3bac4e8e35ce5c Mon Sep 17 00:00:00 2001 From: Justin Weiss Date: Mon, 20 May 2019 13:18:31 -0700 Subject: [PATCH] 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. --- packages/slate/src/commands/at-range.js | 3 +- .../at-current-range/delete/first-position.js | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/slate/test/commands/at-current-range/delete/first-position.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 04d3e95e0..52d92bd94 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -114,7 +114,8 @@ Commands.deleteAtRange = (editor, range) => { endOffset === 0 && isStartVoid === false && 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 (isHanging && isEndVoid) { diff --git a/packages/slate/test/commands/at-current-range/delete/first-position.js b/packages/slate/test/commands/at-current-range/delete/first-position.js new file mode 100644 index 000000000..076680879 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete/first-position.js @@ -0,0 +1,29 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.delete() +} + +export const input = ( + + + + + word + + + +) + +export const output = ( + + + + + word + + + +)