Merge pull request #1989 from StileEducation/PR_cursor_timer

Fixed race condition in the iText cursor flash animation
This commit is contained in:
Juriy Zaytsev 2015-02-25 14:21:32 +01:00
commit 1e5bd1e678

View file

@ -61,18 +61,23 @@
* @private
*/
_tick: function() {
if (this._abortCursorAnimation) {
return;
}
var _this = this;
var tickState, _this = this;
tickState = {
isAborted: false,
abort: function() {
this.isAborted = true;
},
};
this.animate('_currentCursorOpacity', 1, {
duration: this.cursorDuration,
onComplete: function() {
_this._onTickComplete();
if (!tickState.isAborted) {
_this._onTickComplete();
}
},
onChange: function() {
@ -80,20 +85,25 @@
},
abort: function() {
return _this._abortCursorAnimation;
return tickState.isAborted;
}
});
this._currentTickState = tickState;
},
/**
* @private
*/
_onTickComplete: function() {
if (this._abortCursorAnimation) {
return;
}
var _this = this;
var tickState, _this = this;
tickState = {
isAborted: false,
abort: function() {
this.isAborted = true;
},
};
if (this._cursorTimeout1) {
clearTimeout(this._cursorTimeout1);
}
@ -101,16 +111,20 @@
_this.animate('_currentCursorOpacity', 0, {
duration: this.cursorDuration / 2,
onComplete: function() {
_this._tick();
if (!tickState.isAborted) {
_this._tick();
}
},
onChange: function() {
_this.canvas && _this.canvas.renderAll();
},
abort: function() {
return _this._abortCursorAnimation;
return tickState.isAborted;
}
});
}, 100);
this._currentTickCompleteState = tickState;
},
/**
@ -121,7 +135,8 @@
delay = restart ? 0 : this.cursorDelay;
if (restart) {
this._abortCursorAnimation = true;
this._currentTickState && this._currentTickState.abort();
this._currentTickCompleteState && this._currentTickCompleteState.abort();
clearTimeout(this._cursorTimeout1);
this._currentCursorOpacity = 1;
this.canvas && this.canvas.renderAll();
@ -130,7 +145,6 @@
clearTimeout(this._cursorTimeout2);
}
this._cursorTimeout2 = setTimeout(function() {
_this._abortCursorAnimation = false;
_this._tick();
}, delay);
},
@ -139,18 +153,14 @@
* Aborts cursor animation and clears all timeouts
*/
abortCursorAnimation: function() {
this._abortCursorAnimation = true;
this._currentTickState && this._currentTickState.abort();
this._currentTickCompleteState && this._currentTickCompleteState.abort();
clearTimeout(this._cursorTimeout1);
clearTimeout(this._cursorTimeout2);
this._currentCursorOpacity = 0;
this.canvas && this.canvas.renderAll();
var _this = this;
setTimeout(function() {
_this._abortCursorAnimation = false;
}, 10);
},
/**