Skip to content

Commit

Permalink
fix(structure): console error for when selection is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Apr 16, 2024
1 parent 5f61cfe commit 7c7bce3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/sanity/src/structure/comments/plugin/input/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ export function useAuthoringReferenceElement(
export function getSelectionBoundingRect(): DOMRect | null {
const selection = window.getSelection()
let range = null
try {
range = selection?.getRangeAt(0)
} catch (error) {
console.error('Unable to get selection rect for portable text comment input', error)

if (selection && selection.rangeCount > 0) {
try {
range = selection?.getRangeAt(0)
} catch (error) {
console.error('Unable to get selection rect for portable text comment input', error)
}
}
const rect = range?.getBoundingClientRect()

Expand Down

0 comments on commit 7c7bce3

Please sign in to comment.