File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
packages/text-annotator/src Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,19 @@ export const SelectionHandler = (
7575 const onSelectionChange = debounce ( ( evt : Event ) => {
7676 const sel = document . getSelection ( ) ;
7777
78+ /**
79+ * In iOS when a user clicks on a button, the `selectionchange` event is fired.
80+ * However, the generated selection is empty and the `anchorNode` is `null`.
81+ * That doesn't give us information about whether the selection is in the annotatable area
82+ * or whether the previously selected text was dismissed.
83+ * Therefore - we should bail out from such a range processing.
84+ *
85+ * @see https://github.com/recogito/text-annotator-js/pull/164#issuecomment-2416961473
86+ */
87+ if ( ! sel ?. anchorNode ) {
88+ return ;
89+ }
90+
7891 /**
7992 * This is to handle cases where the selection is "hijacked"
8093 * by another element in a not-annotatable area.
@@ -189,7 +202,7 @@ export const SelectionHandler = (
189202 const currentIds = new Set ( selected . map ( s => s . id ) ) ;
190203 const nextIds = Array . isArray ( hovered ) ? hovered . map ( a => a . id ) : [ hovered . id ] ;
191204
192- const hasChanged =
205+ const hasChanged =
193206 currentIds . size !== nextIds . length ||
194207 ! nextIds . every ( id => currentIds . has ( id ) ) ;
195208
You can’t perform that action at this time.
0 commit comments