@@ -59,16 +59,18 @@ export class DoubleClickFSM extends FSMImpl {
5959
6060 private checkButton : number | undefined ;
6161
62- public constructor ( logger : Logger , subAction ?: ( evt : MouseEvent ) => void ) {
62+ public constructor ( logger : Logger , subAction ?: ( evt : MouseEvent ) => void , toleranceMove ?: number ) {
6363 super ( logger ) ;
64- this . firstClickFSM = new ClickFSM ( logger , subAction ) ;
65- this . sndClickFSM = new ClickFSM ( logger ) ;
64+ this . firstClickFSM = new ClickFSM ( logger , subAction , toleranceMove ) ;
65+ this . sndClickFSM = new ClickFSM ( logger , undefined , toleranceMove ) ;
6666
6767 const errorHandler = {
6868 "fsmError" : ( err : unknown ) : void => {
6969 this . notifyHandlerOnError ( err ) ;
7070 }
7171 } ;
72+ let firstX = 0 ;
73+ let firstY = 0 ;
7274
7375 this . firstClickFSM . addHandler ( errorHandler ) ;
7476 this . sndClickFSM . addHandler ( errorHandler ) ;
@@ -77,12 +79,18 @@ export class DoubleClickFSM extends FSMImpl {
7779 const clicked = this . addStdState ( "clicked" ) ;
7880
7981 new SubFSMTransitionImpl ( this . initState , clicked , this . firstClickFSM ,
80- ( ) : void => {
82+ ( evt : Event ) : void => {
8183 this . setCheckButton ( this . firstClickFSM . getCheckButton ( ) ) ;
84+ if ( evt instanceof MouseEvent ) {
85+ firstX = evt . clientX ;
86+ firstY = evt . clientY ;
87+ }
8288 } ) ;
8389
84- new MouseTransition ( clicked , cancelled , "mousemove" , undefined ,
85- ( ev : Event ) : boolean => ( this . checkButton === undefined || ev instanceof MouseEvent && ev . button === this . checkButton ) ) ;
90+ if ( toleranceMove !== undefined ) {
91+ new MouseTransition ( clicked , cancelled , "mousemove" , undefined ,
92+ ( evt : MouseEvent ) : boolean => Math . abs ( firstX - evt . clientX ) > toleranceMove || Math . abs ( firstY - evt . clientY ) > toleranceMove ) ;
93+ }
8694
8795 new TimeoutTransition ( clicked , cancelled , DoubleClickFSM . timeGapSupplier ) ;
8896 new SubFSMTransitionImpl ( clicked , this . addTerminalState ( "dbleclicked" , true ) , this . sndClickFSM ) ;
@@ -125,10 +133,18 @@ export class DoubleClickFSM extends FSMImpl {
125133 * @category Interaction Library
126134 */
127135export class DoubleClick extends InteractionBase < PointData , PointDataImpl > {
128- public constructor ( logger : Logger , fsm ?: DoubleClickFSM , data ?: PointDataImpl , name ?: string ) {
136+ /**
137+ * Creates the interaction
138+ * @param logger - The logger to use for this interaction
139+ * @param fsm - The optional FSM provided for the interaction
140+ * @param data - The interaction data to use
141+ * @param name - The name of the user interaction
142+ * @param toleranceMove - The accepted number of pixel moves between the pressure and the release of each click
143+ */
144+ public constructor ( logger : Logger , fsm ?: DoubleClickFSM , data ?: PointDataImpl , name ?: string , toleranceMove ?: number ) {
129145 const theFSM = fsm ?? new DoubleClickFSM ( logger , ( evt : MouseEvent ) : void => {
130146 this . _data . copy ( evt ) ;
131- } ) ;
147+ } , toleranceMove ) ;
132148 super ( theFSM , data ?? new PointDataImpl ( ) , logger , name ?? DoubleClick . name ) ;
133149 /*
134150 * We give the interaction to the first click as this click interaction
0 commit comments