mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 09:25:33 +00:00
fix(web): context save-state on reset
This commit is contained in:
parent
f42e57980e
commit
0fcbb84dfa
2 changed files with 21 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<WebviewConfigurat
|
|||
|
||||
return activatingKeyboard;
|
||||
}
|
||||
|
||||
public resetContext(): void {
|
||||
super.resetContext();
|
||||
this._rawContext.saveState();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue