From f9b4be688364a32fb8a21ffd8cd5682e2e2e126a Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Mon, 29 Nov 2021 10:54:28 +1100 Subject: [PATCH] chore(web): refactor constructNullKeyEvent --- .../src/text/keyboardProcessor.ts | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/common/core/web/keyboard-processor/src/text/keyboardProcessor.ts b/common/core/web/keyboard-processor/src/text/keyboardProcessor.ts index 7be3c14c20..3c5d75be49 100644 --- a/common/core/web/keyboard-processor/src/text/keyboardProcessor.ts +++ b/common/core/web/keyboard-processor/src/text/keyboardProcessor.ts @@ -211,28 +211,25 @@ namespace com.keyman.text { } } - processNewContextEvent(device: utils.DeviceSpec, outputTarget: OutputTarget): RuleBehavior { - if(!this.activeKeyboard) { - return null; - } - let keyEvent = new KeyEvent(); + constructNullKeyEvent(device: utils.DeviceSpec): KeyEvent { + const keyEvent = new KeyEvent(); keyEvent.Lcode = 0; keyEvent.kName = ''; keyEvent.device = device; this.setSyntheticEventDefaults(keyEvent); - return this.keyboardInterface.processNewContextEvent(outputTarget, keyEvent); + return keyEvent; + } + + processNewContextEvent(device: utils.DeviceSpec, outputTarget: OutputTarget): RuleBehavior { + return this.activeKeyboard ? + this.keyboardInterface.processNewContextEvent(outputTarget, this.constructNullKeyEvent(device)) : + null; } processPostKeystroke(device: utils.DeviceSpec, outputTarget: OutputTarget): RuleBehavior { - if(!this.activeKeyboard) { - return null; - } - let keyEvent = new KeyEvent(); - keyEvent.Lcode = 0; - keyEvent.kName = ''; - keyEvent.device = device; - this.setSyntheticEventDefaults(keyEvent); - return this.keyboardInterface.processPostKeystroke(outputTarget, keyEvent); + return this.activeKeyboard ? + this.keyboardInterface.processPostKeystroke(outputTarget, this.constructNullKeyEvent(device)) : + null; } processKeystroke(keyEvent: KeyEvent, outputTarget: OutputTarget): RuleBehavior {