Write a better debounced onSelect method for showing the context

view icon after select events are finished being fired.

Change-Id: I4e1307b90eed14b1c9167830018e50b9c7832ae6
This commit is contained in:
Rob Moen 2012-06-15 10:45:53 -07:00
parent 0be0ebf4a8
commit d1eba674b1

View file

@ -13,7 +13,7 @@ ve.ce.Surface = function( $container, model ) {
this.model = model;
this.documentView = null; // See initialization below
this.contextView = null; // See initialization below
this.selectionInterval = null;
this.selectionTimeout = null;
this.$ = $container;
this.$document = $( document );
this.clipboard = {};
@ -144,11 +144,14 @@ ve.ce.Surface.prototype.clearPollData = function() {
};
};
/* Responsible for Debouncing the ContextView Icon
until select events are finished being fired. */
ve.ce.Surface.prototype.onSelect = function( range ) {
var _this = this,
selection = this.model.getSelection();
function update() {
var _this = this;
clearTimeout(this.selectionTimeout);
this.selectionTimeout = setTimeout(function(){
var selection = _this.model.getSelection();
if ( _this.contextView ) {
if ( selection.getLength() > 0 ) {
_this.contextView.set();
@ -156,9 +159,7 @@ ve.ce.Surface.prototype.onSelect = function( range ) {
_this.contextView.clear();
}
}
_this.updateSelectionTimeout = undefined;
}
this.updateSelectionTimeout = setTimeout( update, 500 );
}, 500);
};
ve.ce.Surface.prototype.onTransact = function( tx ) {