From b2b088ac6e9285bbdf949fe2b87a9b86ca5c19b3 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Thu, 27 Jun 2024 10:22:43 +0700 Subject: [PATCH] fix(web): show reversion after backspace following key-based auto-apply --- .../src/text/prediction/predictionContext.ts | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/common/web/input-processor/src/text/prediction/predictionContext.ts b/common/web/input-processor/src/text/prediction/predictionContext.ts index 1f3c94d2fb..534b20b79b 100644 --- a/common/web/input-processor/src/text/prediction/predictionContext.ts +++ b/common/web/input-processor/src/text/prediction/predictionContext.ts @@ -23,7 +23,8 @@ export default class PredictionContext extends EventEmitter; private swallowPrediction: boolean = false; @@ -191,7 +192,7 @@ export default class PredictionContext extends EventEmitter { - //let keyman = com.keyman.singleton; + const recentAcceptCause = this.recentAcceptCause; - if(!this.recentAccept && this.selected) { + if(!recentAcceptCause && this.selected) { this.accept(this.selected); returnObj.shouldSwallow = true; - // No need to swallow the next keystroke's whitespace; we triggered FROM a space, - // which this matches. - // Standard applications from the banner, those we DO want to swallow the first time. - this.recentAccept = false; - } else if(this.recentAccept && source == 'space') { - this.recentAccept = false; - // If the model doesn't insert wordbreaks, don't swallow the space. If it does, - // we consider that insertion to be the results of the first post-accept space. + + // doTryAccept is the path for keystroke-based auto-acceptance. + // Overwrite the cause to reflect this. + this.recentAcceptCause = 'key'; + } else if(recentAcceptCause && source == 'space') { + this.recentAcceptCause = null; + if(recentAcceptCause == 'key') { + // No need to swallow the keystroke's whitespace; we triggered the prior acceptance + // FROM a space, so we've already aliased the suggestion's built-in space. + returnObj.shouldSwallow = false; + return; + } + + // Standard whitespace applications from the banner, those we DO want to + // swallow the first time. + // + // If the model doesn't insert wordbreaks, there's no space to alias, so + // don't swallow the space. If it does, we consider that insertion to be + // the results of the first post-accept space. returnObj.shouldSwallow = !!this.langProcessor.wordbreaksAfterSuggestions; // can be handed outside } else { returnObj.shouldSwallow = false; @@ -254,9 +268,9 @@ export default class PredictionContext extends EventEmitter