From 19ff35b779d5a93e9e2ea58570ceed65deeccfe9 Mon Sep 17 00:00:00 2001 From: fullex <106392080+0xfullex@users.noreply.github.com> Date: Thu, 5 Jun 2025 14:28:50 +0800 Subject: [PATCH] fix(SelectionAssistant): ignore ctrl pressing when user is zooming in/out (#6822) * fix(SelectionService): ignore ctrl pressing when user is zomming in/out * chore: rename function * fix: reset listener status --- src/main/services/SelectionService.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/services/SelectionService.ts b/src/main/services/SelectionService.ts index e4f33c2cf6..f785683b5a 100644 --- a/src/main/services/SelectionService.ts +++ b/src/main/services/SelectionService.ts @@ -304,7 +304,12 @@ export class SelectionService { if (!this.selectionHook) return false this.selectionHook.stop() - this.selectionHook.cleanup() + this.selectionHook.cleanup() //already remove all listeners + + //reset the listener states + this.isCtrlkeyListenerActive = false + this.isHideByMouseKeyListenerActive = false + if (this.toolbarWindow) { this.toolbarWindow.close() this.toolbarWindow = null @@ -836,6 +841,8 @@ export class SelectionService { //ctrlkey pressed if (this.lastCtrlkeyDownTime === 0) { this.lastCtrlkeyDownTime = Date.now() + //add the mouse-wheel listener, detect if user is zooming in/out + this.selectionHook!.on('mouse-wheel', this.handleMouseWheelCtrlkeyMode) return } @@ -859,9 +866,20 @@ export class SelectionService { */ private handleKeyUpCtrlkeyMode = (data: KeyboardEventData) => { if (!this.isCtrlkey(data.vkCode)) return + //remove the mouse-wheel listener + this.selectionHook!.off('mouse-wheel', this.handleMouseWheelCtrlkeyMode) this.lastCtrlkeyDownTime = 0 } + /** + * Handle mouse wheel events in ctrlkey trigger mode + * ignore CtrlKey pressing when mouse wheel is used + * because user is zooming in/out + */ + private handleMouseWheelCtrlkeyMode = () => { + this.lastCtrlkeyDownTime = -1 + } + //check if the key is ctrl key private isCtrlkey(vkCode: number) { return vkCode === 162 || vkCode === 163