Skip to content

Commit

Permalink
fix(theme): keep display copied hint when click multiple times (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
CHOYSEN committed Aug 31, 2022
1 parent 12591a9 commit bb11d0f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/client/app/composables/copyCode.ts
Expand Up @@ -2,6 +2,7 @@ import { inBrowser } from '../utils.js'

export function useCopyCode() {
if (inBrowser) {
const timeoutIdMap: Map<HTMLElement, number> = new Map()
window.addEventListener('click', (e) => {
const el = e.target as HTMLElement
if (el.matches('div[class*="language-"] > button.copy')) {
Expand All @@ -24,10 +25,13 @@ export function useCopyCode() {

copyToClipboard(text).then(() => {
el.classList.add('copied')
setTimeout(() => {
clearTimeout(timeoutIdMap.get(el))
const timeoutId = setTimeout(() => {
el.classList.remove('copied')
el.blur()
timeoutIdMap.delete(el)
}, 2000)
timeoutIdMap.set(el, timeoutId)
})
}
})
Expand Down

0 comments on commit bb11d0f

Please sign in to comment.