From d1eba674b1f3558ec1aaeb3d6d1b3d7921d71e90 Mon Sep 17 00:00:00 2001 From: Rob Moen Date: Fri, 15 Jun 2012 10:45:53 -0700 Subject: [PATCH] Write a better debounced onSelect method for showing the context view icon after select events are finished being fired. Change-Id: I4e1307b90eed14b1c9167830018e50b9c7832ae6 --- modules/ve2/ce/ve.ce.Surface.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/ve2/ce/ve.ce.Surface.js b/modules/ve2/ce/ve.ce.Surface.js index 2c9cfd9b71..2beca361d8 100644 --- a/modules/ve2/ce/ve.ce.Surface.js +++ b/modules/ve2/ce/ve.ce.Surface.js @@ -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 ) {