From f83b3114db7df7065b1c6ec82773b898f72cea77 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Thu, 19 Jul 2018 20:07:22 +0100 Subject: [PATCH] rebuild selection from anchorPath and focusPath if keys were dropped (#1980) --- packages/slate/src/models/value.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/slate/src/models/value.js b/packages/slate/src/models/value.js index b5af7a2ad..e7fe465fb 100644 --- a/packages/slate/src/models/value.js +++ b/packages/slate/src/models/value.js @@ -100,6 +100,18 @@ class Value extends Record(DEFAULTS) { let data = new Map() document = Document.fromJSON(document) + + // rebuild selection from anchorPath and focusPath if keys were dropped + const { anchorPath, focusPath, anchorKey, focusKey } = selection + + if (anchorPath !== undefined && anchorKey === undefined) { + selection.anchorKey = document.assertPath(anchorPath).key + } + + if (focusPath !== undefined && focusKey === undefined) { + selection.focusKey = document.assertPath(focusPath).key + } + selection = Range.fromJSON(selection) schema = Schema.fromJSON(schema)