File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -556,9 +556,9 @@ function Highlighter(options = hhDefaultOptions) {
556556
557557 // Remove this Highlighter instance and its highlights
558558 this . removeHighlighter = ( ) => {
559- for ( const stylesheet of Object . values ( this . stylesheets ) ) if ( stylesheet . parentElement ) stylesheet . remove ( ) ;
560559 this . loadHighlights ( [ ] ) ;
561560 this . annotatableContainer . querySelectorAll ( '.hh-svg-background, .hh-selection-handle' ) . forEach ( el => el . remove ( ) )
561+ removeStylesheets ( this . stylesheets ) ;
562562 controller . abort ( ) ;
563563
564564 this . annotatableContainer . highlighter = undefined ;
@@ -1072,6 +1072,18 @@ function Highlighter(options = hhDefaultOptions) {
10721072 }
10731073 return stylesheet ;
10741074 }
1075+
1076+ // Remove CSS stylesheets
1077+ function removeStylesheets ( stylesheets ) {
1078+ for ( const stylesheet of Object . values ( stylesheets ) ) {
1079+ if ( supportsCssStylesheetApi ) {
1080+ const adoptedStylesheetIndex = document . adoptedStyleSheets . indexOf ( stylesheet ) ;
1081+ document . adoptedStyleSheets . splice ( adoptedStylesheetIndex , 1 ) ;
1082+ } else {
1083+ stylesheet . remove ( ) ;
1084+ }
1085+ }
1086+ }
10751087
10761088 // Restore the previous selection range in case the browser clears the selection
10771089 const getRestoredSelectionOrCaret = ( selection , pointerEvent = null ) => {
You can’t perform that action at this time.
0 commit comments