@@ -36,7 +36,7 @@ export default class RectangleSelection extends Module {
3636 /**
3737 * Speed of Scrolling
3838 */
39- private readonly SCROLL_SPEED : number = 3 ;
39+ private readonly SCROLL_SPEED : number = 1 ;
4040
4141 /**
4242 * Height of scroll zone on boundary of screen
@@ -87,45 +87,22 @@ export default class RectangleSelection extends Module {
8787 */
8888 private overlayRectangle : HTMLDivElement ;
8989
90- /**
91- * Coords of redactor
92- */
93- private left ;
94- private top ;
95-
9690 /**
9791 * Module Preparation
9892 * Creating rect and hang handlers
9993 */
10094 public prepare ( ) : void {
10195 const { Listeners} = this . Editor ;
102- const { overlayTopScrollZone, overlayBottomScrollZone, container, overlay} = this . genHTML ( ) ;
103-
104- Listeners . on ( overlayBottomScrollZone , 'mouseenter' , ( event ) => {
105- this . inScrollZone = this . BOTTOM_SCROLL_ZONE ;
106- this . scrollVertical ( this . SCROLL_SPEED ) ;
107- } ) ;
108-
109- Listeners . on ( overlayTopScrollZone , 'mouseenter' , ( event ) => {
110- this . inScrollZone = this . TOP_SCROLL_ZONE ;
111- this . scrollVertical ( - this . SCROLL_SPEED ) ;
112- } ) ;
113-
114- Listeners . on ( overlayBottomScrollZone , 'mouseleave' , ( event ) => {
115- this . inScrollZone = null ;
116- } ) ;
117-
118- Listeners . on ( overlayTopScrollZone , 'mouseleave' , ( event ) => {
119- this . inScrollZone = null ;
120- } ) ;
96+ const { container, overlay} = this . genHTML ( ) ;
12197
12298 Listeners . on ( container , 'mousedown' , ( event : MouseEvent ) => {
12399 if ( event . button !== this . MAIN_MOUSE_BUTTON ) { return ; }
124100 this . startSelection ( event . pageX , event . pageY ) ;
125101 } , false ) ;
126102
127- Listeners . on ( document . body , 'mousemove' , ( event ) => {
103+ Listeners . on ( document . body , 'mousemove' , ( event : MouseEvent ) => {
128104 this . changingRectangle ( event ) ;
105+ this . scrollByZones ( event . clientY ) ;
129106 } , false ) ;
130107
131108 Listeners . on ( document . body , 'mouseleave' , ( event ) => {
@@ -135,6 +112,7 @@ export default class RectangleSelection extends Module {
135112
136113 Listeners . on ( window , 'scroll' , ( event ) => {
137114 this . changingRectangle ( event ) ;
115+ this . scrollByZones ( null ) ;
138116 } , false ) ;
139117
140118 Listeners . on ( document . body , 'mouseup' , ( event ) => {
@@ -188,24 +166,40 @@ export default class RectangleSelection extends Module {
188166 this . isRectSelectionActivated = false ;
189167 }
190168
169+ /**
170+ * Scroll If mouse in scroll zone
171+ * @param {number } clientY - Y coord of mouse
172+ */
173+ private scrollByZones ( clientY ) {
174+ // Может быть 0
175+ if ( clientY !== null ) {
176+ this . inScrollZone = null ;
177+ if ( clientY <= this . HEIGHT_OF_SCROLL_ZONE ) {
178+ this . inScrollZone = this . TOP_SCROLL_ZONE ;
179+ }
180+ if ( document . documentElement . clientHeight - clientY <= this . HEIGHT_OF_SCROLL_ZONE ) {
181+ this . inScrollZone = this . BOTTOM_SCROLL_ZONE ;
182+ }
183+ }
184+ if ( ! this . inScrollZone ) {
185+ return ;
186+ }
187+
188+ this . scrollVertical ( this . inScrollZone === this . TOP_SCROLL_ZONE ? - this . SCROLL_SPEED : this . SCROLL_SPEED ) ;
189+ }
190+
191191 private genHTML ( ) {
192192 const container = document . querySelector ( '.' + UI . CSS . editorWrapper ) ;
193193 const overlay = $ . make ( 'div' , RectangleSelection . CSS . overlay , { } ) ;
194194 const overlayContainer = $ . make ( 'div' , RectangleSelection . CSS . overlayContainer , { } ) ;
195195 const overlayRectangle = $ . make ( 'div' , RectangleSelection . CSS . rect , { } ) ;
196- const overlayTopScrollZone = $ . make ( 'div' , RectangleSelection . CSS . topScrollZone , { } ) ;
197- const overlayBottomScrollZone = $ . make ( 'div' , RectangleSelection . CSS . bottomScrollZone , { } ) ;
198196
199197 overlayContainer . appendChild ( overlayRectangle ) ;
200198 overlay . appendChild ( overlayContainer ) ;
201- document . body . appendChild ( overlayTopScrollZone ) ;
202- document . body . appendChild ( overlayBottomScrollZone ) ;
203199 container . appendChild ( overlay ) ;
204200
205201 this . overlayRectangle = overlayRectangle as HTMLDivElement ;
206202 return {
207- overlayBottomScrollZone,
208- overlayTopScrollZone,
209203 container,
210204 overlay,
211205 } ;
0 commit comments