From 736662f80838902f8560554fae704c13c5d8e227 Mon Sep 17 00:00:00 2001 From: Taro Shono Date: Mon, 4 Jul 2022 19:05:25 +0900 Subject: [PATCH] fix: `Path.previous()` dose not working when path is `null` (#5029) * fix: `Path.previous()` dose not working when path is `null` * feat: changeset add --- .changeset/nervous-cars-divide.md | 5 +++++ packages/slate/src/transforms/text.ts | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 .changeset/nervous-cars-divide.md diff --git a/.changeset/nervous-cars-divide.md b/.changeset/nervous-cars-divide.md new file mode 100644 index 000000000..e33141dad --- /dev/null +++ b/.changeset/nervous-cars-divide.md @@ -0,0 +1,5 @@ +--- +'slate': patch +--- + +fix: `Path.previous()` dose not working when path is `null` diff --git a/packages/slate/src/transforms/text.ts b/packages/slate/src/transforms/text.ts index 1fa4197ef..0fa942828 100644 --- a/packages/slate/src/transforms/text.ts +++ b/packages/slate/src/transforms/text.ts @@ -451,16 +451,18 @@ export const TextTransforms: TextTransforms = { if (!options.at) { let path - if (ends.length > 0) { - path = Path.previous(endRef.current!) - } else if (middles.length > 0) { - path = Path.previous(middleRef.current!) - } else { - path = Path.previous(startRef.current!) + if (ends.length > 0 && endRef.current) { + path = Path.previous(endRef.current) + } else if (middles.length > 0 && middleRef.current) { + path = Path.previous(middleRef.current) + } else if (startRef.current) { + path = Path.previous(startRef.current) } - const end = Editor.end(editor, path) - Transforms.select(editor, end) + if (path) { + const end = Editor.end(editor, path) + Transforms.select(editor, end) + } } startRef.unref()