r112854 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112853‎ | r112854 | r112855 >
Date:00:10, 2 March 2012
Author:inez
Status:deferred
Tags:
Comment:
Fix couple of poll interval bugs in Surface and add new parameter called 'byref' to method getAnnotationsFromOffset which makes it return array references instead of copy of arrays.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -32,7 +32,7 @@
3333 $document.unbind( '.ce-surfaceView' );
3434 $document.bind( {
3535 'keydown.ce-surfaceView': function( e ) {
36 -// return _this.onKeyDown( e );
 36+ return _this.onKeyDown( e );
3737 }
3838 } );
3939 },
@@ -104,13 +104,14 @@
105105 };
106106
107107 ve.es.Surface.prototype.onPaste = function( e ) {
108 - var _this = this,
109 - insertionPoint = _this.getSelection().start,
110 - node = rangy.getSelection().anchorNode;
 108+ var _this = this,
 109+ insertionPoint = _this.getSelection().start,
 110+ node = rangy.getSelection().anchorNode;
111111
 112+_this.stopPolling();
112113 $('#paste').html('').show().css( 'top', $(window).scrollTop() ).css(' left', $(window).scrollLeft() ).focus();
113114
114 - _this.stopPolling();
 115+
115116
116117 setTimeout( function() {
117118
@@ -129,11 +130,12 @@
130131
131132 // re-render
132133 _this.getLeafNode( node ).data( 'view' ).renderContent();
 134+ _this.poll.prevText = _this.poll.prevHash = _this.poll.prevOffset = _this.poll.node = null;
133135
134136 // place cursor
135 - _this.showCursorAt( insertionPoint + _this.clipboard[key].length );
 137+ //_this.showCursorAt( insertionPoint + _this.clipboard[key].length );
136138
137 - _this.startPolling();
 139+ //_this.startPolling();
138140 } else {
139141 alert('i can only handle copy/paste from hybrid surface. sorry. :(');
140142 }
@@ -171,10 +173,12 @@
172174 ve.es.Surface.prototype.startPolling = function() {
173175 if ( this.poll.interval === null ) {
174176 var _this = this;
 177+ setTimeout( function() {
 178+ _this.pollContent();
 179+ }, 0);
175180 this.poll.interval = setInterval( function() {
176181 _this.pollContent();
177182 }, this.poll.frequency );
178 - this.pollContent();
179183 }
180184 };
181185
@@ -231,7 +235,7 @@
232236
233237 if ( lengthDiff === offsetDiff && this.poll.prevText.substring( 0, this.poll.prevOffset ) === text.substring( 0, this.poll.prevOffset ) ) {
234238 newData = text.substring( this.poll.prevOffset, localOffset ).split( '' );
235 - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1 );
 239+ annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + this.poll.prevOffset - 1, true );
236240 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
237241 this.model.transact( this.documentView.model.prepareInsertion(
238242 nodeOffset + 1 + this.poll.prevOffset,
@@ -248,12 +252,12 @@
249253 while ( sameFromRight < l && this.poll.prevText[this.poll.prevText.length - 1 - sameFromRight] === text[text.length - 1 - sameFromRight] ) {
250254 ++sameFromRight;
251255 }
 256+ annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft, true );
252257 this.model.transact( this.documentView.model.prepareRemoval( new ve.Range(
253258 nodeOffset + 1 + sameFromLeft,
254259 nodeOffset + 1 + this.poll.prevText.length - sameFromRight
255260 ) ) );
256261 newData = text.substring( sameFromLeft, text.length - sameFromRight ).split( '' );
257 - annotations = this.model.getDocument().getAnnotationsFromOffset( nodeOffset + 1 + sameFromLeft );
258262 ve.dm.DocumentNode.addAnnotationsToData( newData, annotations );
259263 this.model.transact( this.documentView.model.prepareInsertion(
260264 nodeOffset + 1 + sameFromLeft,
@@ -263,7 +267,15 @@
264268 this.poll.prevText = text;
265269 }
266270 if ( hash !== this.poll.prevHash ) {
 271+ console.log("hash mismatch", text, hash);
267272 // TODO: redisplay cursor in correct position (with setTimeout)
 273+ /*
 274+ this.stopPolling();
 275+ var _this = this;
 276+ setTimeout(function() {
 277+ _this.startPolling();
 278+ }, 500);
 279+ */
268280 this.getLeafNode( this.poll.node ).data( 'view' ).renderContent();
269281 this.poll.prevHash = hash;
270282 }
@@ -271,6 +283,41 @@
272284 this.poll.prevOffset = localOffset;
273285 };
274286
 287+ve.es.Surface.prototype.onKeyDown = function( e ) {
 288+ console.log("keyDown");
 289+ switch ( e.keyCode ) {
 290+ // Left arrow
 291+ case 37:
 292+ var rangySel = rangy.getSelection();
 293+ if ( rangySel.anchorOffset === 0 ) {
 294+ var globalOffset = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset, true ),
 295+ node = this.documentView.getNodeFromOffset( globalOffset ),
 296+ nodeOffset = surfaceView.documentView.getOffsetFromNode( node );
 297+
 298+
 299+ if ( nodeOffset + 1 === globalOffset ) {
 300+ var newOffset = this.documentView.model.getRelativeContentOffset( globalOffset, -1 );
 301+ console.log('newOffset', newOffset);
 302+ this.showCursorAt(newOffset);
 303+ e.preventDefault();
 304+ //return false;
 305+ }
 306+
 307+ //debugger;
 308+
 309+
 310+
 311+ }
 312+
 313+ console.log( 'left' );
 314+ break;
 315+ // Right arrow
 316+ case 39:
 317+ console.log( 'right' );
 318+ break;
 319+ }
 320+};
 321+
275322 ve.es.Surface.prototype.getOffset = function( elem, offset, global ) {
276323 var $leafNode = this.getLeafNode( elem ),
277324 current = [$leafNode.contents(), 0],
Index: trunk/extensions/VisualEditor/modules/ve/dm/nodes/ve.dm.DocumentNode.js
@@ -723,9 +723,13 @@
724724 * @param {Integer} offset Offset to get annotations for
725725 * @returns {Object[]} A copy of all annotation objects offset is covered by
726726 */
727 -ve.dm.DocumentNode.prototype.getAnnotationsFromOffset = function( offset ) {
 727+ve.dm.DocumentNode.prototype.getAnnotationsFromOffset = function( offset, byref ) {
728728 if ( ve.isArray( this.data[offset] ) ) {
729 - return ve.copyArray( this.data[offset].slice( 1 ) );
 729+ if ( byref === true ) {
 730+ return this.data[offset].slice( 1 );
 731+ } else {
 732+ return ve.copyArray( this.data[offset].slice( 1 ) );
 733+ }
730734 }
731735 return [];
732736 };

Status & tagging log