Skip to content

Commit 1c34de0

Browse files
committed
Fixed another edge case?
1 parent 0ed6325 commit 1c34de0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/text-annotator/src/SelectionHandler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const SelectionHandler = (
9595
* But rich text editors like Quill will do it!
9696
*/
9797
if (!selectionRanges.some(r => r.intersectsNode(container))) {
98-
// currentTarget = undefined;
98+
currentTarget = undefined;
9999
return;
100100
}
101101

@@ -117,8 +117,19 @@ export const SelectionHandler = (
117117
}
118118
}
119119

120+
// Note: commenting out the line below. We should no longer do this. Why?
121+
// Let's assume the user drags the selection from outside the annotatable area
122+
// over the anntoatable area (intersection!). Then drags it out again
123+
// (no intersection!), then in again (intersection). Because the
124+
// currentTarget will have been cleared meanwhile, execution will stop.
125+
//
126+
// But we don't want this - instead, processing should continue as normal,
127+
// and a new currentTarget should be computed when the user drags the
128+
// selection into the annotatable area a second time.
129+
120130
// The selection isn't active -> bail out from selection change processing
121-
if (!currentTarget) return;
131+
// if (!currentTarget) return;
132+
if (!currentTarget) onSelectStart();
122133

123134
if (sel.isCollapsed) {
124135
/**
@@ -144,6 +155,7 @@ export const SelectionHandler = (
144155
const annotatableRanges = containedRanges.flatMap(r => splitAnnotatableRanges(container, r.cloneRange()));
145156

146157
const hasChanged =
158+
(annotatableRanges.length > 0 && !currentTarget) ||
147159
annotatableRanges.length !== currentTarget.selector.length ||
148160
annotatableRanges.some((r, i) => r.toString() !== currentTarget.selector[i]?.quote);
149161

0 commit comments

Comments
 (0)