r92111 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92110‎ | r92111 | r92112 >
Date:22:33, 13 July 2011
Author:inez
Status:deferred
Tags:
Comment:
After changing location (due to moving cursor with arrows or typing or deleting) always create new location object.
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -12,7 +12,7 @@
1313 this.rendered = false;
1414 this.location = null;
1515 this.selection = new Selection();
16 - this.selecting = false;
 16+ this.mouseSelecting = false;
1717 this.keydownTimeout = null;
1818 this.initialHorizontalCursorPosition = null;
1919
@@ -148,20 +148,28 @@
149149 }
150150
151151 Surface.prototype.handleBackspace = function() {
152 - var location = this.getLocation();
153 - if ( location.offset > 0 ) {
154 - location.block.deleteContent( location.offset - 1, location.offset );
155 - location.offset--;
156 - this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() );
 152+ var block = this.location.block,
 153+ offset = this.location.offset;
 154+
 155+ if ( offset > 0 ) {
 156+ block.deleteContent( offset - 1, offset );
 157+ offset--;
 158+ this.cursor.show( block.flow.getPosition( offset ), block.$.offset() );
157159 }
 160+
 161+ this.location = new Location( block, offset );
158162 }
159163
160164 Surface.prototype.handleDelete = function() {
161 - var location = this.getLocation();
162 - if ( location.offset < location.block.getLength() - 1 ) {
163 - location.block.deleteContent( location.offset, location.offset + 1);
164 - this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() );
 165+ var block = this.location.block,
 166+ offset = this.location.offset;
 167+
 168+ if ( offset < block.getLength() - 1 ) {
 169+ block.deleteContent( offset, offset + 1);
 170+ this.cursor.show( block.flow.getPosition( offset ), block.$.offset() );
165171 }
 172+
 173+ this.location = new Location( block, offset );
166174 };
167175
168176 Surface.prototype.onMouseDown = function( e ) {
@@ -171,7 +179,7 @@
172180 var cursorPosition = this.location.block.getPosition( this.location.offset );
173181 this.cursor.show( cursorPosition, this.location.block.$.offset() );
174182 this.$input.css( 'top', cursorPosition.top );
175 - this.selecting = true;
 183+ this.mouseSelecting = true;
176184 this.drawSelection();
177185 this.cursor.show();
178186 }
@@ -183,7 +191,7 @@
184192 };
185193
186194 Surface.prototype.onMouseMove = function( e ) {
187 - if ( e.button === 0 && this.selecting ) {
 195+ if ( e.button === 0 && this.mouseSelecting ) {
188196 this.cursor.hide();
189197 this.selection.to = this.getLocationFromEvent( e );
190198 this.drawSelection();
@@ -195,7 +203,7 @@
196204 this.drawSelection();
197205 this.cursor.hide();
198206 }
199 - this.selecting = false;
 207+ this.mouseSelecting = false;
200208 };
201209
202210 /**
@@ -336,8 +344,9 @@
337345 * Moves the cursor to the nearest location directly above the current flowed line.
338346 */
339347 Surface.prototype.moveCursorUp = function() {
340 - var location = this.getLocation(),
341 - position = location.block.getPosition( location.offset );
 348+ var block = this.location.block,
 349+ offset = this.location.offset,
 350+ position = block.getPosition( offset );
342351
343352 if ( this.initialHorizontalCursorPosition ) {
344353 position.left = this.initialHorizontalCursorPosition;
@@ -347,23 +356,26 @@
348357
349358 position.top = position.top - 1;
350359 if ( position.top < 0 ) {
351 - var previousBlock = location.block.previousBlock();
 360+ var previousBlock = block.previousBlock();
352361 if ( previousBlock ) {
353 - location.block = previousBlock;
354 - position.top += location.block.$.height();
 362+ block = previousBlock;
 363+ position.top += block.$.height();
355364 }
356365 }
357 - location.offset = location.block.getOffset( position );
358 - position = location.block.getPosition( location.offset );
359 - this.cursor.show( position, location.block.$.offset() );
 366+ offset = block.getOffset( position );
 367+ position = block.getPosition( offset );
 368+ this.cursor.show( position, block.$.offset() );
 369+
 370+ this.location = new Location( block, offset );
360371 };
361372
362373 /**
363374 * Moves the cursor to the nearest location directly below the current flowed line.
364375 */
365376 Surface.prototype.moveCursorDown = function() {
366 - var location = this.getLocation()
367 - position = location.block.getPosition( location.offset );
 377+ var block = this.location.block,
 378+ offset = this.location.offset,
 379+ position = block.getPosition( offset );
368380
369381 if ( this.initialHorizontalCursorPosition ) {
370382 position.left = this.initialHorizontalCursorPosition;
@@ -372,56 +384,66 @@
373385 }
374386
375387 position.top = position.bottom + 1;
376 - if ( position.top > location.block.$.height() ) {
377 - var nextBlock = location.block.nextBlock();
 388+ if ( position.top > block.$.height() ) {
 389+ var nextBlock = block.nextBlock();
378390 if ( nextBlock ) {
379 - position.top -= location.block.$.height();
380 - location.block = nextBlock;
 391+ position.top -= block.$.height();
 392+ block = nextBlock;
381393 }
382394 }
383 - location.offset = location.block.getOffset( position );
384 - position = location.block.getPosition( location.offset );
385 - this.cursor.show( position, location.block.$.offset() );
 395+ offset = block.getOffset( position );
 396+ position = block.getPosition( offset );
 397+ this.cursor.show( position, block.$.offset() );
 398+
 399+ this.location = new Location( block, offset );
386400 };
387401
388402 /**
389403 * Moves the cursor backward of the current position.
390404 */
391405 Surface.prototype.moveCursorRight = function() {
392 - var location = this.getLocation();
393 - if ( location.offset < location.block.getLength() ) {
394 - location.offset++;
 406+ var block = this.location.block,
 407+ offset = this.location.offset;
 408+
 409+ if ( offset < block.getLength() ) {
 410+ offset++;
395411 } else {
396 - var next = location.block.nextBlock();
 412+ var next = block.nextBlock();
397413 if ( next ) {
398 - location.block = next;
399 - location.offset = 0;
 414+ block = next;
 415+ offset = 0;
400416 }
401417 }
402418 this.cursor.show(
403 - location.block.flow.getPosition( location.offset ),
404 - location.block.$.offset()
 419+ block.flow.getPosition( offset ),
 420+ block.$.offset()
405421 );
 422+
 423+ this.location = new Location( block, offset );
406424 };
407425
408426 /**
409427 * Moves the cursor forward of the current position.
410428 */
411429 Surface.prototype.moveCursorLeft = function() {
412 - var location = this.getLocation();
413 - if ( location.offset > 0 ) {
414 - location.offset--;
 430+ var block = this.location.block,
 431+ offset = this.location.offset;
 432+
 433+ if ( offset > 0 ) {
 434+ offset--;
415435 } else {
416 - var previous = location.block.previousBlock();
 436+ var previous = block.previousBlock();
417437 if ( previous ) {
418 - location.block = previous;
419 - location.offset = location.block.getLength();
 438+ block = previous;
 439+ offset = block.getLength();
420440 }
421441 }
422442 this.cursor.show(
423 - location.block.flow.getPosition( location.offset ),
424 - location.block.$.offset()
 443+ block.flow.getPosition( offset ),
 444+ block.$.offset()
425445 );
 446+
 447+ this.location = new Location( block, offset );
426448 };
427449
428450 /**

Status & tagging log