From 0fcbb84dfa83f2f387c23d44ca5804c2b49dc9cc Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 28 Feb 2024 10:15:37 +0700 Subject: [PATCH] fix(web): context save-state on reset --- android/KMEA/app/src/main/assets/android-host.js | 14 ++++++++++---- web/src/app/webview/src/contextManager.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/android/KMEA/app/src/main/assets/android-host.js b/android/KMEA/app/src/main/assets/android-host.js index 8c4fd7da8f..04a9ba44c1 100644 --- a/android/KMEA/app/src/main/assets/android-host.js +++ b/android/KMEA/app/src/main/assets/android-host.js @@ -1,4 +1,4 @@ -var _debug = 0; +var _debug = false; // Android harness attachment if(window.parent && window.parent.jsInterface && !window.jsInterface) { @@ -235,7 +235,7 @@ function updateKMText(text) { text = ''; } - console_debug('updateKMText(text='+text+') context.value='+keyman.context.getText()); + console_debug('updateKMText(text=' + text + ') with: ' + build_context_string(keyman.context)); if(text != keyman.context.getText()) { keyman.context.setText(text); @@ -249,11 +249,17 @@ function console_debug(s) { } } +function build_context_string(context) { + // Sadly, ES6-style "template strings" - strings with backticks - require Chrome 41+. + return 'preCaret: `' + context.getTextBeforeCaret() + '`\n' + + 'selected: `' + context.getSelectedText() + '`\n' + + 'postCaret: `' + context.getTextAfterCaret() + '`'; +} + function updateKMSelectionRange(start, end) { var context = keyman.context; - // console_debug('updateKMSelectionRange('+start+','+end+'): context.selStart='+ta.selectionStart+' '+ - // '['+ta._KeymanWebSelectionStart+'] context.selEnd='+ta.selectionEnd+' '+ta._KeymanWebSelectionEnd); + console_debug('updateKMSelectionRange(' + start + ', ' + end + ') with: ' + build_context_string(context)); if(start > end) { var e0 = end; diff --git a/web/src/app/webview/src/contextManager.ts b/web/src/app/webview/src/contextManager.ts index b887bac15c..2f6cfd6ae7 100644 --- a/web/src/app/webview/src/contextManager.ts +++ b/web/src/app/webview/src/contextManager.ts @@ -12,6 +12,7 @@ export class ContextHost extends Mock { constructor(oninserttext: OnInsertTextFunc) { super(); this.oninserttext = oninserttext; + this.saveState(); } apply(transform: Transform): void { @@ -45,6 +46,10 @@ export class ContextHost extends Mock { } // Save the current context state for use in future diffs. + this.saveState(); + } + + saveState() { this.savedState = Mock.from(this); } @@ -77,7 +82,7 @@ export class ContextHost extends Mock { this.setSelection(this.text._kmwLength()); } - this.savedState = Mock.from(this); + this.saveState(); return shouldResetContext; } @@ -183,4 +188,9 @@ export default class ContextManager extends ContextManagerBase