Index: trunk/parsers/wikidom/lib/synth/views/es.ListBlockView.js |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 | es.ListBlockView.prototype.getOffsetFromPosition = function( position ) { |
23 | 23 | var contentOffset; |
24 | 24 | var itemHeight; |
| 25 | + var offset = 0; |
25 | 26 | for ( var i = 0; i < this.items.length; i++ ) { |
26 | 27 | contentOffset = this.items[i].$content.offset(); |
27 | 28 | if ( position.top >= contentOffset.top ) { |
— | — | @@ -28,9 +29,10 @@ |
29 | 30 | if ( position.top < contentOffset.top + itemHeight ) { |
30 | 31 | position.left -= contentOffset.left; |
31 | 32 | position.top -= contentOffset.top; |
32 | | - return this.items[i].contentView.getOffset( position ); |
| 33 | + return offset + this.items[i].contentView.getOffset( position ); |
33 | 34 | } |
34 | 35 | } |
| 36 | + offset += this.items[i].getLength() + 1; |
35 | 37 | } |
36 | 38 | |
37 | 39 | while(!documentView.list) { |
Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -34,6 +34,9 @@ |
35 | 35 | } |
36 | 36 | }; |
37 | 37 | |
| 38 | + this.selecting = false; |
| 39 | + this.from = this.to = 0; |
| 40 | + |
38 | 41 | // Cursor |
39 | 42 | this.blinkInterval = null; |
40 | 43 | this.$cursor = $( '<div class="editSurface-cursor"></div>' ).appendTo( this.$ ); |
— | — | @@ -237,15 +240,30 @@ |
238 | 241 | es.SurfaceView.prototype.onMouseDown = function( e ) { |
239 | 242 | var position = es.Position.newFromEventPagePosition( e ); |
240 | 243 | var offset = this.documentView.getOffsetFromPosition( position ); |
241 | | - console.log( offset ); |
| 244 | + this.from = offset; |
| 245 | + this.selecting = true; |
| 246 | + |
| 247 | + console.log(offset); |
| 248 | + |
| 249 | + if ( !this.$input.is(':focus') ) { |
| 250 | + this.$input.focus().select(); |
| 251 | + } |
| 252 | + |
242 | 253 | return false; |
243 | 254 | }; |
244 | 255 | |
245 | 256 | es.SurfaceView.prototype.onMouseMove = function( e ) { |
| 257 | + if (this.selecting ) { |
| 258 | + var position = es.Position.newFromEventPagePosition( e ); |
| 259 | + var offset = this.documentView.getOffsetFromPosition( position ); |
| 260 | + this.to = offset; |
| 261 | + this.documentView.drawSelection( new es.Range( this.from, this.to ) ); |
| 262 | + } |
246 | 263 | // TODO: Respond to mouse move event, updating selection while painting |
247 | 264 | }; |
248 | 265 | |
249 | 266 | es.SurfaceView.prototype.onMouseUp = function( e ) { |
| 267 | + this.selecting = false; |
250 | 268 | // TODO: Respond to mouse up event, possibly ending selection painting |
251 | 269 | }; |
252 | 270 | |
Index: trunk/parsers/wikidom/lib/synth/views/es.ContentView.js |
— | — | @@ -126,7 +126,8 @@ |
127 | 127 | '\'': ''', |
128 | 128 | '"': '"', |
129 | 129 | '\n': '<span class="editSurface-whitespace">¶</span>', |
130 | | - '\t': '<span class="editSurface-whitespace">⇾</span>' |
| 130 | + '\t': '<span class="editSurface-whitespace">⇾</span>', |
| 131 | + ' ': ' ' |
131 | 132 | }; |
132 | 133 | |
133 | 134 | /* Static Methods */ |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockRowView.js |
— | — | @@ -17,15 +17,17 @@ |
18 | 18 | es.TableBlockRowView.prototype.getOffsetFromPosition = function( position ) { |
19 | 19 | var cellOffset; |
20 | 20 | var itemWidth; |
| 21 | + var offset = 0; |
21 | 22 | |
22 | 23 | for ( var i = 0; i < this.items.length; i++ ) { |
23 | 24 | cellOffset = this.items[i].$.offset(); |
24 | 25 | if ( position.left >= cellOffset.left ) { |
25 | 26 | itemWidth = this.items[i].$.width(); |
26 | 27 | if ( position.left < cellOffset.left + itemWidth ) { |
27 | | - return this.items[i].getOffsetFromPosition( position ); |
| 28 | + return offset + this.items[i].getOffsetFromPosition( position ); |
28 | 29 | } |
29 | 30 | } |
| 31 | + offset += this.items[i].getLength() + 1; |
30 | 32 | } |
31 | 33 | }; |
32 | 34 | |
Index: trunk/parsers/wikidom/lib/synth/views/es.DocumentView.js |
— | — | @@ -16,16 +16,23 @@ |
17 | 17 | if ( this.items.length === 0 ) { |
18 | 18 | return 0; |
19 | 19 | } |
| 20 | + |
| 21 | + var blockView = this.items[0], |
| 22 | + blockLength = 0, |
| 23 | + offset = 0; |
20 | 24 | |
21 | | - var blockView = this.items[0]; |
22 | 25 | for ( var i = 0; i < this.items.length; i++ ) { |
23 | 26 | if ( this.items[i].$.offset().top >= position.top ) { |
24 | 27 | break; |
25 | 28 | } |
26 | 29 | blockView = this.items[i]; |
| 30 | + blockLength = blockView.getLength(); |
| 31 | + offset += blockLength + 1; |
27 | 32 | } |
28 | 33 | |
29 | | - return blockView.getOffsetFromPosition( position ); |
| 34 | + offset -= blockLength + 1; |
| 35 | + |
| 36 | + return offset + blockView.getOffsetFromPosition( position ); |
30 | 37 | }; |
31 | 38 | |
32 | 39 | /** |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockCellView.js |
— | — | @@ -16,18 +16,29 @@ |
17 | 17 | es.TableBlockCellView.prototype.getOffsetFromPosition = function( position ) { |
18 | 18 | var blockOffset; |
19 | 19 | var itemHeight; |
| 20 | + var offset = 0; |
20 | 21 | |
21 | 22 | for ( var i = 0; i < this.items.length; i++ ) { |
22 | 23 | blockOffset = this.items[i].$.offset(); |
23 | 24 | if ( position.top >= blockOffset.top ) { |
24 | 25 | itemHeight = this.items[i].$.height(); |
25 | 26 | if ( position.top < blockOffset.top + itemHeight ) { |
26 | | - return this.items[i].getOffsetFromPosition( position ); |
| 27 | + return offset + this.items[i].getOffsetFromPosition( position ); |
27 | 28 | } |
28 | 29 | } |
| 30 | + offset += this.items[i].getLength() + 1; |
29 | 31 | } |
30 | 32 | }; |
31 | 33 | |
| 34 | +/** |
| 35 | + * Gets length of contents. |
| 36 | + * |
| 37 | + * @method |
| 38 | + * @returns {Integer} Length of content, including any virtual spaces within the block |
| 39 | + */ |
| 40 | +es.TableBlockCellView.prototype.getLength = function() { |
| 41 | + return this.items.getLengthOfItems(); |
| 42 | +}; |
32 | 43 | |
33 | 44 | /** |
34 | 45 | * Render content. |
— | — | @@ -69,19 +80,16 @@ |
70 | 81 | * @param range {es.Range} Range of content to draw selection around |
71 | 82 | */ |
72 | 83 | es.TableBlockCellView.prototype.drawSelection = function( range ) { |
73 | | - this.documentView.drawSelection( range ); |
| 84 | + var selectedViews = this.items.select( range ); |
| 85 | + for ( var i = 0; i < selectedViews.length; i++ ) { |
| 86 | + selectedViews[i].item.drawSelection( |
| 87 | + new es.Range( selectedViews[i].from, selectedViews[i].to ) |
| 88 | + ); |
| 89 | + } |
74 | 90 | }; |
75 | 91 | |
76 | | -/** |
77 | | - * Gets length of contents. |
78 | | - * |
79 | | - * @method |
80 | | - * @returns {Integer} Length of content, including any virtual spaces within the block |
81 | | - */ |
82 | | -es.TableBlockCellView.prototype.getLength = function() { |
83 | | - return this.documentView.getLength(); |
84 | | -}; |
85 | 92 | |
| 93 | + |
86 | 94 | /** |
87 | 95 | * Gets HTML rendering of block. |
88 | 96 | * |
Index: trunk/parsers/wikidom/lib/synth/views/es.TableBlockView.js |
— | — | @@ -18,15 +18,17 @@ |
19 | 19 | es.TableBlockView.prototype.getOffsetFromPosition = function( position ) { |
20 | 20 | var rowOffset; |
21 | 21 | var itemHeight; |
| 22 | + var offset = 0; |
22 | 23 | |
23 | 24 | for ( var i = 0; i < this.items.length; i++ ) { |
24 | 25 | rowOffset = this.items[i].$.offset(); |
25 | 26 | if ( position.top >= rowOffset.top ) { |
26 | 27 | itemHeight = this.items[i].$.height(); |
27 | 28 | if ( position.top < rowOffset.top + itemHeight ) { |
28 | | - return this.items[i].getOffsetFromPosition( position ); |
| 29 | + return offset + this.items[i].getOffsetFromPosition( position ); |
29 | 30 | } |
30 | 31 | } |
| 32 | + offset += this.items[i].getLength() + 1; |
31 | 33 | } |
32 | 34 | }; |
33 | 35 | |
Index: trunk/parsers/wikidom/demos/synth/es.js |
— | — | @@ -83,6 +83,56 @@ |
84 | 84 | 'content': { 'text': 'row 2 & cell 2' } |
85 | 85 | }, |
86 | 86 | { |
| 87 | + 'type': 'table', |
| 88 | + 'attributes': { 'style': 'width: 150px; border: solid 1px;' }, |
| 89 | + 'rows': [ |
| 90 | + { |
| 91 | + 'cells': [ |
| 92 | + { |
| 93 | + 'attributes': { 'style': 'border: solid 1px;' }, |
| 94 | + 'blocks': [ |
| 95 | + { |
| 96 | + 'type': 'paragraph', |
| 97 | + 'content': { 'text': '#1 #1 #1' } |
| 98 | + } |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + 'attributes': { 'style': 'border: solid 1px;' }, |
| 103 | + 'blocks': [ |
| 104 | + { |
| 105 | + 'type': 'paragraph', |
| 106 | + 'content': { 'text': '#2 #2 #2' } |
| 107 | + } |
| 108 | + ] |
| 109 | + } |
| 110 | + ] |
| 111 | + }, |
| 112 | + { |
| 113 | + 'cells': [ |
| 114 | + { |
| 115 | + 'attributes': { 'style': 'border: solid 1px;' }, |
| 116 | + 'blocks': [ |
| 117 | + { |
| 118 | + 'type': 'paragraph', |
| 119 | + 'content': { 'text': '#3 #3 #3' } |
| 120 | + } |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + 'attributes': { 'style': 'border: solid 1px;' }, |
| 125 | + 'blocks': [ |
| 126 | + { |
| 127 | + 'type': 'paragraph', |
| 128 | + 'content': { 'text': '#4 #4 #4' } |
| 129 | + } |
| 130 | + ] |
| 131 | + } |
| 132 | + ] |
| 133 | + } |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
87 | 137 | 'type': 'list', |
88 | 138 | 'style': 'number', |
89 | 139 | 'items': [ |