r101663 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101662‎ | r101663 | r101664 >
Date:19:23, 2 November 2011
Author:inez
Status:deferred
Tags:
Comment:
Improved handling for home and end key
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
@@ -14,14 +14,23 @@
1515 // Initialize document view
1616 this.documentView = new es.DocumentView( this.model.getDocument(), this );
1717 this.$.append( this.documentView.$ );
18 -
 18+
 19+ // Interaction state
 20+ this.mouse = {
 21+ selecting: false,
 22+ clicks: 0,
 23+ clickDelay: 500,
 24+ clickTimeout: null,
 25+ clickPosition: null,
 26+ hotSpotRadius: 1,
 27+ lastMovePosition: null
 28+ };
1929 this.cursor = {
2030 $: $( '<div class="es-surfaceView-cursor"></div>' ).appendTo( this.$ ),
2131 interval: null,
2232 offset: null,
2333 initialLeft: null
2434 };
25 -
2635 this.keyboard = {
2736 selecting: false,
2837 cursorAnchor: null,
@@ -32,10 +41,14 @@
3342 command: false,
3443 alt: false
3544 }
36 - };
37 -
 45+ };
 46+ this.selection = {
 47+ from: 0,
 48+ to: 0
 49+ };
 50+
3851 // References for use in closures
39 - var surfaceView = this,
 52+ var surfaceView = this,
4053 $document = $( document );
4154
4255 // MouseDown on surface
@@ -76,6 +89,27 @@
7790
7891 // First render
7992 this.documentView.renderContent();
 93+
 94+ this.dimensions = {
 95+ width: this.$.width(),
 96+ height: this.$window.height(),
 97+ scrollTop: this.$window.scrollTop()
 98+ };
 99+
 100+ // Re-render when resizing horizontally
 101+ this.$window.resize( function() {
 102+ surfaceView.hideCursor();
 103+ surfaceView.dimensions.height = surfaceView.$window.height();
 104+ var width = surfaceView.$.width();
 105+ if ( surfaceView.dimensions.width !== width ) {
 106+ surfaceView.dimensions.width = width;
 107+ surfaceView.documentView.renderContent();
 108+ }
 109+ } );
 110+
 111+ this.$window.scroll( function() {
 112+ surfaceView.dimensions.scrollTop = surfaceView.$window.scrollTop();
 113+ } );
80114 };
81115
82116 es.SurfaceView.boundaryTest = /([ \-\t\r\n\f])/;
@@ -142,7 +176,26 @@
143177 };
144178
145179 es.SurfaceView.prototype.onKeyUp = function( e ) {
146 - //
 180+ switch ( e.keyCode ) {
 181+ case 16: // Shift
 182+ this.keyboard.keys.shift = false;
 183+ if ( this.keyboard.selecting ) {
 184+ this.keyboard.selecting = false;
 185+ }
 186+ break;
 187+ case 17: // Control
 188+ this.keyboard.keys.control = false;
 189+ break;
 190+ case 18: // Alt
 191+ this.keyboard.keys.alt = false;
 192+ break;
 193+ case 91: // Command
 194+ this.keyboard.keys.command = false;
 195+ break;
 196+ default:
 197+ break;
 198+ }
 199+ return true;
147200 };
148201
149202 es.SurfaceView.prototype.moveCursor = function( instruction ) {
@@ -157,16 +210,29 @@
158211 } else if ( instruction === 'up' || instruction === 'down' ) {
159212 // ...
160213 } else if ( instruction === 'home' ) {
161 - this.showCursor( this.documentView.getRenderedLineRange( this.cursor.offset ).start );
 214+ if ( wasLeftBias ) {
 215+ this.showCursor(
 216+ this.documentView.getRenderedLineRangeFromOffset(
 217+ this.documentView.getModel().getRelativeContentOffset( this.cursor.offset, -1 )
 218+ ).start
 219+ );
 220+ } else {
 221+ this.showCursor( this.documentView.getRenderedLineRangeFromOffset( this.cursor.offset ).start );
 222+ }
162223 } else if ( instruction === 'end' ) {
163 - var end = this.documentView.getRenderedLineRange( this.cursor.offset ).end;
164 - var data = this.documentView.getModel().data;
165 - if ( es.DocumentModel.isContentData( data, end ) ) {
166 - while ( es.SurfaceView.boundaryTest.exec( data[ end - 1 ] ) ) {
167 - end--;
168 - }
 224+ if ( !wasLeftBias ) {
 225+ 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+ );
169236 }
170 - this.showCursor( end );
171237 }
172238 };
173239
@@ -176,8 +242,15 @@
177243 * @method
178244 * @param offset {Integer} Position to show the cursor at
179245 */
180 -es.SurfaceView.prototype.showCursor = function( offset, leftBias ) {
 246+var wasLeftBias = false;
 247+es.SurfaceView.prototype.showCursor = function( offset, leftBias ) {
181248 if ( typeof offset !== 'undefined' ) {
 249+ if ( leftBias ) {
 250+ wasLeftBias = true;
 251+ } else {
 252+ wasLeftBias = false;
 253+ }
 254+ console.log('showCursor: ' + offset + ' leftBias: ' + leftBias);
182255 this.cursor.offset = offset;
183256 var position = this.documentView.getRenderedPositionFromOffset(
184257 this.cursor.offset, leftBias

Status & tagging log