Skip to content

Commit e26b657

Browse files
committed
Upserting target instead of inserting on Shift up
1 parent 9461812 commit e26b657

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/text-annotator/src/SelectionHandler.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,18 @@ export const SelectionHandler = (
230230
// Proper lifecycle management: clear selection first...
231231
selection.clear();
232232

233-
// ...then add annotation to store...
234-
store.addAnnotation({
235-
id: currentTarget.annotation,
236-
bodies: [],
237-
target: currentTarget
238-
});
233+
const exists = store.getAnnotation(currentTarget.annotation);
234+
if (exists) {
235+
// ...then add annotation to store...
236+
store.updateTarget(currentTarget);
237+
} else {
238+
// ...then add annotation to store...
239+
store.addAnnotation({
240+
id: currentTarget.annotation,
241+
bodies: [],
242+
target: currentTarget
243+
});
244+
}
239245

240246
// ...then make the new annotation the current selection
241247
selection.userSelect(currentTarget.annotation, cloneKeyboardEvent(evt));

0 commit comments

Comments
 (0)