Skip to content

Commit

Permalink
Workaround Android hiding the keyboard on cut.
Browse files Browse the repository at this point in the history
  • Loading branch information
neilj committed Jul 14, 2016
1 parent d4abc18 commit 1324102
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
19 changes: 19 additions & 0 deletions build/squire-raw.js
Expand Up @@ -31,6 +31,8 @@ var ua = navigator.userAgent;
var isIOS = /iP(?:ad|hone|od)/.test( ua );
var isMac = /Mac OS X/.test( ua );

var isAndroid = /Android/.test( ua );

var isGecko = /Gecko\//.test( ua );
var isIElt11 = /Trident\/[456]\./.test( ua );
var isPresto = !!win.opera;
Expand Down Expand Up @@ -1644,6 +1646,13 @@ var keyHandlers = {
!node.nextSibling && range.endOffset === getLength( node ) ) {
range.setStartAfter( parent );
}
// Delete the selection if not collapsed
else if ( !range.collapsed ) {
deleteContentsOfRange( range, self._root );
self._ensureBottomLine();
self.setSelection( range );
self._updatePath( range, true );
}

self.setSelection( range );
},
Expand Down Expand Up @@ -2717,6 +2726,16 @@ proto.setSelection = function ( range ) {
// needing restore on focus.
if ( !this._isFocused ) {
enableRestoreSelection.call( this );
} else if ( isAndroid && !this._restoreSelection ) {
// Android closes the keyboard on removeAllRanges() and doesn't
// open it again when addRange() is called, sigh.
// Since Android doesn't trigger a focus event in setSelection(),
// use a blur/focus dance to work around this by letting the
// selection be restored on focus.
// Need to check for !this._restoreSelection to avoid infinite loop
enableRestoreSelection.call( this );
this.blur();
this.focus();
} else {
// iOS bug: if you don't focus the iframe before setting the
// selection, you can end up in a state where you type but the input
Expand Down
4 changes: 2 additions & 2 deletions build/squire.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions source/Constants.js
Expand Up @@ -27,6 +27,8 @@ var ua = navigator.userAgent;
var isIOS = /iP(?:ad|hone|od)/.test( ua );
var isMac = /Mac OS X/.test( ua );

var isAndroid = /Android/.test( ua );

var isGecko = /Gecko\//.test( ua );
var isIElt11 = /Trident\/[456]\./.test( ua );
var isPresto = !!win.opera;
Expand Down
10 changes: 10 additions & 0 deletions source/Editor.js
Expand Up @@ -427,6 +427,16 @@ proto.setSelection = function ( range ) {
// needing restore on focus.
if ( !this._isFocused ) {
enableRestoreSelection.call( this );
} else if ( isAndroid && !this._restoreSelection ) {
// Android closes the keyboard on removeAllRanges() and doesn't
// open it again when addRange() is called, sigh.
// Since Android doesn't trigger a focus event in setSelection(),
// use a blur/focus dance to work around this by letting the
// selection be restored on focus.
// Need to check for !this._restoreSelection to avoid infinite loop
enableRestoreSelection.call( this );
this.blur();
this.focus();
} else {
// iOS bug: if you don't focus the iframe before setting the
// selection, you can end up in a state where you type but the input
Expand Down

0 comments on commit 1324102

Please sign in to comment.