r101668 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101667‎ | r101668 | r101669 >
Date:20:08, 2 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Sort out Home/End buttons
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/views/es.SurfaceView.js
@@ -29,7 +29,8 @@
3030 $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ),
3131 interval: null,
3232 offset: null,
33 - initialLeft: null
 33+ initialLeft: null,
 34+ initialBias: false
3435 };
3536 this.keyboard = {
3637 selecting: false,
@@ -112,8 +113,6 @@
113114 } );
114115 };
115116
116 -es.SurfaceView.boundaryTest = /([ \-\t\r\n\f])/;
117 -
118117 es.SurfaceView.prototype.onMouseDown = function( e ) {
119118 var position = es.Position.newFromEventPagePosition( e ),
120119 offset = this.documentView.getOffsetFromEvent( e ),
@@ -209,29 +208,19 @@
210209 );
211210 } else if ( instruction === 'up' || instruction === 'down' ) {
212211 // ...
213 - } else if ( instruction === 'home' ) {
214 - if ( wasLeftBias ) {
215 - this.showCursor(
216 - this.documentView.getRenderedLineRangeFromOffset(
217 - this.documentView.getModel().getRelativeContentOffset( this.cursor.offset, -1 )
218 - ).start
219 - );
 212+ } else if ( instruction === 'home' || instruction === 'end' ) {
 213+ var offset;
 214+ if ( this.cursor.initialBias ) {
 215+ offset = this.documentView.getModel().getRelativeContentOffset(
 216+ this.cursor.offset, -1 );
220217 } else {
221 - this.showCursor( this.documentView.getRenderedLineRangeFromOffset( this.cursor.offset ).start );
 218+ offset = this.cursor.offset;
222219 }
223 - } else if ( instruction === 'end' ) {
224 - if ( !wasLeftBias ) {
 220+ if ( instruction === 'home' ) {
225221 this.showCursor(
226 - this.documentView.getRenderedLineRangeFromOffset( this.cursor.offset ).end,
227 - true
228 - );
229 - } else {
230 - this.showCursor(
231 - this.documentView.getRenderedLineRangeFromOffset(
232 - this.documentView.getModel().getRelativeContentOffset( this.cursor.offset, -1 )
233 - ).end,
234 - true
235 - );
 222+ this.documentView.getRenderedLineRangeFromOffset( offset ).start, false );
 223+ } else { // end
 224+ this.showCursor( this.documentView.getRenderedLineRangeFromOffset( offset ).end, true );
236225 }
237226 }
238227 };
@@ -242,15 +231,9 @@
243232 * @method
244233 * @param offset {Integer} Position to show the cursor at
245234 */
246 -var wasLeftBias = false;
247235 es.SurfaceView.prototype.showCursor = function( offset, leftBias ) {
248236 if ( typeof offset !== 'undefined' ) {
249 - if ( leftBias ) {
250 - wasLeftBias = true;
251 - } else {
252 - wasLeftBias = false;
253 - }
254 - console.log('showCursor: ' + offset + ' leftBias: ' + leftBias);
 237+ this.cursor.initialBias = leftBias ? true : false;
255238 this.cursor.offset = offset;
256239 var position = this.documentView.getRenderedPositionFromOffset(
257240 this.cursor.offset, leftBias

Status & tagging log