r104095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104094‎ | r104095 | r104096 >
Date:22:21, 23 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
* Added node updates for annotation+retain transactions
* Added time-buffered updates for selection/cursor
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js
@@ -171,7 +171,7 @@
172172 return node;
173173 };
174174
175 -es.TransactionProcessor.prototype.applyAnnotations = function( to ) {
 175+es.TransactionProcessor.prototype.applyAnnotations = function( to, update ) {
176176 var i,
177177 j,
178178 length,
@@ -213,10 +213,16 @@
214214 }
215215 }
216216 }
 217+ if ( update ) {
 218+ var updates = this.model.selectNodes( new es.Range( this.cursor, to ) );
 219+ for ( i = 0; i < updates.length; i++ ) {
 220+ updates[i].node.emit( 'update' );
 221+ }
 222+ }
217223 };
218224
219225 es.TransactionProcessor.prototype.retain = function( op ) {
220 - this.applyAnnotations( this.cursor + op.length );
 226+ this.applyAnnotations( this.cursor + op.length, true );
221227 this.cursor += op.length;
222228 };
223229
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -26,6 +26,7 @@
2727 .prependTo( this.$ );
2828 this.$cursor = $( '<div class="es-surfaceView-cursor"></div>' )
2929 .appendTo( this.$ );
 30+ this.updateSelectionTimeout = undefined;
3031
3132 // Interaction states
3233
@@ -68,16 +69,12 @@
6970 // Keep a copy of the current selection on hand
7071 _this.currentSelection = selection.clone();
7172 // Respond to selection changes
72 - if ( selection.from !== selection.to ) {
73 - _this.hideCursor();
74 - _this.documentView.drawSelection( selection );
75 - } else {
76 - _this.showCursor();
77 - _this.documentView.clearSelection( selection );
78 - }
 73+ _this.updateSelection( 0 );
7974 } );
8075 this.model.getDocument().on( 'update', function() {
8176 _this.emit( 'update' );
 77+ // Respond to layout changes
 78+ _this.updateSelection( 50 );
8279 } );
8380 this.$.mousedown( function(e) {
8481 return _this.onMouseDown( e );
@@ -142,12 +139,28 @@
143140
144141 /* Methods */
145142
 143+es.SurfaceView.prototype.updateSelection = function( delay ) {
 144+ if ( this.updateSelectionTimeout !== undefined ) {
 145+ return;
 146+ }
 147+ var _this = this;
 148+ this.updateSelectionTimeout = setTimeout( function() {
 149+ if ( _this.currentSelection.from !== _this.currentSelection.to ) {
 150+ _this.hideCursor();
 151+ _this.documentView.drawSelection( _this.currentSelection );
 152+ } else {
 153+ _this.showCursor();
 154+ _this.documentView.clearSelection( _this.currentSelection );
 155+ }
 156+ _this.updateSelectionTimeout = undefined;
 157+ }, delay );
 158+};
 159+
146160 es.SurfaceView.prototype.onMouseDown = function( e ) {
147161 // Only for left mouse button
148162 if ( e.button === 0 ) {
149163 var selection = this.currentSelection.clone(),
150164 offset = this.documentView.getOffsetFromEvent( e );
151 -
152165 // Single click
153166 if ( e.originalEvent.detail === 1 ) {
154167 // @see {es.SurfaceView.prototype.onMouseMove}
@@ -163,7 +176,6 @@
164177 nodeView = this.documentView.getNodeFromOffset( offset, false );
165178 this.cursor.initialBias = position.left > nodeView.contentView.$.offset().left;
166179 }
167 -
168180 }
169181 // Double click
170182 else if ( e.originalEvent.detail === 2 ) {
@@ -175,7 +187,6 @@
176188 selection = wordRange;
177189 this.mouse.selectedRange = selection.clone();
178190 }
179 -
180191 }
181192 // Triple click
182193 else if ( e.originalEvent.detail >= 3 ) {
@@ -191,7 +202,6 @@
192203 );
193204 this.mouse.selectedRange = selection.clone();
194205 }
195 -
196206 // Reset the initial left position
197207 this.cursor.initialLeft = null;
198208 // Apply new selection

Status & tagging log