mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Restore selection of focus after call to setHTML.
This commit is contained in:
parent
f593d8ac04
commit
f060dbf978
3 changed files with 38 additions and 28 deletions
|
@ -2691,20 +2691,24 @@ var getWindowSelection = function ( self ) {
|
||||||
|
|
||||||
proto.setSelection = function ( range ) {
|
proto.setSelection = function ( range ) {
|
||||||
if ( range ) {
|
if ( range ) {
|
||||||
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. Don't want a reentrant call to setSelection.
|
|
||||||
this._restoreSelection = false;
|
|
||||||
this._lastSelection = range;
|
this._lastSelection = range;
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. So just store the selection and mark it as
|
||||||
// selection, you can end up in a state where you type but the input
|
// needing restore on focus.
|
||||||
// doesn't get directed into the contenteditable area but is instead
|
if ( !this._isFocused ) {
|
||||||
// lost in a black hole. Very strange.
|
enableRestoreSelection.call( this );
|
||||||
if ( isIOS ) {
|
} else {
|
||||||
this._win.focus();
|
// 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
|
||||||
var sel = getWindowSelection( this );
|
// doesn't get directed into the contenteditable area but is instead
|
||||||
if ( sel ) {
|
// lost in a black hole. Very strange.
|
||||||
sel.removeAllRanges();
|
if ( isIOS ) {
|
||||||
sel.addRange( range );
|
this._win.focus();
|
||||||
|
}
|
||||||
|
var sel = getWindowSelection( this );
|
||||||
|
if ( sel ) {
|
||||||
|
sel.removeAllRanges();
|
||||||
|
sel.addRange( range );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -3831,6 +3835,7 @@ proto.setHTML = function ( html ) {
|
||||||
// anything calls getSelection before first focus, we have a range
|
// anything calls getSelection before first focus, we have a range
|
||||||
// to return.
|
// to return.
|
||||||
this._lastSelection = range;
|
this._lastSelection = range;
|
||||||
|
enableRestoreSelection.call( this );
|
||||||
this._updatePath( range, true );
|
this._updatePath( range, true );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -423,20 +423,24 @@ var getWindowSelection = function ( self ) {
|
||||||
|
|
||||||
proto.setSelection = function ( range ) {
|
proto.setSelection = function ( range ) {
|
||||||
if ( range ) {
|
if ( range ) {
|
||||||
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. Don't want a reentrant call to setSelection.
|
|
||||||
this._restoreSelection = false;
|
|
||||||
this._lastSelection = range;
|
this._lastSelection = range;
|
||||||
// iOS bug: if you don't focus the iframe before setting the
|
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. So just store the selection and mark it as
|
||||||
// selection, you can end up in a state where you type but the input
|
// needing restore on focus.
|
||||||
// doesn't get directed into the contenteditable area but is instead
|
if ( !this._isFocused ) {
|
||||||
// lost in a black hole. Very strange.
|
enableRestoreSelection.call( this );
|
||||||
if ( isIOS ) {
|
} else {
|
||||||
this._win.focus();
|
// 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
|
||||||
var sel = getWindowSelection( this );
|
// doesn't get directed into the contenteditable area but is instead
|
||||||
if ( sel ) {
|
// lost in a black hole. Very strange.
|
||||||
sel.removeAllRanges();
|
if ( isIOS ) {
|
||||||
sel.addRange( range );
|
this._win.focus();
|
||||||
|
}
|
||||||
|
var sel = getWindowSelection( this );
|
||||||
|
if ( sel ) {
|
||||||
|
sel.removeAllRanges();
|
||||||
|
sel.addRange( range );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -1563,6 +1567,7 @@ proto.setHTML = function ( html ) {
|
||||||
// anything calls getSelection before first focus, we have a range
|
// anything calls getSelection before first focus, we have a range
|
||||||
// to return.
|
// to return.
|
||||||
this._lastSelection = range;
|
this._lastSelection = range;
|
||||||
|
enableRestoreSelection.call( this );
|
||||||
this._updatePath( range, true );
|
this._updatePath( range, true );
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue