Skip to content

Commit

Permalink
Fix error breaking annotation interaction when resize range is invalid
Browse files Browse the repository at this point in the history
And align range validity check in handlePointerMove() with the one in
_getAnnotationFromRange() by rejecting ranges containing only whitespace.

https://forums.zotero.org/discussion/106961/zotero-7-select-space-problems
  • Loading branch information
AbeJellinek committed Aug 16, 2023
1 parent c26e1bb commit 35ff811
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/dom/common/components/overlay/annotation-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export const AnnotationOverlay: React.FC<AnnotationOverlayProps> = (props) => {
}, [onDragStart]);

let handleResizeStart = useCallback((annotation: DisplayedAnnotation) => {
onResizeStart(annotation.id!);
setResizing(true);
onResizeStart(annotation.id!);
}, [onResizeStart]);

let handleResizeEnd = useCallback((annotation: DisplayedAnnotation, range: Range, cancelled: boolean) => {
onResizeEnd(annotation.id!, range, cancelled);
setResizing(false);
onResizeEnd(annotation.id!, range, cancelled);
}, [onResizeEnd]);

let widgetContainer = useRef<SVGSVGElement>(null);
Expand Down Expand Up @@ -563,11 +563,11 @@ const Resizer: React.FC<ResizerProps> = (props) => {
}

if (newRange.collapsed
|| !newRange.toString().length
|| newRange.getClientRects().length == 0
// Make sure we stay within one section
|| doc?.querySelector('[data-section-index]')
&& !closestElement(newRange.commonAncestorContainer)?.closest('[data-section-index]')) {
|| !newRange.toString().trim().length
|| newRange.getClientRects().length == 0
// Make sure we stay within one section
|| doc?.querySelector('[data-section-index]')
&& !closestElement(newRange.commonAncestorContainer)?.closest('[data-section-index]')) {
return;
}
let boundingRect = newRange.getBoundingClientRect();
Expand Down

0 comments on commit 35ff811

Please sign in to comment.