mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-20 05:32:46 -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,9 +2691,12 @@ 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;
|
||||||
|
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. So just store the selection and mark it as
|
||||||
|
// needing restore on focus.
|
||||||
|
if ( !this._isFocused ) {
|
||||||
|
enableRestoreSelection.call( this );
|
||||||
|
} 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
|
||||||
// doesn't get directed into the contenteditable area but is instead
|
// doesn't get directed into the contenteditable area but is instead
|
||||||
|
@ -2707,6 +2710,7 @@ proto.setSelection = function ( range ) {
|
||||||
sel.addRange( range );
|
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,9 +423,12 @@ 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;
|
||||||
|
// If we're setting selection, that automatically, and synchronously, // triggers a focus event. So just store the selection and mark it as
|
||||||
|
// needing restore on focus.
|
||||||
|
if ( !this._isFocused ) {
|
||||||
|
enableRestoreSelection.call( this );
|
||||||
|
} 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
|
||||||
// doesn't get directed into the contenteditable area but is instead
|
// doesn't get directed into the contenteditable area but is instead
|
||||||
|
@ -439,6 +442,7 @@ proto.setSelection = function ( range ) {
|
||||||
sel.addRange( range );
|
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…
Add table
Reference in a new issue