@@ -107,6 +107,12 @@ export class Highlighter extends OBC.Component implements OBC.Disposable {
107
107
/** Styles with auto toggle will be unselected when selected twice. */
108
108
autoToggle = new Set < string > ( ) ;
109
109
110
+ /** Position of the mouse on mouseDown. */
111
+ private mouseDownPosition = { x : 0 , y : 0 } ;
112
+
113
+ /** Threshhold on how much the mouse have to move until its considered movement */
114
+ mouseMoveThreshold = 5
115
+
110
116
/** If defined, only the specified elements will be selected by the specified style. */
111
117
selectable : { [ name : string ] : FragmentIdMap } = { } ;
112
118
@@ -629,9 +635,11 @@ export class Highlighter extends OBC.Component implements OBC.Disposable {
629
635
this . selection [ this . config . hoverName ] = { } ;
630
636
} ;
631
637
632
- private onMouseDown = ( ) => {
638
+ private onMouseDown = ( e : MouseEvent ) => {
633
639
if ( ! this . enabled ) return ;
640
+ this . mouseDownPosition = { x : e . clientX , y : e . clientY }
634
641
this . _mouseState . down = true ;
642
+
635
643
} ;
636
644
637
645
private onMouseUp = async ( event : MouseEvent ) => {
@@ -656,29 +664,38 @@ export class Highlighter extends OBC.Component implements OBC.Disposable {
656
664
}
657
665
} ;
658
666
659
- private onMouseMove = async ( ) => {
667
+ private onMouseMove = async ( e : MouseEvent ) => {
660
668
if ( ! this . enabled ) return ;
669
+
670
+ // Calculate the distance the mouse has moved since mouse down
671
+ const dx = e . clientX - this . mouseDownPosition . x ;
672
+ const dy = e . clientY - this . mouseDownPosition . y ;
673
+ const moveDistance = Math . sqrt ( dx * dx + dy * dy ) ;
674
+
661
675
const { hoverName, hoverEnabled } = this . config ;
662
676
if ( this . _mouseState . moved ) {
663
677
this . clear ( hoverName ) ;
664
678
return ;
665
679
}
666
-
667
- this . _mouseState . moved = this . _mouseState . down ;
668
- const excluded : FRAGS . FragmentIdMap = { } ;
669
- for ( const name in this . selection ) {
670
- if ( name === hoverName ) continue ;
671
- const fragmentIdMap = this . selection [ name ] ;
672
- for ( const fragmentID in fragmentIdMap ) {
673
- if ( ! ( fragmentID in excluded ) ) excluded [ fragmentID ] = new Set ( ) ;
674
- const expressIDs = fragmentIdMap [ fragmentID ] ;
675
- for ( const expressID of expressIDs ) {
676
- excluded [ fragmentID ] . add ( expressID ) ;
680
+
681
+ // If the distance is greater than the threshold, set dragging to true
682
+ if ( moveDistance > this . mouseMoveThreshold ) {
683
+ this . _mouseState . moved = this . _mouseState . down ;
684
+ const excluded : FRAGS . FragmentIdMap = { } ;
685
+ for ( const name in this . selection ) {
686
+ if ( name === hoverName ) continue ;
687
+ const fragmentIdMap = this . selection [ name ] ;
688
+ for ( const fragmentID in fragmentIdMap ) {
689
+ if ( ! ( fragmentID in excluded ) ) excluded [ fragmentID ] = new Set ( ) ;
690
+ const expressIDs = fragmentIdMap [ fragmentID ] ;
691
+ for ( const expressID of expressIDs ) {
692
+ excluded [ fragmentID ] . add ( expressID ) ;
693
+ }
677
694
}
678
695
}
679
- }
680
- if ( hoverEnabled ) {
681
- await this . highlight ( this . config . hoverName , true , false , excluded ) ;
696
+ if ( hoverEnabled ) {
697
+ await this . highlight ( this . config . hoverName , true , false , excluded ) ;
698
+ }
682
699
}
683
700
} ;
684
701
}
0 commit comments