@@ -58,6 +58,9 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
58
58
private _scrollSpeed : Coordinates = { x : 0 , y : 0 } ;
59
59
private _scrollDelta : Coordinates = { x : 0 , y : 0 } ;
60
60
61
+ // Required for keydown scrolling
62
+ private _lastMousePosition = { x : 0 , y : 0 } ;
63
+
61
64
constructor ( opt : PartialSelectionOptions ) {
62
65
super ( ) ;
63
66
@@ -330,7 +333,11 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
330
333
if ( this . _scrollAvailable ) {
331
334
332
335
// Detect mouse scrolling
333
- on ( this . _targetElement , 'wheel' , this . _manualScroll , { passive : false } ) ;
336
+ on ( this . _targetElement , 'wheel' , this . _wheelScroll , { passive : false } ) ;
337
+
338
+ // Detect keyboard scrolling
339
+ on ( this . _options . document , 'keydown' , this . _keyboardScroll , { passive : false } ) ;
340
+
334
341
335
342
/**
336
343
* The selection-area will also cover another element
@@ -403,6 +410,9 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
403
410
_areaLocation . x2 = x ;
404
411
_areaLocation . y2 = y ;
405
412
413
+ this . _lastMousePosition . x = x ;
414
+ this . _lastMousePosition . y = y ;
415
+
406
416
if ( this . _scrollAvailable && ! this . _scrollingActive && ( _scrollSpeed . y || _scrollSpeed . x ) ) {
407
417
408
418
// Continuous scrolling
@@ -484,7 +494,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
484
494
off ( this . _targetElement , 'scroll' , this . _onStartAreaScroll ) ;
485
495
}
486
496
487
- _manualScroll ( evt : ScrollEvent ) : void {
497
+ _wheelScroll ( evt : ScrollEvent ) : void {
488
498
const { manualSpeed} = this . _options . behaviour . scrolling ;
489
499
490
500
// Consistent scrolling speed on all browsers
@@ -498,6 +508,24 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
498
508
evt . preventDefault ( ) ;
499
509
}
500
510
511
+ _keyboardScroll ( evt : KeyboardEvent ) : void {
512
+ const { manualSpeed} = this . _options . behaviour . scrolling ;
513
+
514
+ const deltaX = evt . key === 'ArrowLeft' ? - 1 : evt . key === 'ArrowRight' ? 1 : 0 ;
515
+ const deltaY = evt . key === 'ArrowUp' ? - 1 : evt . key === 'ArrowDown' ? 1 : 0 ;
516
+
517
+ this . _scrollSpeed . x += Math . sign ( deltaX ) * manualSpeed ;
518
+ this . _scrollSpeed . y += Math . sign ( deltaY ) * manualSpeed ;
519
+
520
+ evt . preventDefault ( ) ;
521
+
522
+ this . _onTapMove ( {
523
+ clientX : this . _lastMousePosition . x ,
524
+ clientY : this . _lastMousePosition . y ,
525
+ preventDefault : ( ) => void 0 ,
526
+ } as ScrollEvent ) ;
527
+ }
528
+
501
529
_recalculateSelectionAreaRect ( ) : void {
502
530
const { _scrollSpeed, _areaLocation, _targetElement, _options} = this ;
503
531
const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth} = _targetElement as Element ;
@@ -572,7 +600,10 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
572
600
this . _scrollSpeed . y = 0 ;
573
601
574
602
// Unbind mouse scrolling listener
575
- off ( this . _targetElement , 'wheel' , this . _manualScroll , { passive : true } ) ;
603
+ off ( this . _targetElement , 'wheel' , this . _wheelScroll , { passive : true } ) ;
604
+
605
+ // Unbind keyboard scrolling listener
606
+ off ( this . _options . document , 'keydown' , this . _keyboardScroll , { passive : true , } ) ;
576
607
577
608
// Remove selection-area from dom
578
609
this . _clippingElement . remove ( ) ;
0 commit comments