From 0edcc8969283b87350d4fe4d9a0bcbfe96967cb9 Mon Sep 17 00:00:00 2001 From: Charley DAVID Date: Mon, 19 Aug 2019 18:17:07 +0200 Subject: [PATCH] Fix splitNode range updates when selection is backward (#2938) --- packages/slate/src/models/value.js | 14 ++++----- .../remove-mark/part-of-mark-backward.js | 30 +++++++++++++++++++ .../remove-mark/part-of-mark.js | 30 +++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 packages/slate/test/commands/at-current-range/remove-mark/part-of-mark-backward.js create mode 100644 packages/slate/test/commands/at-current-range/remove-mark/part-of-mark.js diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index f74414fc0a..02884c3c51 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -799,16 +799,16 @@ class Value extends Record(DEFAULTS) { value = value.mapRanges(range => { const next = newDocument.getNextText(node.key) - const { start, end } = range + const { anchor, focus } = range - // If the start was after the split, move it to the next node. - if (node.key === start.key && position <= start.offset) { - range = range.moveStartTo(next.key, start.offset - position) + // If the anchor was after the split, move it to the next node. + if (node.key === anchor.key && position <= anchor.offset) { + range = range.moveAnchorTo(next.key, anchor.offset - position) } - // If the end was after the split, move it to the next node. - if (node.key === end.key && position <= end.offset) { - range = range.moveEndTo(next.key, end.offset - position) + // If the focus was after the split, move it to the next node. + if (node.key === focus.key && position <= focus.offset) { + range = range.moveFocusTo(next.key, focus.offset - position) } range = range.updatePoints(point => point.setPath(null)) diff --git a/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark-backward.js b/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark-backward.js new file mode 100644 index 0000000000..c23513da89 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark-backward.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.removeMark('bold') +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wor + d + + + +) diff --git a/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark.js b/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark.js new file mode 100644 index 0000000000..f83f87662c --- /dev/null +++ b/packages/slate/test/commands/at-current-range/remove-mark/part-of-mark.js @@ -0,0 +1,30 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.removeMark('bold') +} + +export const input = ( + + + + + word + + + + +) + +export const output = ( + + + + wor + d + + + +)