From ffdf71f6ed4ff69a683fa0a404d47ae63601b5f3 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Thu, 22 Apr 2021 06:57:02 +1000 Subject: [PATCH] fix(web): publish restorePosition() function This makes the `osk.restorePosition()` function public and makes it work even if the OSK is not presently visible. Also DRY out the repeated implementation. --- web/source/osk/oskManager.ts | 38 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/web/source/osk/oskManager.ts b/web/source/osk/oskManager.ts index 8a5c2042bc..03528245f5 100644 --- a/web/source/osk/oskManager.ts +++ b/web/source/osk/oskManager.ts @@ -354,6 +354,7 @@ namespace com.keyman.osk { * Create a control bar with title and buttons for the desktop OSK */ controlBar(): HTMLDivElement { + // TODO: merge with _TitleBarInterior? let keymanweb = com.keyman.singleton; let util = keymanweb.util; @@ -413,20 +414,7 @@ namespace com.keyman.osk { Limg.id='kmw-pin-image'; Limg.className='kmw-title-bar-image'; Limg.title='Pin the On Screen Keyboard to its default location on the active text box'; - Limg.onclick=function(this: OSKManager) { - this.loadCookie(); - this.userPositioned=false; - this.saveCookie(); - this._Show(); - this.doResizeMove(); //allow the UI to respond to OSK movements - if(this.pinImg) { - this.pinImg.style.display='none'; - } - if(window.event) { - window.event.returnValue=false; - } - return false; - }.bind(this); + Limg.onclick=this.restorePosition; Limg.onmousedown=util._CancelMouse; bar.appendChild(Limg); @@ -482,17 +470,25 @@ namespace com.keyman.osk { } /** - * Move OSK back to default position + * Function restorePosition + * Scope Public + * Description Move OSK back to default position, floating under active input element */ restorePosition: () => void = function(this: OSKManager) { - if(this._Visible) { + let isVisible = this._Visible; + if(isVisible) { com.keyman.singleton.domManager.focusLastActiveElement(); // I2036 - OSK does not unpin to correct location - this.loadCookie(); - this.userPositioned=false; - this.saveCookie(); - this._Show(); - this.doResizeMove(); //allow the UI to respond to OSK movements } + + this.loadCookie(); + this.userPositioned=false; + this.saveCookie(); + + if(isVisible) { + this._Show(); + } + + this.doResizeMove(); //allow the UI to respond to OSK movements if(this.pinImg) { this.pinImg.style.display='none'; }