diff --git a/android/KMEA/app/src/main/assets/keyboard.html b/android/KMEA/app/src/main/assets/keyboard.html index 9f0e8d8d69..663ecd833e 100644 --- a/android/KMEA/app/src/main/assets/keyboard.html +++ b/android/KMEA/app/src/main/assets/keyboard.html @@ -39,6 +39,7 @@ kmw['setActiveElement'](ta); ta.readOnly = false; + checkTextArea(); // Tell KMW the default banner height to use com.keyman.osk.Banner.DEFAULT_HEIGHT = @@ -327,6 +328,27 @@ return hexString; } + /** + * Check the WebView version and determine if the textarea that KeymanWeb uses needs to be "visible". + * Normally, this textarea is not displayed to avoid redundant layout calculations. + * In older WebViews on Android 5.0 though, selectionStart and selectionEnd positions fail to + * update unless the textarea is visible. + * Reference: Issue #5376 + */ + function checkTextArea() { + var uaRe = /Chrome\/([0-9]*)./g; + var chromeMajorVersion = uaRe.exec(navigator.userAgent); + if (chromeMajorVersion && parseInt(chromeMajorVersion[1]) <= 37) { + var ta = document.getElementById('ta'); + if (ta != null) { + ta.style.display = ''; + ta.style.position = 'absolute'; + ta.style.left = '-500px'; + ta.style.top = '0px'; + } + } + } +