mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-11-30 16:37:18 +01:00
For text selection we use some document-global event handlers to detect when selection finishes: we cannot have them be limited to the viewer container because one might start selection in the container but then move the mouse outside of it before releasing it. The global event listener will then "dispatch" the event response to the correct `TextLayerBuilder`. The global event listener was using the `AbortSignal` from the first TextLayerBuilder that registered it: if two builders have two different signals, destroying the first one would remove the global event listener that is still needed by the second one. This commit fixes the problem by manually listening to the TextLayerBuilder's own abortSignal, and when it's cancelled only remove the global event listener if there is no other TextLayerBuilder that still needs it.