Skip to content

Commit eb5cd50

Browse files
authoredMar 4, 2024
fix(comments): allow ranges to be collapsed (#5892)
* 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
1 parent 4ae88a0 commit eb5cd50

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed
 

‎packages/sanity/src/structure/comments/src/utils/inline-comments/buildRangeDecorationSelectionsFromComments.ts

+19-24
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,26 @@ export function buildRangeDecorationSelectionsFromComments(
137137
break
138138
}
139139
}
140-
// If range is now collapsed, don't create a decoration
141-
if (anchorOffset === focusOffset && childIndexFocus === childIndexAnchor) {
142-
nullSelection = true
143-
}
140+
144141
decorators.push({
145-
selection: nullSelection
146-
? null
147-
: {
148-
anchor: {
149-
path: [
150-
{_key: matchedBlock._key},
151-
'children',
152-
{_key: matchedBlock.children[childIndexAnchor]._key},
153-
],
154-
offset: anchorOffset,
155-
},
156-
focus: {
157-
path: [
158-
{_key: matchedBlock._key},
159-
'children',
160-
{_key: matchedBlock.children[childIndexFocus]._key},
161-
],
162-
offset: focusOffset,
163-
},
164-
},
142+
selection: {
143+
anchor: {
144+
path: [
145+
{_key: matchedBlock._key},
146+
'children',
147+
{_key: matchedBlock.children[childIndexAnchor]._key},
148+
],
149+
offset: anchorOffset,
150+
},
151+
focus: {
152+
path: [
153+
{_key: matchedBlock._key},
154+
'children',
155+
{_key: matchedBlock.children[childIndexFocus]._key},
156+
],
157+
offset: focusOffset,
158+
},
159+
},
165160
comment,
166161
range: {_key: matchedBlock._key, text: nullSelection ? '' : diffedText},
167162
})

0 commit comments

Comments
 (0)
Please sign in to comment.