fixed #4483 - repeat keydown events affecting hotkeys

This commit is contained in:
Eugene Pankov 2021-08-27 20:02:32 +02:00
parent 2d331332a4
commit 7252f80573
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -63,7 +63,7 @@ export class HotkeysService {
private pressedHotkey: string|null = null private pressedHotkey: string|null = null
private pressedKeystroke: Keystroke|null = null private pressedKeystroke: Keystroke|null = null
private lastKeystrokes: PastKeystroke[] = [] private lastKeystrokes: PastKeystroke[] = []
private shouldSaveNextKeystroke = true private recognitionPhase = true
private lastEventTimestamp = 0 private lastEventTimestamp = 0
private constructor ( private constructor (
@ -130,18 +130,20 @@ export class HotkeysService {
const keyName = getKeyName(eventData) const keyName = getKeyName(eventData)
if (eventName === 'keydown') { if (eventName === 'keydown') {
this.addPressedKey(keyName, eventData) this.addPressedKey(keyName, eventData)
this.shouldSaveNextKeystroke = true if (!nativeEvent.repeat) {
this.recognitionPhase = true
}
this.updateModifiers(eventData) this.updateModifiers(eventData)
} }
if (eventName === 'keyup') { if (eventName === 'keyup') {
const keystroke = getKeystrokeName([...this.pressedKeys]) const keystroke = getKeystrokeName([...this.pressedKeys])
if (this.shouldSaveNextKeystroke) { if (this.recognitionPhase) {
this._keystroke.next(keystroke) this._keystroke.next(keystroke)
this.lastKeystrokes.push({ this.lastKeystrokes.push({
keystroke, keystroke,
time: performance.now(), time: performance.now(),
}) })
this.shouldSaveNextKeystroke = false this.recognitionPhase = false
} }
this.removePressedKey(keyName) this.removePressedKey(keyName)
} }
@ -154,7 +156,7 @@ export class HotkeysService {
const matched = this.matchActiveHotkey() const matched = this.matchActiveHotkey()
this.zone.run(() => { this.zone.run(() => {
if (matched) { if (matched && this.recognitionPhase) {
this.emitHotkeyOn(matched) this.emitHotkeyOn(matched)
} else if (this.pressedHotkey) { } else if (this.pressedHotkey) {
this.emitHotkeyOff(this.pressedHotkey) this.emitHotkeyOff(this.pressedHotkey)