Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -23,13 +23,26 @@ |
24 | 24 | this.document = document; |
25 | 25 | this.rendered = false; |
26 | 26 | this.location = null; |
| 27 | + this.selection = null; |
27 | 28 | this.render(); |
28 | | - |
| 29 | + |
| 30 | + this.state = { |
| 31 | + 'selection': { |
| 32 | + 'active': false |
| 33 | + } |
| 34 | + }; |
| 35 | + |
29 | 36 | var surface = this; |
30 | 37 | |
31 | 38 | this.$.bind({ |
32 | 39 | 'mousedown' : function(e) { |
33 | 40 | return surface.onMouseDown( e ); |
| 41 | + }, |
| 42 | + 'mousemove' : function(e) { |
| 43 | + return surface.onMouseMove( e ); |
| 44 | + }, |
| 45 | + 'mouseup' : function(e) { |
| 46 | + return surface.onMouseUp( e ); |
34 | 47 | } |
35 | 48 | }); |
36 | 49 | |
— | — | @@ -72,40 +85,51 @@ |
73 | 86 | ? $target : $target.closest( '.editSurface-block' ); |
74 | 87 | // Not a block or child of a block? Find the nearest block... |
75 | 88 | if( !$block.length ) { |
76 | | - var minDistance, |
77 | | - $blocks = this.$.find( '> .editSurface-document .editSurface-block' ); |
| 89 | + $blocks = this.$.find( '> .editSurface-document .editSurface-block' ); |
| 90 | + $block = $blocks.first(); |
78 | 91 | $blocks.each( function() { |
79 | | - var top = $(this).offset().top, |
80 | | - bottom = top + $(this).height(); |
81 | | - // Inside test |
82 | | - if ( e.pageY >= top && e.pageY < bottom ) { |
83 | | - $block = $(this); |
| 92 | + // Stop looking when mouse is above top |
| 93 | + if ( e.pageY <= $(this).offset().top ) { |
84 | 94 | return false; |
85 | 95 | } |
86 | | - // Distance test |
87 | | - var distance = Math.abs( e.pageY - top ); |
88 | | - if ( typeof minDistance === 'undefined' || distance < minDistance ) { |
89 | | - minDistance = distance; |
90 | | - $block = $(this); |
91 | | - } |
| 96 | + $block = $(this); |
92 | 97 | } ); |
93 | | - if ( !$block.length ) { |
94 | | - $block = $blocks.first(); |
95 | | - } |
96 | 98 | } |
97 | 99 | var block = $block.data( 'block' ) |
98 | | - blockOffset = $block.offset() |
99 | | - mousePosition = new Position( e.pageX - blockOffset.left, e.pageY - blockOffset.top ) |
| 100 | + blockPosition = $block.offset() |
| 101 | + mousePosition = new Position( e.pageX - blockPosition.left, e.pageY - blockPosition.top ) |
100 | 102 | nearestOffset = block.flow.getOffset( mousePosition ), |
101 | 103 | cursorPosition = block.flow.getPosition( nearestOffset ); |
102 | 104 | |
103 | | - this.cursor.show( cursorPosition, blockOffset ); |
| 105 | + this.cursor.show( cursorPosition, blockPosition ); |
104 | 106 | this.location = new Location( block, nearestOffset ); |
105 | 107 | |
| 108 | + this.state.selection = { |
| 109 | + 'active': true, |
| 110 | + 'from': null, |
| 111 | + 'to': null, |
| 112 | + 'start': nearestOffset, |
| 113 | + 'end': null |
| 114 | + }; |
| 115 | + |
106 | 116 | this.$input.focus(); |
107 | 117 | return false; |
108 | 118 | }; |
109 | 119 | |
| 120 | +Surface.prototype.onMouseMove = function( e ) { |
| 121 | + var sel = this.state.selection; |
| 122 | + if ( sel.active ) { |
| 123 | + // |
| 124 | + } |
| 125 | +}; |
| 126 | + |
| 127 | +Surface.prototype.onMouseUp = function( e ) { |
| 128 | + var sel = this.state.selection; |
| 129 | + if ( sel.active ) { |
| 130 | + sel.active = false; |
| 131 | + } |
| 132 | +}; |
| 133 | + |
110 | 134 | /** |
111 | 135 | * Sets the selection to a new range. |
112 | 136 | * |
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js |
— | — | @@ -47,11 +47,10 @@ |
48 | 48 | * @return {Integer} Offset within content nearest the given coordinates |
49 | 49 | */ |
50 | 50 | TextFlow.prototype.getOffset = function( position ) { |
51 | | - var line = 0, |
52 | | - lineCount = this.lines.length, |
| 51 | + var lineCount = this.lines.length, |
| 52 | + line = 0, |
53 | 53 | offset = 0, |
54 | | - top = 0, |
55 | | - bottom = 0; |
| 54 | + top = 0; |
56 | 55 | |
57 | 56 | /* |
58 | 57 | * Line finding |
— | — | @@ -62,13 +61,12 @@ |
63 | 62 | * positions, which is a nice benefit of this method. |
64 | 63 | */ |
65 | 64 | while ( line < lineCount ) { |
66 | | - bottom += this.lines[line].height; |
67 | | - if ( position.top >= top && position.top < bottom ) { |
| 65 | + top += this.lines[line].height; |
| 66 | + if ( position.top <= top ) { |
68 | 67 | break; |
69 | 68 | } |
70 | | - top = bottom; |
71 | 69 | line++; |
72 | | - }; |
| 70 | + } |
73 | 71 | |
74 | 72 | /* |
75 | 73 | * Offset finding |
— | — | @@ -79,6 +77,9 @@ |
80 | 78 | * TODO: The offset needs to be chosen based on nearest offset to the cursor, not offset before |
81 | 79 | * the cursor. |
82 | 80 | */ |
| 81 | + var virtual = line < this.lines.length - 1 |
| 82 | + && this.boundaryTest.exec( this.lines[line].text.substr( -1 ) ) ? -1 : 0; |
| 83 | + line = Math.min( line, this.lines.length - 1 ); |
83 | 84 | var $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( this.$ ) |
84 | 85 | ruler = $ruler[0], |
85 | 86 | fit = this.fitCharacters( |
— | — | @@ -92,9 +93,6 @@ |
93 | 94 | $ruler.remove(); |
94 | 95 | // Reset RegExp object's state |
95 | 96 | this.boundaryTest.lastIndex = 0; |
96 | | - var virtual = line < this.lines.length - 1 |
97 | | - && this.boundaryTest.exec( this.lines[line].text.substr( -1, 1 ) ) |
98 | | - ? -1 : 0; |
99 | 97 | return Math.min( |
100 | 98 | fit.end + ( position.left >= center ? 1 : 0 ), |
101 | 99 | this.lines[line].end + virtual |