Skip to content

Commit

Permalink
fix(portable-text-editor): check that path is lengthy (#5875)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
skogsmaskin authored Feb 29, 2024
1 parent fc73437 commit 2deebb1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {PortableTextEditor} from '../../PortableTextEditor'
const INITIAL_VALUE: PortableTextBlock[] = [
{
_key: 'a',
_type: 'block',
_type: 'myTestBlockType',
children: [
{
_key: 'a1',
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/portable-text-editor/src/utils/ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export function toSlateRange(selection: EditorSelection, editor: Editor): Range
path: createArrayedPath(selection.focus, editor),
offset: selection.focus.offset,
}
if (focus.path.length === 0 || anchor.path.length === 0) {
return null
}
const range = anchor && focus ? {anchor, focus} : null
return range
}

0 comments on commit 2deebb1

Please sign in to comment.