r95247 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95246‎ | r95247 | r95248 >
Date:20:48, 22 August 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed some empty-content selection bugs
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Flow.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.Flow.js
@@ -33,18 +33,14 @@
3434
3535 // Events
3636 var flow = this;
37 - this.content.on( 'insert', function( args ) {
 37+ function render( args ) {
3838 flow.scanBoundaries();
3939 flow.render( args.offset );
40 - } );
41 - this.content.on( 'remove', function( args ) {
42 - flow.scanBoundaries();
43 - flow.render( args.start );
44 - } );
45 - this.content.on( 'annotate', function( args ) {
46 - flow.scanBoundaries();
47 - flow.render( args.start );
48 - } );
 40+ }
 41+ this.content.on( 'insert', render );
 42+ this.content.on( 'remove', render );
 43+ this.content.on( 'clear', render );
 44+ this.content.on( 'annotate', render );
4945
5046 // Initialization
5147 this.scanBoundaries();
@@ -70,6 +66,11 @@
7167 * @return {Integer} Offset within content nearest the given coordinates
7268 */
7369 es.Flow.prototype.getOffset = function( position ) {
 70+ // Empty content shortcut
 71+ if ( this.content.getLength() === 0 ) {
 72+ return 0;
 73+ }
 74+
7475 /*
7576 * Line finding
7677 *
@@ -344,11 +345,20 @@
345346
346347 // Clear caches that were specific to the previous render
347348 this.widthCache = {};
348 -
 349+
349350 // In case of empty content we still want to display empty with non-breaking space inside
350351 // This is very important for lists
351352 if(this.content.getLength() === 0) {
352 - this.$.empty().append( '<div class="editSurface-line" line-index="0">&nbsp;</div>' );
 353+ var $line = $( '<div class="editSurface-line" line-index="0">&nbsp;</div>' );
 354+ this.$.empty().append( $line );
 355+ this.lines = [{
 356+ 'text': ' ',
 357+ 'range': new es.Range( 0,0 ),
 358+ 'width': 0,
 359+ 'height': $line.outerHeight(),
 360+ 'wordOffset': 0,
 361+ 'fractional': false
 362+ }];
353363 this.emit( 'render' );
354364 return;
355365 }
Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -417,15 +417,18 @@
418418 if ( e.button === 0 && this.mouse.selecting ) {
419419 this.cursor.hide();
420420 this.selection.to = this.getLocationFromEvent( e );
421 - this.drawSelection();
 421+ if (! this.drawSelection() ) {
 422+ this.cursor.show();
 423+ }
422424 }
423425 };
424426
425427 es.Surface.prototype.onMouseUp = function( e ) {
426428 if ( e.button === 0 && this.selection.to ) {
427429 this.location = this.selection.to;
428 - this.drawSelection();
429 - this.cursor.hide();
 430+ if ( this.drawSelection() ) {
 431+ this.cursor.hide();
 432+ }
430433 }
431434 this.mouse.selecting = false;
432435 };
@@ -460,6 +463,8 @@
461464 this.$rangeStart.hide();
462465 this.$rangeFill.hide();
463466 this.$rangeEnd.hide();
 467+ this.$input.val( '' );
 468+ return false;
464469 } else if ( fromLineIndex === toLineIndex ) {
465470 // Single line selection
466471 this.$rangeStart

Status & tagging log