From 220dd476e31a7a96cbc8e87fbf2fe41bb3745747 Mon Sep 17 00:00:00 2001 From: Dundercover Date: Mon, 5 Nov 2018 05:58:45 +0100 Subject: [PATCH] Check if inline ancestor exists before using it in wrapInlineAtRange (#2374) --- packages/slate/src/commands/at-range.js | 4 +++ ...lapsed-range-without-parent-void-inline.js | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js diff --git a/packages/slate/src/commands/at-range.js b/packages/slate/src/commands/at-range.js index 7b3501606..c730a949d 100644 --- a/packages/slate/src/commands/at-range.js +++ b/packages/slate/src/commands/at-range.js @@ -1268,6 +1268,10 @@ Commands.wrapInlineAtRange = (editor, range, inline) => { // Wrapping an inline void const inlineParent = document.getClosestInline(start.key) + if (!inlineParent) { + return + } + if (!editor.isVoid(inlineParent)) { return } diff --git a/packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js b/packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js new file mode 100644 index 000000000..15c54fb75 --- /dev/null +++ b/packages/slate/test/commands/at-current-range/wrap-inline/collapsed-range-without-parent-void-inline.js @@ -0,0 +1,27 @@ +/** @jsx h */ + +import h from '../../../helpers/h' + +export default function(editor) { + editor.wrapInline('hashtag') +} + +export const input = ( + + + + wd + + + +) + +export const output = ( + + + + wd + + + +)