@@ -8,6 +8,8 @@ let spacePressed = false
88let altPressed = false
99let duplicateClass : string | null = null
1010let classSnapshot = new Set < string > ( )
11+ const cursorHost = shallowRef < HTMLElement | null > ( null )
12+ const canvas = shallowRef < HTMLElement | null > ( null )
1113const DUPLICATE_URL_SIGNATURE =
1214 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAIZElEQVR4AeyYTWxUVRTH3yD9UCEE'
1315function extractHotspot ( cursor : string ) : [ number , number ] | null {
@@ -28,20 +30,24 @@ function pause() {
2830 setLockAltKey ( false )
2931}
3032
33+ function isCanvasHovered ( ) {
34+ return ! ! canvas . value ?. matches ( ':hover' )
35+ }
36+
3137function resume ( ) {
32- if ( spacePressed ) {
38+ if ( spacePressed || ! isCanvasHovered ( ) ) {
3339 return
3440 }
35- setLockMetaKey ( options . value . deepSelectOn )
41+ syncMetaLock ( )
3642 syncAltLock ( )
3743}
3844
3945function pauseMeasure ( ) {
4046 setLockAltKey ( false )
4147}
4248
43- function resumeMeasure ( ) {
44- syncAltLock ( )
49+ function pauseDeepSelect ( ) {
50+ setLockMetaKey ( false )
4551}
4652
4753let resuming : number | null = null
@@ -55,7 +61,7 @@ function pauseMetaThenResume() {
5561 resuming = setTimeout ( ( ) => {
5662 resuming = null
5763 if ( ! spacePressed ) {
58- setLockMetaKey ( options . value . deepSelectOn )
64+ syncMetaLock ( )
5965 }
6066 } , 200 )
6167}
@@ -97,7 +103,13 @@ function keyup(e: KeyboardEvent) {
97103}
98104
99105function syncAltLock ( ) {
100- setLockAltKey ( ! altPressed && options . value . measureOn )
106+ const hovered = isCanvasHovered ( )
107+ setLockAltKey ( hovered && ! altPressed && options . value . measureOn )
108+ }
109+
110+ function syncMetaLock ( ) {
111+ const hovered = isCanvasHovered ( )
112+ setLockMetaKey ( hovered && options . value . deepSelectOn )
101113}
102114
103115function isDuplicateCursor ( host : HTMLElement ) {
@@ -125,8 +137,6 @@ function clearCursorCover(host: HTMLElement) {
125137 delete host . dataset . tpCursorOverride
126138}
127139
128- const cursorHost = shallowRef < HTMLElement | null > ( null )
129-
130140function reconcileCursor ( host ?: HTMLElement | null ) {
131141 const target = host ?? cursorHost . value
132142 if ( ! target ) return
@@ -145,8 +155,6 @@ function reconcileCursor(host?: HTMLElement | null) {
145155}
146156
147157export function useKeyLock ( ) {
148- const canvas = shallowRef < HTMLElement | null > ( null )
149-
150158 function syncTargets ( ) {
151159 canvas . value = getCanvas ( )
152160 cursorHost . value = canvas . value ?. parentElement ?. parentElement as HTMLElement | null
@@ -163,7 +171,7 @@ export function useKeyLock() {
163171 ( ready ) => {
164172 if ( ready ) {
165173 syncTargets ( )
166- setLockMetaKey ( options . value . deepSelectOn )
174+ syncMetaLock ( )
167175 syncAltLock ( )
168176 reconcileCursor ( cursorHost . value )
169177 return
@@ -181,7 +189,10 @@ export function useKeyLock() {
181189 useEventListener ( canvas , 'mouseleave' , pause )
182190 useEventListener ( canvas , 'mouseenter' , resume )
183191 useEventListener ( canvas , 'pointerdown' , pauseMeasure , { capture : true } )
184- useEventListener ( 'pointerup' , resumeMeasure , { capture : true } )
192+ useEventListener ( canvas , 'pointerdown' , ( ) => {
193+ setTimeout ( pauseDeepSelect , 0 )
194+ } )
195+ useEventListener ( 'pointerup' , resume , { capture : true } )
185196 useEventListener ( canvas , 'wheel' , pauseMetaThenResume )
186197 useEventListener ( 'keydown' , keydown )
187198 useEventListener ( 'keyup' , keyup )
@@ -204,7 +215,7 @@ export function useKeyLock() {
204215 ( ) => options . value . deepSelectOn ,
205216 ( ) => {
206217 if ( ! layoutReady . value ) return
207- setLockMetaKey ( options . value . deepSelectOn )
218+ syncMetaLock ( )
208219 }
209220 )
210221
0 commit comments