r91680 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91679‎ | r91680 | r91681 >
Date:20:47, 7 July 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Changed cursor to take positions, and not know of surface.
Modified paths:
  • /trunk/parsers/wikidom/lib/es/es.Cursor.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.Surface.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.TextFlow.js (modified) (history)
  • /trunk/parsers/wikidom/lib/es/es.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/es/es.js
@@ -31,13 +31,17 @@
3232 /**
3333 * Pixel position, a 2D position within a rendered document.
3434 *
35 - * @param x {Integer} Horizontal position
36 - * @param y {Integer} Vertical position
 35+ * This can also support an optional bottom field, to represent a vertical line, such as a cursor.
 36+ *
 37+ * @param left {Integer} Horizontal position
 38+ * @param top {Integer} Vertical position (of top, if bottom is used)
 39+ * @param bottom {Integer} Vertical position of bottom (optional)
3740 * @returns {Position}
3841 */
39 -function Position( x, y ) {
40 - this.x = x || 0;
41 - this.y = y || 0;
 42+function Position( left, top, bottom ) {
 43+ this.left = left || 0;
 44+ this.top = top || 0;
 45+ this.bottom = bottom || 0;
4246 }
4347
4448 /**
Index: trunk/parsers/wikidom/lib/es/es.Surface.js
@@ -35,6 +35,7 @@
3636
3737 // Cursor
3838 this.cursor = new Cursor( this );
 39+ this.$.after( this.cursor.$ );
3940
4041 // Hidden input
4142 this.$input = $( '<input/>' );
@@ -90,9 +91,12 @@
9192 }
9293 var block = $block.data( 'block' )
9394 blockOffset = $block.offset()
94 - position = new Position( e.pageX - blockOffset.left, e.pageY - blockOffset.top )
95 - offset = block.flow.getOffset( position );
96 - this.cursor.show( new Location( block, offset ) );
 95+ mousePosition = new Position( e.pageX - blockOffset.left, e.pageY - blockOffset.top )
 96+ nearestOffset = block.flow.getOffset( mousePosition ),
 97+ cursorPosition = block.flow.getPosition( nearestOffset );
 98+
 99+ this.cursor.show( cursorPosition, blockOffset );
 100+
97101 this.$input.focus();
98102 return false;
99103 };
@@ -158,8 +162,8 @@
159163 location.block = block.previous();
160164 }
161165 var above = this.getPosition( location );
162 - if ( above.y < below.y ) {
163 - var distance = below.x - above.x;
 166+ if ( above.top < below.top ) {
 167+ var distance = below.left - above.left;
164168 if ( minDistance > distance ) {
165169 location.offset++;
166170 break;
@@ -184,8 +188,8 @@
185189 location.block = block.next();
186190 }
187191 var below = this.getPosition( location );
188 - if ( above.y < below.y ) {
189 - var distance = below.x - above.x;
 192+ if ( above.top < below.top ) {
 193+ var distance = below.left - above.left;
190194 if ( minDistance > distance ) {
191195 location.offset++;
192196 break;
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js
@@ -63,7 +63,7 @@
6464 */
6565 while ( line < lineCount ) {
6666 bottom += this.lines[line].height;
67 - if ( position.y >= top && position.y < bottom ) {
 67+ if ( position.top >= top && position.top < bottom ) {
6868 break;
6969 }
7070 top = bottom;
@@ -74,14 +74,16 @@
7575 * Offset finding
7676 *
7777 * Now that we know which line we are on, we can just use the "fitCharacters" method to get the
78 - * last offset before "position.x".
 78+ * last offset before "position.left".
7979 *
8080 * TODO: The offset needs to be chosen based on nearest offset to the cursor, not offset before
8181 * the cursor.
8282 */
8383 var $ruler = $( '<div class="editSurface-line"></div>' ).appendTo( this.$ )
8484 ruler = $ruler[0],
85 - fit = this.fitCharacters( this.lines[line].start, this.lines[line].end, ruler, position.x );
 85+ fit = this.fitCharacters(
 86+ this.lines[line].start, this.lines[line].end, ruler, position.left
 87+ );
8688 ruler.innerHTML = this.escape( this.text.substring( this.lines[line].start, fit.end ) );
8789 var left = ruler.clientWidth;
8890 ruler.innerHTML = this.escape( this.text.substring( this.lines[line].start, fit.end + 1 ) );
@@ -93,7 +95,10 @@
9496 var virtual = line < this.lines.length - 1
9597 && this.boundaryTest( this.lines[line].text.substr( -1, 1 ) )
9698 ? -1 : 0;
97 - return Math.min( fit.end + ( position.x >= center ? 1 : 0 ), this.lines[line].end + virtual );
 99+ return Math.min(
 100+ fit.end + ( position.left >= center ? 1 : 0 ),
 101+ this.lines[line].end + virtual
 102+ );
98103 };
99104
100105 /**
Index: trunk/parsers/wikidom/lib/es/es.Cursor.js
@@ -2,54 +2,44 @@
33 *
44 * @returns {Cursor}
55 */
6 -function Cursor( surface ) {
7 - this.surface = surface;
 6+function Cursor() {
87 this.cursorInterval = null;
9 - this.$cursor = $( '<div class="editSurface-cursor"></div>' );
10 - this.surface.$.after( this.$cursor );
 8+ this.$ = $( '<div class="editSurface-cursor"></div>' );
119 }
1210
1311 /**
14 - * Shows the cursor in a new location.
 12+ * Shows the cursor in a new position.
1513 *
16 - * @param location {Location} Location to show the cursor in
 14+ * @param position {Position} Position to show the cursor at
 15+ * @param offset {Position} Offset to be added to position
1716 */
18 -Cursor.prototype.show = function( location ) {
19 - this.surface.location = location;
20 -
21 - var position = this.surface.location.block.getPosition( this.surface.location.offset );
22 - var offset = this.surface.location.block.$.offset();
23 -
24 - this.$cursor.css({
25 - 'left': position.left + offset.left,
26 - 'top': position.top + offset.top
 17+Cursor.prototype.show = function( position, offset ) {
 18+ if ( $.isPlainObject( offset ) ) {
 19+ position.left += offset.left;
 20+ position.top += offset.top;
 21+ position.bottom += offset.top;
 22+ }
 23+ this.$.css({
 24+ 'left': position.left,
 25+ 'top': position.top,
 26+ 'height': position.bottom - position.top
2727 }).show();
2828
29 - if( this.cursorInterval ) {
 29+ if ( this.cursorInterval ) {
3030 clearInterval( this.cursorInterval );
3131 }
3232 this.cursorInterval = setInterval( function( cursor ) {
33 - cursor.$cursor.css( 'display' ) == 'block' ? cursor.$cursor.hide() : cursor.$cursor.show();
 33+ cursor.$.css( 'display' ) == 'block'
 34+ ? cursor.$.hide() : cursor.$.show();
3435 }, 500, this );
3536 };
3637
3738 /**
3839 * Hides the cursor.
39 - *
40 - * @returns {Location}
4140 */
4241 Cursor.prototype.hide = function() {
4342 if( this.cursorInterval ) {
4443 clearInterval( this.cursorInterval );
4544 }
46 - this.$cursor.hide()
 45+ this.$.hide()
4746 };
48 -
49 -/**
50 - * Gets the current location of the cursor.
51 - *
52 - * @returns {Location}
53 - */
54 -Cursor.prototype.get = function() {
55 - return this.surface.location;
56 -};
\ No newline at end of file

Status & tagging log