Skip to content

Commit

Permalink
fix: hide cursor conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 28, 2024
1 parent e434c9d commit 777d27d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/client/composables/useHideCursorIdle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Ref } from 'vue'
import { useEventListener } from '@vueuse/core'
import { computed } from 'vue'
import { computed, watch } from 'vue'
import { hideCursorIdle } from '../state'

const TIMEOUT = 2000
Expand All @@ -19,15 +19,24 @@ export function useHideCursorIdle(

let timer: ReturnType<typeof setTimeout> | null = null

// If disabled, immediately show the cursor
watch(
shouldHide,
(value) => {
if (!value)
show()
},
)

useEventListener(
document.body,
['pointermove', 'pointerdown'],
() => {
show()
if (!shouldHide.value)
return
if (timer)
clearTimeout(timer)
if (!shouldHide.value)
return
timer = setTimeout(hide, TIMEOUT)
},
{ passive: true },
Expand Down

0 comments on commit 777d27d

Please sign in to comment.