From 490498f2285e9834c7e3f084bb424a93abf4255f Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Tue, 22 Nov 2016 16:56:22 -0800 Subject: [PATCH] refactor splitBlock --- src/transforms/at-current-range.js | 38 +++++------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/src/transforms/at-current-range.js b/src/transforms/at-current-range.js index 2eeccea38..bf4802309 100644 --- a/src/transforms/at-current-range.js +++ b/src/transforms/at-current-range.js @@ -218,38 +218,12 @@ export function setInline(transform, properties) { export function splitBlock(transform, depth = 1) { let { state } = transform - let { document, selection } = state - - transform.unsetSelection() - transform.splitBlockAtRange(selection, depth) - - state = transform.state - document = state.document - - const { startKey, startOffset } = selection - const startText = document.getNode(startKey) - const startBlock = document.getClosestBlock(startKey) - const startInline = startBlock.getFurthestInline(startKey) - const nextText = document.getNextText(startText.key) - let after - - // If the selection is at the start of the highest inline child inside the - // block, the starting text node won't need to be split. - if ( - (startOffset == 0) && - (startBlock.text != '') && - (!startInline || startInline.getOffset(startText.key) == 0) - ) { - after = selection.collapseToStartOf(startText) - } - - // Otherwise, we'll need to move the selection forward one to account for the - // text node that was split. - else { - after = selection.collapseToStartOf(nextText) - } - - transform.moveTo(after) + let { selection } = state + transform + .snapshotSelection() + .splitBlockAtRange(selection, depth) + .collapseToEnd() + .snapshotSelection() } /**