From aa1fff193c12b852c0ed4c6cef3172e9d0d2195a Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Wed, 27 Aug 2025 15:25:00 -0500 Subject: [PATCH] fix(web): handle backward context-slides (as from backspaces) --- .../src/main/correction/context-tokenization.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts index 943a042289..11a30ce078 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/correction/context-tokenization.ts @@ -377,11 +377,15 @@ export class ContextTokenization { if(leadTokenShift < 0) { tokenization.splice(0, -leadTokenShift); } else if(leadTokenShift > 0) { - // TODO: insert token(s) at the start to match the text that's back within the + // insert token(s) at the start to match the text that's back within the // sliding context window. - // - // (was not part of original source method [`attemptContextMatch`]) - return null; + + const reinsertedTokens = tokenizedContext.slice(0, leadTokenShift); + while(reinsertedTokens.length > 0) { + const reinserted = reinsertedTokens.pop(); + const token = new ContextToken(lexicalModel, reinserted.text); + tokenization.unshift(token); + } } // If no TAIL mutations have happened, we're safe to return now.