0
Fork 0
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:
Neil Jenkins 2017-02-11 09:40:56 -08:00
parent d8917a291c
commit 70a2b48333
3 changed files with 7 additions and 3 deletions

View file

@ -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

View file

@ -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;