Skip to content

Commit

Permalink
fix(comments): allow ranges to be collapsed (#5892)
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

* fix(comments): allow ranges to be collapsed

This is needed to support including empty blocks within the commented range
  • Loading branch information
skogsmaskin committed Mar 4, 2024
1 parent 4ae88a0 commit eb5cd50
Showing 1 changed file with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,26 @@ export function buildRangeDecorationSelectionsFromComments(
break
}
}
// If range is now collapsed, don't create a decoration
if (anchorOffset === focusOffset && childIndexFocus === childIndexAnchor) {
nullSelection = true
}

decorators.push({
selection: nullSelection
? null
: {
anchor: {
path: [
{_key: matchedBlock._key},
'children',
{_key: matchedBlock.children[childIndexAnchor]._key},
],
offset: anchorOffset,
},
focus: {
path: [
{_key: matchedBlock._key},
'children',
{_key: matchedBlock.children[childIndexFocus]._key},
],
offset: focusOffset,
},
},
selection: {
anchor: {
path: [
{_key: matchedBlock._key},
'children',
{_key: matchedBlock.children[childIndexAnchor]._key},
],
offset: anchorOffset,
},
focus: {
path: [
{_key: matchedBlock._key},
'children',
{_key: matchedBlock.children[childIndexFocus]._key},
],
offset: focusOffset,
},
},
comment,
range: {_key: matchedBlock._key, text: nullSelection ? '' : diffedText},
})
Expand Down

0 comments on commit eb5cd50

Please sign in to comment.