Index: trunk/parsers/wikidom/lib/synth/views/es.SurfaceView.js |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | */ |
8 | 8 | es.SurfaceView = function( $container, model ) { |
9 | 9 | this.$ = $container.addClass( 'editSurface' ); |
| 10 | + this.$window = $( window ); |
10 | 11 | this.model = model; |
11 | 12 | |
12 | 13 | // Initialize document view |
— | — | @@ -96,11 +97,11 @@ |
97 | 98 | this.dimensions = { |
98 | 99 | width: this.$.width(), |
99 | 100 | height: this.$.height(), |
100 | | - scrollTop: $(window).scrollTop() |
| 101 | + scrollTop: this.$window.scrollTop() |
101 | 102 | }; |
102 | 103 | |
103 | 104 | // Re-render when resizing horizontally |
104 | | - $( window ).resize( function() { |
| 105 | + this.$window.resize( function() { |
105 | 106 | surfaceView.hideCursor(); |
106 | 107 | surfaceView.dimensions.height = surfaceView.$.height(); |
107 | 108 | var width = surfaceView.$.width(); |
— | — | @@ -110,8 +111,8 @@ |
111 | 112 | } |
112 | 113 | } ); |
113 | 114 | |
114 | | - $( window ).scroll( function() { |
115 | | - surfaceView.dimensions.scrollTop = $( window ).scrollTop() |
| 115 | + this.$window.scroll( function() { |
| 116 | + surfaceView.dimensions.scrollTop = surfaceView.$window.scrollTop(); |
116 | 117 | } ); |
117 | 118 | }; |
118 | 119 | |
— | — | @@ -203,8 +204,13 @@ |
204 | 205 | es.SurfaceView.prototype.onMouseMove = function( e ) { |
205 | 206 | if ( e.button === 0 /* left mouse button */ && this.mouse.selecting ) { |
206 | 207 | |
207 | | - if ( e.pageY - $(window).scrollTop() <= window.innerHeight ) { |
| 208 | + |
| 209 | + if ( e.pageY - $(window).scrollTop() < 0 ) { |
| 210 | + lastEventPosition = es.Position.newFromEventPagePosition( e ); |
208 | 211 | stopScrolling(); |
| 212 | + startScrolling(true); |
| 213 | + } else if ( e.pageY - $(window).scrollTop() <= window.innerHeight ) { |
| 214 | + stopScrolling(); |
209 | 215 | } else { |
210 | 216 | lastEventPosition = es.Position.newFromEventPagePosition( e ); |
211 | 217 | stopScrolling(); |
— | — | @@ -347,16 +353,13 @@ |
348 | 354 | } |
349 | 355 | |
350 | 356 | // Auto scroll to cursor |
351 | | - var $window = $(window), |
352 | | - scrollTop = $window.scrollTop(), |
353 | | - windowHeight = $window.height(), |
354 | | - inputTop = this.$input.offset().top, |
| 357 | + var inputTop = this.$input.offset().top, |
355 | 358 | inputBottom = inputTop + this.$input.height(); |
356 | | - if (inputTop < scrollTop) { |
357 | | - $window.scrollTop(inputTop); |
358 | | - } else if (inputBottom > (scrollTop + windowHeight)) { |
359 | | - $window.scrollTop(inputBottom - windowHeight); |
360 | | - } |
| 359 | + if ( inputTop < this.dimensions.scrollTop ) { |
| 360 | + this.$window.scrollTop( inputTop ); |
| 361 | + } else if ( inputBottom > ( this.dimensions.scrollTop + this.dimensions.height ) ) { |
| 362 | + this.$window.scrollTop( inputBottom - this.dimensions.height ); |
| 363 | + } |
361 | 364 | |
362 | 365 | return; |
363 | 366 | }; |
— | — | @@ -374,7 +377,7 @@ |
375 | 378 | |
376 | 379 | |
377 | 380 | |
378 | | -var scrollStep = function() { |
| 381 | +var scrollStepDown = function() { |
379 | 382 | lastEventPosition.top += 20; |
380 | 383 | lastEventPosition.bottom += 20; |
381 | 384 | |
— | — | @@ -385,10 +388,29 @@ |
386 | 389 | |
387 | 390 | $(window).scrollTop( $(window).scrollTop() + 20 ); |
388 | 391 | }; |
| 392 | + |
| 393 | +var scrollStepUp = function() { |
| 394 | + lastEventPosition.top -= 20; |
| 395 | + lastEventPosition.bottom -= 20; |
| 396 | + |
| 397 | + fakelastEventPosition = new es.Position(lastEventPosition.left, lastEventPosition.top, lastEventPosition.bottom); |
| 398 | + |
| 399 | + surfaceView.selection.to = surfaceView.documentView.getOffsetFromPosition( fakelastEventPosition ); |
| 400 | + surfaceView.drawSelection(); |
| 401 | + |
| 402 | + $(window).scrollTop( $(window).scrollTop() - 20 ); |
| 403 | +}; |
| 404 | + |
389 | 405 | var scrollInterval = null; |
390 | | -var startScrolling = function( interval ) { |
391 | | - scrollStep(); |
392 | | - scrollInterval = setInterval(scrollStep, interval || 50); |
| 406 | +var startScrolling = function( up ) { |
| 407 | + if ( up ) { |
| 408 | + console.log('t'); |
| 409 | + scrollStepUp(); |
| 410 | + scrollInterval = setInterval(scrollStepUp, 50); |
| 411 | + } else { |
| 412 | + scrollStepDown(); |
| 413 | + scrollInterval = setInterval(scrollStepDown, 50); |
| 414 | + } |
393 | 415 | }; |
394 | 416 | var stopScrolling = function() { |
395 | 417 | clearInterval( scrollInterval ); |