mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 13:16:31 -05:00
Workaround Android hiding the keyboard on cut.
This commit is contained in:
parent
d4abc182c8
commit
13241028f1
4 changed files with 33 additions and 2 deletions
|
@ -31,6 +31,8 @@ var ua = navigator.userAgent;
|
||||||
var isIOS = /iP(?:ad|hone|od)/.test( ua );
|
var isIOS = /iP(?:ad|hone|od)/.test( ua );
|
||||||
var isMac = /Mac OS X/.test( ua );
|
var isMac = /Mac OS X/.test( ua );
|
||||||
|
|
||||||
|
var isAndroid = /Android/.test( ua );
|
||||||
|
|
||||||
var isGecko = /Gecko\//.test( ua );
|
var isGecko = /Gecko\//.test( ua );
|
||||||
var isIElt11 = /Trident\/[456]\./.test( ua );
|
var isIElt11 = /Trident\/[456]\./.test( ua );
|
||||||
var isPresto = !!win.opera;
|
var isPresto = !!win.opera;
|
||||||
|
@ -1644,6 +1646,13 @@ var keyHandlers = {
|
||||||
!node.nextSibling && range.endOffset === getLength( node ) ) {
|
!node.nextSibling && range.endOffset === getLength( node ) ) {
|
||||||
range.setStartAfter( parent );
|
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 );
|
self.setSelection( range );
|
||||||
},
|
},
|
||||||
|
@ -2717,6 +2726,16 @@ proto.setSelection = function ( range ) {
|
||||||
// needing restore on focus.
|
// needing restore on focus.
|
||||||
if ( !this._isFocused ) {
|
if ( !this._isFocused ) {
|
||||||
enableRestoreSelection.call( this );
|
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 {
|
} else {
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// 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
|
// selection, you can end up in a state where you type but the input
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -27,6 +27,8 @@ var ua = navigator.userAgent;
|
||||||
var isIOS = /iP(?:ad|hone|od)/.test( ua );
|
var isIOS = /iP(?:ad|hone|od)/.test( ua );
|
||||||
var isMac = /Mac OS X/.test( ua );
|
var isMac = /Mac OS X/.test( ua );
|
||||||
|
|
||||||
|
var isAndroid = /Android/.test( ua );
|
||||||
|
|
||||||
var isGecko = /Gecko\//.test( ua );
|
var isGecko = /Gecko\//.test( ua );
|
||||||
var isIElt11 = /Trident\/[456]\./.test( ua );
|
var isIElt11 = /Trident\/[456]\./.test( ua );
|
||||||
var isPresto = !!win.opera;
|
var isPresto = !!win.opera;
|
||||||
|
|
|
@ -427,6 +427,16 @@ proto.setSelection = function ( range ) {
|
||||||
// needing restore on focus.
|
// needing restore on focus.
|
||||||
if ( !this._isFocused ) {
|
if ( !this._isFocused ) {
|
||||||
enableRestoreSelection.call( this );
|
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 {
|
} else {
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// 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
|
// selection, you can end up in a state where you type but the input
|
||||||
|
|
Loading…
Reference in a new issue