@@ -98,15 +98,6 @@ if (!iconCopy) {
9898
9999const codeCellId = ( index : number , prefix : string ) => `${ prefix } ${ index } `
100100
101- // Clears selected text since ClipboardJS will select the text when copying
102- const clearSelection = ( ) => {
103- if ( window . getSelection ) {
104- window . getSelection ( ) . removeAllRanges ( )
105- } else if ( 'selection' in document ) {
106- ; ( document . selection as Selection ) . empty ( )
107- }
108- }
109-
110101// Changes tooltip text for a moment, then changes it back
111102// We want the timeout of our `success` class to be a bit shorter than the
112103// tooltip and icon change, so that we can hide the icon before changing back.
@@ -130,7 +121,11 @@ const temporarilyChangeIcon = (el) => {
130121 } , timeoutIcon )
131122}
132123
133- const addCopyButtonToCodeCells = ( selector : string , baseElement : ParentNode , prefix : string ) => {
124+ const addCopyButtonToCodeCells = (
125+ selector : string ,
126+ baseElement : ParentNode ,
127+ prefix : string
128+ ) => {
134129 // If ClipboardJS hasn't loaded, wait a bit and try again. This
135130 // happens because we load ClipboardJS asynchronously.
136131
@@ -148,11 +143,10 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
148143 clipboardButton . setAttribute ( 'data-tooltip' , messages [ locale ] [ 'copy' ] )
149144 clipboardButton . setAttribute ( 'data-clipboard-target' , `#${ id } ` )
150145 clipboardButton . innerHTML = iconCopy
151- clipboardButton . onclick = async ( event ) => {
146+ clipboardButton . onclick = async ( ) => {
152147 try {
153148 const text = copyTargetText ( clipboardButton , baseElement )
154149 await navigator . clipboard . writeText ( text )
155-
156150 temporarilyChangeTooltip (
157151 clipboardButton ,
158152 messages [ locale ] [ 'copy' ] ,
@@ -163,7 +157,7 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
163157 console . error ( error )
164158 }
165159 }
166-
160+
167161 codeCell . insertAdjacentElement ( 'afterend' , clipboardButton )
168162 } )
169163
@@ -277,6 +271,10 @@ const addCopyButtonToCodeCells = (selector: string, baseElement: ParentNode, pre
277271 // })
278272}
279273
280- export function initCopyButton ( selector : string = '.highlight pre' , baseElement : ParentNode = document , prefix : string = 'markdown-content-codecell-' ) {
274+ export function initCopyButton (
275+ selector : string = '.highlight pre' ,
276+ baseElement : ParentNode = document ,
277+ prefix : string = 'markdown-content-codecell-'
278+ ) {
281279 addCopyButtonToCodeCells ( selector , baseElement , prefix )
282280}
0 commit comments