From 4d974962996935f775dfc0e96794028a46c0e91e Mon Sep 17 00:00:00 2001 From: Slapbox Date: Tue, 7 Aug 2018 19:21:30 -0400 Subject: [PATCH] Fixes inability to deleteWordBackward at line start (#2046) * Adds Unicode LF character to line endings for clipboard plaintext This addresses https://github.com/ianstormtaylor/slate/issues/1932 * Fixes plaintext/unicode pastes not having line breaks * Removes stray spaces for Prettier * Refactors Value creation to save 4 lines * Allows for Ctrl+Backspace on line start Previously Ctrl+Backspace would do nothing instead of continuing on to the above block. * Tests that deleteWordBackwards joins lines properly --- packages/slate/src/changes/at-range.js | 2 +- .../delete-word-backward/join-blocks.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/slate/test/changes/at-current-range/delete-word-backward/join-blocks.js diff --git a/packages/slate/src/changes/at-range.js b/packages/slate/src/changes/at-range.js index f47796240..2f9420f5d 100644 --- a/packages/slate/src/changes/at-range.js +++ b/packages/slate/src/changes/at-range.js @@ -322,7 +322,7 @@ Changes.deleteWordBackwardAtRange = (change, range, options) => { const offset = startBlock.getOffset(start.key) const o = offset + start.offset const { text } = startBlock - const n = TextUtils.getWordOffsetBackward(text, o) + const n = o === 0 ? 1 : TextUtils.getWordOffsetBackward(text, o) change.deleteBackwardAtRange(range, n, options) } diff --git a/packages/slate/test/changes/at-current-range/delete-word-backward/join-blocks.js b/packages/slate/test/changes/at-current-range/delete-word-backward/join-blocks.js new file mode 100644 index 000000000..88075c003 --- /dev/null +++ b/packages/slate/test/changes/at-current-range/delete-word-backward/join-blocks.js @@ -0,0 +1,28 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(change) { + change.deleteWordBackward() +} + +export const input = ( + + + word + + another + + + +) + +export const output = ( + + + + wordanother + + + +)