From 611fa85b807d6fc31dc9d00d34ac460f08c8a291 Mon Sep 17 00:00:00 2001 From: Slapbox Date: Wed, 24 Oct 2018 18:46:01 -0400 Subject: [PATCH] Fixes deleteWordForward at line ending (#2290) #### Is this adding or improving a _feature_ or fixing a _bug_? Bug fix - Very minor change #### What's the new behavior? `deleteWordBackward` at line ending behaves the same as `deleteCharForward` #### How does this change work? If `TextUtils.getWordOffsetForward(text, o)` returns 0, instead we substitute in `1` to delete the line break and join the blocks. The relevant test for this change (`join-blocks`) is also added. #### Have you checked that...? * [x] The new code matches the existing patterns and styles. * [x] The tests pass with `yarn test`. * [x] The linter passes with `yarn lint`. (Fix errors with `yarn prettier`.) * [x] The relevant examples still work. (Run examples with `yarn watch`.) #### Does this fix any issues or need any specific reviewers? Fixes: #2258 Reviewers: @ianstormtaylor --- packages/slate/src/commands/at-range.js | 3 +- .../delete-word-forward/join-blocks.js | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 574e2c8da..ed2b598b1 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -455,7 +455,8 @@ Commands.deleteWordForwardAtRange = (change, range) => { const offset = startBlock.getOffset(start.key) const o = offset + start.offset const { text } = startBlock - const n = TextUtils.getWordOffsetForward(text, o) + const wordOffset = TextUtils.getWordOffsetForward(text, o) + const n = wordOffset === 0 ? 1 : wordOffset change.deleteForwardAtRange(range, n) } diff --git a/packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js b/packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js new file mode 100644 index 000000000..2651be7fa --- /dev/null +++ b/packages/slate/test/commands/at-current-range/delete-word-forward/join-blocks.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(change) { + change.deleteWordForward() +} + +export const input = ( + + + + word + + another + + +) + +export const output = ( + + + + wordanother + + + +)