r104112 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104111‎ | r104112 | r104113 >
Date:23:57, 23 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Took time-buffered actions out of a timeout if delay is undefined or 0
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -70,7 +70,7 @@
7171 // Keep a copy of the current selection on hand
7272 _this.currentSelection = selection.clone();
7373 // Respond to selection changes
74 - _this.updateSelection( 0 );
 74+ _this.updateSelection();
7575 } );
7676 this.model.getDocument().on( 'update', function() {
7777 _this.emitUpdate( 25 );
@@ -141,31 +141,45 @@
142142 /* Methods */
143143
144144 es.SurfaceView.prototype.updateSelection = function( delay ) {
145 - if ( this.updateSelectionTimeout !== undefined ) {
146 - return;
147 - }
148 - var _this = this;
149 - this.updateSelectionTimeout = setTimeout( function() {
150 - if ( _this.currentSelection.from !== _this.currentSelection.to ) {
151 - _this.hideCursor();
152 - _this.documentView.drawSelection( _this.currentSelection );
 145+ if ( delay ) {
 146+ if ( this.updateSelectionTimeout !== undefined ) {
 147+ return;
 148+ }
 149+ var _this = this;
 150+ this.updateSelectionTimeout = setTimeout( function() {
 151+ if ( _this.currentSelection.from !== _this.currentSelection.to ) {
 152+ _this.hideCursor();
 153+ _this.documentView.drawSelection( _this.currentSelection );
 154+ } else {
 155+ _this.showCursor();
 156+ _this.documentView.clearSelection( _this.currentSelection );
 157+ }
 158+ _this.updateSelectionTimeout = undefined;
 159+ }, delay || 0 );
 160+ } else {
 161+ if ( this.currentSelection.from !== this.currentSelection.to ) {
 162+ this.hideCursor();
 163+ this.documentView.drawSelection( this.currentSelection );
153164 } else {
154 - _this.showCursor();
155 - _this.documentView.clearSelection( _this.currentSelection );
 165+ this.showCursor();
 166+ this.documentView.clearSelection( this.currentSelection );
156167 }
157 - _this.updateSelectionTimeout = undefined;
158 - }, delay || 0 );
 168+ }
159169 };
160170
161171 es.SurfaceView.prototype.emitUpdate = function( delay ) {
162 - if ( this.emitUpdateTimeout !== undefined ) {
163 - return;
 172+ if ( delay ) {
 173+ if ( this.emitUpdateTimeout !== undefined ) {
 174+ return;
 175+ }
 176+ var _this = this;
 177+ this.emitUpdateTimeout = setTimeout( function() {
 178+ _this.emit( 'update' );
 179+ _this.emitUpdateTimeout = undefined;
 180+ }, delay || 0 );
 181+ } else {
 182+ this.emit( 'update' );
164183 }
165 - var _this = this;
166 - this.emitUpdateTimeout = setTimeout( function() {
167 - _this.emit( 'update' );
168 - _this.emitUpdateTimeout = undefined;
169 - }, delay || 0 );
170184 };
171185
172186 es.SurfaceView.prototype.onMouseDown = function( e ) {

Status & tagging log