mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Return cached selection if not focused
If an action modifies the selection while the editor is not focused, we cannot immediately set it in the DOM as this triggers focus. So instead we cache it and restore on focus. If getSelection is called before the editor is next focused, we need to return this new selection, not the current DOM selection. Fixes #259
This commit is contained in:
parent
d8917a291c
commit
70a2b48333
3 changed files with 7 additions and 3 deletions
|
@ -2910,7 +2910,9 @@ proto.getSelection = function () {
|
|||
var sel = getWindowSelection( this );
|
||||
var root = this._root;
|
||||
var selection, startContainer, endContainer;
|
||||
if ( sel && sel.rangeCount ) {
|
||||
// If not focused, always rely on cached selection; another function may
|
||||
// have set it but the DOM is not modified until focus again
|
||||
if ( this._isFocused && sel && sel.rangeCount ) {
|
||||
selection = sel.getRangeAt( 0 ).cloneRange();
|
||||
startContainer = selection.startContainer;
|
||||
endContainer = selection.endContainer;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -463,7 +463,9 @@ proto.getSelection = function () {
|
|||
var sel = getWindowSelection( this );
|
||||
var root = this._root;
|
||||
var selection, startContainer, endContainer;
|
||||
if ( sel && sel.rangeCount ) {
|
||||
// If not focused, always rely on cached selection; another function may
|
||||
// have set it but the DOM is not modified until focus again
|
||||
if ( this._isFocused && sel && sel.rangeCount ) {
|
||||
selection = sel.getRangeAt( 0 ).cloneRange();
|
||||
startContainer = selection.startContainer;
|
||||
endContainer = selection.endContainer;
|
||||
|
|
Loading…
Reference in a new issue