Index: trunk/parsers/wikidom/lib/es/es.Flow.js |
— | — | @@ -33,18 +33,14 @@ |
34 | 34 | |
35 | 35 | // Events |
36 | 36 | var flow = this; |
37 | | - this.content.on( 'insert', function( args ) { |
| 37 | + function render( args ) { |
38 | 38 | flow.scanBoundaries(); |
39 | 39 | 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 ); |
49 | 45 | |
50 | 46 | // Initialization |
51 | 47 | this.scanBoundaries(); |
— | — | @@ -70,6 +66,11 @@ |
71 | 67 | * @return {Integer} Offset within content nearest the given coordinates |
72 | 68 | */ |
73 | 69 | es.Flow.prototype.getOffset = function( position ) { |
| 70 | + // Empty content shortcut |
| 71 | + if ( this.content.getLength() === 0 ) { |
| 72 | + return 0; |
| 73 | + } |
| 74 | + |
74 | 75 | /* |
75 | 76 | * Line finding |
76 | 77 | * |
— | — | @@ -344,11 +345,20 @@ |
345 | 346 | |
346 | 347 | // Clear caches that were specific to the previous render |
347 | 348 | this.widthCache = {}; |
348 | | - |
| 349 | + |
349 | 350 | // In case of empty content we still want to display empty with non-breaking space inside |
350 | 351 | // This is very important for lists |
351 | 352 | if(this.content.getLength() === 0) { |
352 | | - this.$.empty().append( '<div class="editSurface-line" line-index="0"> </div>' ); |
| 353 | + var $line = $( '<div class="editSurface-line" line-index="0"> </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 | + }]; |
353 | 363 | this.emit( 'render' ); |
354 | 364 | return; |
355 | 365 | } |
Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -417,15 +417,18 @@ |
418 | 418 | if ( e.button === 0 && this.mouse.selecting ) { |
419 | 419 | this.cursor.hide(); |
420 | 420 | this.selection.to = this.getLocationFromEvent( e ); |
421 | | - this.drawSelection(); |
| 421 | + if (! this.drawSelection() ) { |
| 422 | + this.cursor.show(); |
| 423 | + } |
422 | 424 | } |
423 | 425 | }; |
424 | 426 | |
425 | 427 | es.Surface.prototype.onMouseUp = function( e ) { |
426 | 428 | if ( e.button === 0 && this.selection.to ) { |
427 | 429 | this.location = this.selection.to; |
428 | | - this.drawSelection(); |
429 | | - this.cursor.hide(); |
| 430 | + if ( this.drawSelection() ) { |
| 431 | + this.cursor.hide(); |
| 432 | + } |
430 | 433 | } |
431 | 434 | this.mouse.selecting = false; |
432 | 435 | }; |
— | — | @@ -460,6 +463,8 @@ |
461 | 464 | this.$rangeStart.hide(); |
462 | 465 | this.$rangeFill.hide(); |
463 | 466 | this.$rangeEnd.hide(); |
| 467 | + this.$input.val( '' ); |
| 468 | + return false; |
464 | 469 | } else if ( fromLineIndex === toLineIndex ) { |
465 | 470 | // Single line selection |
466 | 471 | this.$rangeStart |