Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | this.rendered = false; |
14 | 14 | this.location = null; |
15 | 15 | this.selection = new Selection(); |
16 | | - this.selecting = false; |
| 16 | + this.mouseSelecting = false; |
17 | 17 | this.keydownTimeout = null; |
18 | 18 | this.initialHorizontalCursorPosition = null; |
19 | 19 | |
— | — | @@ -148,20 +148,28 @@ |
149 | 149 | } |
150 | 150 | |
151 | 151 | Surface.prototype.handleBackspace = function() { |
152 | | - var location = this.getLocation(); |
153 | | - if ( location.offset > 0 ) { |
154 | | - location.block.deleteContent( location.offset - 1, location.offset ); |
155 | | - location.offset--; |
156 | | - this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() ); |
| 152 | + var block = this.location.block, |
| 153 | + offset = this.location.offset; |
| 154 | + |
| 155 | + if ( offset > 0 ) { |
| 156 | + block.deleteContent( offset - 1, offset ); |
| 157 | + offset--; |
| 158 | + this.cursor.show( block.flow.getPosition( offset ), block.$.offset() ); |
157 | 159 | } |
| 160 | + |
| 161 | + this.location = new Location( block, offset ); |
158 | 162 | } |
159 | 163 | |
160 | 164 | Surface.prototype.handleDelete = function() { |
161 | | - var location = this.getLocation(); |
162 | | - if ( location.offset < location.block.getLength() - 1 ) { |
163 | | - location.block.deleteContent( location.offset, location.offset + 1); |
164 | | - this.cursor.show( location.block.flow.getPosition( location.offset ), location.block.$.offset() ); |
| 165 | + var block = this.location.block, |
| 166 | + offset = this.location.offset; |
| 167 | + |
| 168 | + if ( offset < block.getLength() - 1 ) { |
| 169 | + block.deleteContent( offset, offset + 1); |
| 170 | + this.cursor.show( block.flow.getPosition( offset ), block.$.offset() ); |
165 | 171 | } |
| 172 | + |
| 173 | + this.location = new Location( block, offset ); |
166 | 174 | }; |
167 | 175 | |
168 | 176 | Surface.prototype.onMouseDown = function( e ) { |
— | — | @@ -171,7 +179,7 @@ |
172 | 180 | var cursorPosition = this.location.block.getPosition( this.location.offset ); |
173 | 181 | this.cursor.show( cursorPosition, this.location.block.$.offset() ); |
174 | 182 | this.$input.css( 'top', cursorPosition.top ); |
175 | | - this.selecting = true; |
| 183 | + this.mouseSelecting = true; |
176 | 184 | this.drawSelection(); |
177 | 185 | this.cursor.show(); |
178 | 186 | } |
— | — | @@ -183,7 +191,7 @@ |
184 | 192 | }; |
185 | 193 | |
186 | 194 | Surface.prototype.onMouseMove = function( e ) { |
187 | | - if ( e.button === 0 && this.selecting ) { |
| 195 | + if ( e.button === 0 && this.mouseSelecting ) { |
188 | 196 | this.cursor.hide(); |
189 | 197 | this.selection.to = this.getLocationFromEvent( e ); |
190 | 198 | this.drawSelection(); |
— | — | @@ -195,7 +203,7 @@ |
196 | 204 | this.drawSelection(); |
197 | 205 | this.cursor.hide(); |
198 | 206 | } |
199 | | - this.selecting = false; |
| 207 | + this.mouseSelecting = false; |
200 | 208 | }; |
201 | 209 | |
202 | 210 | /** |
— | — | @@ -336,8 +344,9 @@ |
337 | 345 | * Moves the cursor to the nearest location directly above the current flowed line. |
338 | 346 | */ |
339 | 347 | Surface.prototype.moveCursorUp = function() { |
340 | | - var location = this.getLocation(), |
341 | | - position = location.block.getPosition( location.offset ); |
| 348 | + var block = this.location.block, |
| 349 | + offset = this.location.offset, |
| 350 | + position = block.getPosition( offset ); |
342 | 351 | |
343 | 352 | if ( this.initialHorizontalCursorPosition ) { |
344 | 353 | position.left = this.initialHorizontalCursorPosition; |
— | — | @@ -347,23 +356,26 @@ |
348 | 357 | |
349 | 358 | position.top = position.top - 1; |
350 | 359 | if ( position.top < 0 ) { |
351 | | - var previousBlock = location.block.previousBlock(); |
| 360 | + var previousBlock = block.previousBlock(); |
352 | 361 | if ( previousBlock ) { |
353 | | - location.block = previousBlock; |
354 | | - position.top += location.block.$.height(); |
| 362 | + block = previousBlock; |
| 363 | + position.top += block.$.height(); |
355 | 364 | } |
356 | 365 | } |
357 | | - location.offset = location.block.getOffset( position ); |
358 | | - position = location.block.getPosition( location.offset ); |
359 | | - this.cursor.show( position, location.block.$.offset() ); |
| 366 | + offset = block.getOffset( position ); |
| 367 | + position = block.getPosition( offset ); |
| 368 | + this.cursor.show( position, block.$.offset() ); |
| 369 | + |
| 370 | + this.location = new Location( block, offset ); |
360 | 371 | }; |
361 | 372 | |
362 | 373 | /** |
363 | 374 | * Moves the cursor to the nearest location directly below the current flowed line. |
364 | 375 | */ |
365 | 376 | Surface.prototype.moveCursorDown = function() { |
366 | | - var location = this.getLocation() |
367 | | - position = location.block.getPosition( location.offset ); |
| 377 | + var block = this.location.block, |
| 378 | + offset = this.location.offset, |
| 379 | + position = block.getPosition( offset ); |
368 | 380 | |
369 | 381 | if ( this.initialHorizontalCursorPosition ) { |
370 | 382 | position.left = this.initialHorizontalCursorPosition; |
— | — | @@ -372,56 +384,66 @@ |
373 | 385 | } |
374 | 386 | |
375 | 387 | position.top = position.bottom + 1; |
376 | | - if ( position.top > location.block.$.height() ) { |
377 | | - var nextBlock = location.block.nextBlock(); |
| 388 | + if ( position.top > block.$.height() ) { |
| 389 | + var nextBlock = block.nextBlock(); |
378 | 390 | if ( nextBlock ) { |
379 | | - position.top -= location.block.$.height(); |
380 | | - location.block = nextBlock; |
| 391 | + position.top -= block.$.height(); |
| 392 | + block = nextBlock; |
381 | 393 | } |
382 | 394 | } |
383 | | - location.offset = location.block.getOffset( position ); |
384 | | - position = location.block.getPosition( location.offset ); |
385 | | - this.cursor.show( position, location.block.$.offset() ); |
| 395 | + offset = block.getOffset( position ); |
| 396 | + position = block.getPosition( offset ); |
| 397 | + this.cursor.show( position, block.$.offset() ); |
| 398 | + |
| 399 | + this.location = new Location( block, offset ); |
386 | 400 | }; |
387 | 401 | |
388 | 402 | /** |
389 | 403 | * Moves the cursor backward of the current position. |
390 | 404 | */ |
391 | 405 | Surface.prototype.moveCursorRight = function() { |
392 | | - var location = this.getLocation(); |
393 | | - if ( location.offset < location.block.getLength() ) { |
394 | | - location.offset++; |
| 406 | + var block = this.location.block, |
| 407 | + offset = this.location.offset; |
| 408 | + |
| 409 | + if ( offset < block.getLength() ) { |
| 410 | + offset++; |
395 | 411 | } else { |
396 | | - var next = location.block.nextBlock(); |
| 412 | + var next = block.nextBlock(); |
397 | 413 | if ( next ) { |
398 | | - location.block = next; |
399 | | - location.offset = 0; |
| 414 | + block = next; |
| 415 | + offset = 0; |
400 | 416 | } |
401 | 417 | } |
402 | 418 | this.cursor.show( |
403 | | - location.block.flow.getPosition( location.offset ), |
404 | | - location.block.$.offset() |
| 419 | + block.flow.getPosition( offset ), |
| 420 | + block.$.offset() |
405 | 421 | ); |
| 422 | + |
| 423 | + this.location = new Location( block, offset ); |
406 | 424 | }; |
407 | 425 | |
408 | 426 | /** |
409 | 427 | * Moves the cursor forward of the current position. |
410 | 428 | */ |
411 | 429 | Surface.prototype.moveCursorLeft = function() { |
412 | | - var location = this.getLocation(); |
413 | | - if ( location.offset > 0 ) { |
414 | | - location.offset--; |
| 430 | + var block = this.location.block, |
| 431 | + offset = this.location.offset; |
| 432 | + |
| 433 | + if ( offset > 0 ) { |
| 434 | + offset--; |
415 | 435 | } else { |
416 | | - var previous = location.block.previousBlock(); |
| 436 | + var previous = block.previousBlock(); |
417 | 437 | if ( previous ) { |
418 | | - location.block = previous; |
419 | | - location.offset = location.block.getLength(); |
| 438 | + block = previous; |
| 439 | + offset = block.getLength(); |
420 | 440 | } |
421 | 441 | } |
422 | 442 | this.cursor.show( |
423 | | - location.block.flow.getPosition( location.offset ), |
424 | | - location.block.$.offset() |
| 443 | + block.flow.getPosition( offset ), |
| 444 | + block.$.offset() |
425 | 445 | ); |
| 446 | + |
| 447 | + this.location = new Location( block, offset ); |
426 | 448 | }; |
427 | 449 | |
428 | 450 | /** |