Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -238,8 +238,7 @@ |
239 | 239 | }; |
240 | 240 | |
241 | 241 | es.SurfaceView.prototype.onMouseDown = function( e ) { |
242 | | - var mousePosition = es.Position.newFromEventPagePosition( e ); |
243 | | - var contentOffset = this.documentView.getOffsetFromPosition( mousePosition ); |
| 242 | + var contentOffset = this.documentView.getOffsetFromEvent( e ); |
244 | 243 | |
245 | 244 | this.from = contentOffset; |
246 | 245 | this.selecting = true; |
— | — | @@ -253,8 +252,7 @@ |
254 | 253 | |
255 | 254 | es.SurfaceView.prototype.onMouseMove = function( e ) { |
256 | 255 | if (this.selecting ) { |
257 | | - var mousePosition = es.Position.newFromEventPagePosition( e ); |
258 | | - var contentOffset = this.documentView.getOffsetFromPosition( mousePosition ); |
| 256 | + var contentOffset = this.documentView.getOffsetFromEvent( e ); |
259 | 257 | |
260 | 258 | this.to = contentOffset; |
261 | 259 | this.documentView.drawSelection( new es.Range( this.from, this.to ) ); |
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js |
— | — | @@ -12,6 +12,25 @@ |
13 | 13 | |
14 | 14 | /* Methods */ |
15 | 15 | |
| 16 | +es.DocumentView.prototype.getOffsetFromEvent = function( e ) { |
| 17 | + var $target = $( e.target ), |
| 18 | + $block = $target.is( '.editSurface-block' ) |
| 19 | + ? $target : $target.closest( '.editSurface-block' ), |
| 20 | + position = es.Position.newFromEventPagePosition( e ); |
| 21 | + |
| 22 | + if( $block.length ) { |
| 23 | + var block = $block.data( 'block' ), |
| 24 | + offset = block.getOffsetFromPosition( position ); |
| 25 | + while ( typeof block.list !== 'undefined' ) { |
| 26 | + offset += block.list.items.offsetOf( block ); |
| 27 | + block = block.list; |
| 28 | + } |
| 29 | + return offset; |
| 30 | + } else { |
| 31 | + return this.getOffsetFromPosition( position ); |
| 32 | + } |
| 33 | +}; |
| 34 | + |
16 | 35 | es.DocumentView.prototype.getOffsetFromPosition = function( position ) { |
17 | 36 | if ( this.items.length === 0 ) { |
18 | 37 | return 0; |