0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Fix multiple firing of updatePathOnEvent

This commit is contained in:
Neil Jenkins 2016-06-27 13:17:18 +10:00
parent 267085e8c1
commit db09921d7b
3 changed files with 26 additions and 4 deletions

View file

@ -2324,6 +2324,7 @@ function Squire ( root, config ) {
this._lastAnchorNode = null;
this._lastFocusNode = null;
this._path = '';
this._willUpdatePath = false;
if ( 'onselectionchange' in doc ) {
this.addEventListener( 'selectionchange', this._updatePathOnEvent );
@ -2859,8 +2860,18 @@ proto._updatePath = function ( range, force ) {
}
};
// selectionchange is fired synchronously in IE when removing current selection
// and when setting new selection; keyup/mouseup may have processing we want
// to do first. Either way, send to next event loop.
proto._updatePathOnEvent = function () {
this._updatePath( this.getSelection() );
var self = this;
if ( !self._willUpdatePath ) {
self._willUpdatePath = true;
setTimeout( function () {
self._willUpdatePath = false;
self._updatePath( self.getSelection() );
}, 0 );
}
};
// --- Focus ---

File diff suppressed because one or more lines are too long

View file

@ -56,6 +56,7 @@ function Squire ( root, config ) {
this._lastAnchorNode = null;
this._lastFocusNode = null;
this._path = '';
this._willUpdatePath = false;
if ( 'onselectionchange' in doc ) {
this.addEventListener( 'selectionchange', this._updatePathOnEvent );
@ -591,8 +592,18 @@ proto._updatePath = function ( range, force ) {
}
};
// selectionchange is fired synchronously in IE when removing current selection
// and when setting new selection; keyup/mouseup may have processing we want
// to do first. Either way, send to next event loop.
proto._updatePathOnEvent = function () {
this._updatePath( this.getSelection() );
var self = this;
if ( !self._willUpdatePath ) {
self._willUpdatePath = true;
setTimeout( function () {
self._willUpdatePath = false;
self._updatePath( self.getSelection() );
}, 0 );
}
};
// --- Focus ---