11import type { Ref } from 'vue'
22
33import { useDebounceFn } from '@vueuse/core'
4+ import { uniq } from 'es-toolkit'
45import { reactive , ref , watch } from 'vue'
56
67import { LISTEN_KEY } from '../constants'
@@ -9,11 +10,9 @@ import { useTauriListen } from './useTauriListen'
910
1011import { useCatStore } from '@/stores/cat'
1112
12- type MouseButtonValue = 'Left' | 'Right' | 'Middle'
13-
1413interface MouseButtonEvent {
1514 kind : 'MousePress' | 'MouseRelease'
16- value : MouseButtonValue
15+ value : string
1716}
1817
1918interface MouseMoveValue {
@@ -44,7 +43,7 @@ function getSupportKeys() {
4443const supportKeys = getSupportKeys ( )
4544
4645export function useDevice ( ) {
47- const pressedMouses = ref < MouseButtonValue [ ] > ( [ ] )
46+ const pressedMouses = ref < string [ ] > ( [ ] )
4847 const mousePosition = reactive < MouseMoveValue > ( { x : 0 , y : 0 } )
4948 const pressedKeys = ref < string [ ] > ( [ ] )
5049 const catStore = useCatStore ( )
@@ -57,13 +56,19 @@ export function useDevice() {
5756 handleRelease ( pressedKeys , 'CapsLock' )
5857 } , 100 )
5958
60- const handlePress = < T > ( array : Ref < T [ ] > , value ?: T ) => {
59+ const handlePress = ( array : Ref < string [ ] > , value ?: string ) => {
6160 if ( ! value ) return
6261
63- array . value = [ ...new Set ( [ ...array . value , value ] ) ]
62+ if ( catStore . singleMode ) {
63+ array . value = array . value . filter ( ( item ) => {
64+ return item . endsWith ( 'Arrow' ) !== value . endsWith ( 'Arrow' )
65+ } )
66+ }
67+
68+ array . value = uniq ( array . value . concat ( value ) )
6469 }
6570
66- const handleRelease = < T > ( array : Ref < T [ ] > , value ?: T ) => {
71+ const handleRelease = ( array : Ref < string [ ] > , value ?: string ) => {
6772 if ( ! value ) return
6873
6974 array . value = array . value . filter ( item => item !== value )
0 commit comments