Skip to content

Commit 2deebb1

Browse files
authoredFeb 29, 2024
fix(portable-text-editor): check that path is lengthy (#5875)
* fix(portable-text-editor): check that path is lengthy Empty paths should not be returned, as it doesn't make sense and leads to bugs. * test(portable-text-editor): fix failing test
1 parent fc73437 commit 2deebb1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
 

‎packages/@sanity/portable-text-editor/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {PortableTextEditor} from '../../PortableTextEditor'
99
const INITIAL_VALUE: PortableTextBlock[] = [
1010
{
1111
_key: 'a',
12-
_type: 'block',
12+
_type: 'myTestBlockType',
1313
children: [
1414
{
1515
_key: 'a1',

‎packages/@sanity/portable-text-editor/src/utils/ranges.ts

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export function toSlateRange(selection: EditorSelection, editor: Editor): Range
5353
path: createArrayedPath(selection.focus, editor),
5454
offset: selection.focus.offset,
5555
}
56+
if (focus.path.length === 0 || anchor.path.length === 0) {
57+
return null
58+
}
5659
const range = anchor && focus ? {anchor, focus} : null
5760
return range
5861
}

0 commit comments

Comments
 (0)
Please sign in to comment.