Skip to content

Commit

Permalink
fix(portable-text-editor): all paths must be checked (#5891)
Browse files Browse the repository at this point in the history
* fix(portable-text-editor): all paths must be checked

This optimization was a bit too optimistic.
It's causing issues with some type of selections.
Check every path here.

* fix(portable-text-editor): allow uncollapsed ranges

Uncollapsed ranges must be allowed as they may be pointing to empty blocks
  • Loading branch information
skogsmaskin authored Mar 4, 2024
1 parent ed87e2a commit 4ae88a0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/@sanity/portable-text-editor/src/editor/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
const newSlateRanges: BaseRangeWithDecoration[] = []
rangeDecorations.forEach((rangeDecorationItem) => {
const slateRange = toSlateRange(rangeDecorationItem.selection, slateEditor)
if (!SlateRange.isRange(slateRange) || !SlateRange.isExpanded(slateRange)) {
if (!SlateRange.isRange(slateRange)) {
if (rangeDecorationItem.onMoved) {
rangeDecorationItem.onMoved({
newSelection: null,
Expand Down Expand Up @@ -574,9 +574,7 @@ export const PortableTextEditable = forwardRef(function PortableTextEditable(
},
]
}
const result = rangeDecorationState.filter(
(item) => path.length > 1 && SlateRange.includes(item, path),
)
const result = rangeDecorationState.filter((item) => SlateRange.includes(item, path))
if (result.length > 0) {
return result
}
Expand Down

0 comments on commit 4ae88a0

Please sign in to comment.