From cdf76ec53087413fc72f57e5bf06662cd679415e Mon Sep 17 00:00:00 2001 From: jahorton Date: Wed, 18 Mar 2020 15:18:16 +0700 Subject: [PATCH] refactor(web/engine): reworks use of embedded's keyman['oninserttext'] --- web/source/text/kbdInterface.ts | 8 -------- web/source/text/processor.ts | 12 ++++++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/web/source/text/kbdInterface.ts b/web/source/text/kbdInterface.ts index e91d3f23e6..ddd52c9869 100644 --- a/web/source/text/kbdInterface.ts +++ b/web/source/text/kbdInterface.ts @@ -832,11 +832,6 @@ namespace com.keyman.text { output(dn: number, outputTarget: OutputTarget, s:string): void { this.resetContextCache(); let keyman = com.keyman.singleton; - - // KeymanTouch for Android uses direct insertion of the character string - if('oninserttext' in keyman && !(outputTarget instanceof Mock)) { - keyman['oninserttext'](dn,s); - } outputTarget.saveProperties(); outputTarget.clearSelection(); @@ -1041,9 +1036,6 @@ namespace com.keyman.text { } this.output(1, outputTarget, ""); - if(outputTarget.getElement()) { - this.doInputEvent(outputTarget.getElement()); - } } /** diff --git a/web/source/text/processor.ts b/web/source/text/processor.ts index 51ff669060..77b403fde1 100644 --- a/web/source/text/processor.ts +++ b/web/source/text/processor.ts @@ -95,10 +95,6 @@ namespace com.keyman.text { } break; case Codes.keyCodes['K_ENTER']: - // Ensure the newline is forwarded when in an embedded context! It doesn't yet have its own specialized OutputTarget type. - if(keyman.isEmbedded && !quiet) { // Don't pass it along for Mocks, though. They're (currently) only used in predictive text. - keyman['oninserttext'](0, '\n'); - } outputTarget.handleNewlineAtCaret(); return '\n'; // We still return this, as it ensures we generate a rule-match. @@ -531,11 +527,19 @@ namespace com.keyman.text { DOMEventHandlers.states.changed = true; } } + + // -- All keystroke (and 'alternate') processing is now complete. Time to finalize everything! -- // Notify the ModelManager of new input - it's predictive text time! ruleBehavior.transcription.alternates = alternates; keyman.modelManager.predict(ruleBehavior.transcription); + // KMEA and KMEI (embedded mode) use direct insertion of the character string + if(keyman.isEmbedded) { + // A special embedded callback used to setup direct callbacks to app-native code. + keyman['oninserttext'](ruleTransform.deleteLeft, ruleTransform.insert, ruleTransform.deleteRight); + } + // Since this method now performs changes for 'default' keystrokes, synthetic 'change' event generation // belongs here, rather than only in interface.processKeystroke() as in versions pre-12. if(outputTarget.getElement()) {