@@ -12,25 +12,24 @@ import {Tool} from "core/tools/Tool";
12
12
export const PanTool : Tool = ( ( ) => {
13
13
let isDragging = false ;
14
14
return {
15
- shouldActivate ( event : Event , { input} : CircuitInfo ) : boolean {
15
+ shouldActivate ( event : Event , { input } : CircuitInfo ) : boolean {
16
16
// Activate if the user just pressed the "option key"
17
17
// or if the user began dragging with either 2 fingers
18
18
// or the middle mouse button
19
19
// or if the user pressed one of of the arrow keys while no components are selected
20
- return ( ( event . type === "keydown" && ( ( event . key === "Alt" ) ||
21
- ( event . key === "ArrowLeft" || event . key === "ArrowRight" ||
20
+ return ( ( event . type === "keydown" && ( ( event . key === "Alt" ) ||
21
+ ( event . key === "ArrowLeft" || event . key === "ArrowRight" ||
22
22
event . key === "ArrowUp" || event . key === "ArrowDown" ) ) ) ||
23
23
( event . type === "mousedrag" && ( event . button === MIDDLE_MOUSE_BUTTON ||
24
24
input . getTouchCount ( ) === 2 ) ) ) ;
25
25
} ,
26
- shouldDeactivate ( event : Event , { } : CircuitInfo ) : boolean {
27
- // Deactivate if stopped dragging by releasing mouse
28
- // or if no dragging happened and "Alt" was released
26
+ shouldDeactivate ( event : Event , { input } : CircuitInfo ) : boolean {
27
+ // Deactivate user stopped dragging
28
+ // and the alt key isn't currently pressed
29
29
// or if one of the arrow keys were released
30
- return ( event . type === "mouseup" ) ||
31
- ( event . type === "keyup" && ( ( ! isDragging && event . key === "Alt" ||
32
- ( event . key === "ArrowLeft" || event . key === "ArrowRight" ||
33
- event . key === "ArrowUp" || event . key === "ArrowDown" ) ) ) )
30
+ return ( ! isDragging && ! input . isAltKeyDown ( ) ) ||
31
+ ( event . type === "keyup" && ( event . key === "ArrowLeft" || event . key === "ArrowRight" ||
32
+ event . key === "ArrowUp" || event . key === "ArrowDown" ) ) ;
34
33
} ,
35
34
36
35
@@ -43,20 +42,25 @@ export const PanTool: Tool = (() => {
43
42
} ,
44
43
45
44
46
- onEvent ( event : Event , { input, camera} : CircuitInfo ) : boolean {
45
+ onEvent ( event : Event , { input, camera } : CircuitInfo ) : boolean {
47
46
if ( event . type === "mousedrag" ) {
48
47
isDragging = true ;
49
-
48
+
50
49
const dPos = input . getDeltaMousePos ( ) ;
51
50
camera . translate ( dPos . scale ( - 1 * camera . getZoom ( ) ) ) ;
52
-
51
+
52
+ return true ;
53
+ }
54
+
55
+ if ( event . type === "mouseup" ) {
56
+ isDragging = false ;
53
57
return true ;
54
58
}
55
-
59
+
56
60
if ( event . type === "keydown" ) {
57
61
let dPos = new Vector ( ) ;
58
-
59
- // No else if because it introduces bugs when
62
+
63
+ // No else if because it introduces bugs when
60
64
// multiple arrow keys are pressed
61
65
if ( input . isKeyDown ( "ArrowLeft" ) )
62
66
dPos = dPos . add ( - 1 , 0 ) ;
@@ -66,18 +70,18 @@ export const PanTool: Tool = (() => {
66
70
dPos = dPos . add ( 0 , - 1 ) ;
67
71
if ( input . isKeyDown ( "ArrowDown" ) )
68
72
dPos = dPos . add ( 0 , 1 ) ;
69
-
73
+
70
74
// Screen gets moved different amounts depending on if the shift key is held
71
- const factor = ( input . isShiftKeyDown ( ) ? ARROW_PAN_DISTANCE_SMALL : ARROW_PAN_DISTANCE_NORMAL ) ;
72
-
75
+ const factor = ( input . isShiftKeyDown ( ) ? ARROW_PAN_DISTANCE_SMALL : ARROW_PAN_DISTANCE_NORMAL ) ;
76
+
73
77
camera . translate ( dPos . scale ( factor * camera . getZoom ( ) ) ) ;
74
-
78
+
75
79
return true ;
76
80
}
77
-
78
- // Since it wasn't one of the two event types we want we
81
+
82
+ // Since it wasn't one of the two event types we want we
79
83
// don't need a re-render
80
84
return false ;
81
- }
85
+ } ,
82
86
}
83
87
} ) ( ) ;
0 commit comments