@@ -13,21 +13,26 @@ const key_events = 'up,down,left,right'
1313
1414const command_events = `${ metaKey } +up,${ metaKey } +shift+up,${ metaKey } +down,${ metaKey } +shift+down,${ metaKey } +left,${ metaKey } +shift+left,${ metaKey } +right,${ metaKey } +shift+right`
1515
16+ const state = {
17+ active_color : undefined ,
18+ elements : [ ] ,
19+ }
20+
1621export function HueShift ( { Color, Visbug} ) {
17- this . active_color = Color . getActive ( )
18- this . elements = [ ]
22+ state . active_color = Color . getActive ( )
23+ state . elements = [ ]
1924
2025 Visbug . onSelectedUpdate ( elements => {
21- this . elements = elements
22- Color . setActive ( this . active_color )
26+ state . elements = elements
27+ Color . setActive ( state . active_color )
2328 } )
2429
2530 hotkeys ( key_events , ( e , handler ) => {
2631 if ( e . cancelBubble ) return
2732
2833 e . preventDefault ( )
2934
30- let selectedNodes = this . elements
35+ let selectedNodes = state . elements
3136 , keys = handler . key . split ( '+' )
3237
3338 keys . includes ( 'left' ) || keys . includes ( 'right' )
@@ -39,30 +44,30 @@ export function HueShift({Color, Visbug}) {
3944 e . preventDefault ( )
4045 let keys = handler . key . split ( '+' )
4146 keys . includes ( 'left' ) || keys . includes ( 'right' )
42- ? changeHue ( this . elements , keys , 'a' , Color )
43- : changeHue ( this . elements , keys , 'h' , Color )
47+ ? changeHue ( state . elements , keys , 'a' , Color )
48+ : changeHue ( state . elements , keys , 'h' , Color )
4449 } )
4550
4651 hotkeys ( ']' , ( e , handler ) => {
4752 e . preventDefault ( )
4853
49- if ( this . active_color == 'foreground' )
50- this . active_color = 'background'
51- else if ( this . active_color == 'background' )
52- this . active_color = 'border'
54+ if ( state . active_color == 'foreground' )
55+ state . active_color = 'background'
56+ else if ( state . active_color == 'background' )
57+ state . active_color = 'border'
5358
54- Color . setActive ( this . active_color )
59+ Color . setActive ( state . active_color )
5560 } )
5661
5762 hotkeys ( '[' , ( e , handler ) => {
5863 e . preventDefault ( )
5964
60- if ( this . active_color == 'background' )
61- this . active_color = 'foreground'
62- else if ( this . active_color == 'border' )
63- this . active_color = 'background'
65+ if ( state . active_color == 'background' )
66+ state . active_color = 'foreground'
67+ else if ( state . active_color == 'border' )
68+ state . active_color = 'background'
6469
65- Color . setActive ( this . active_color )
70+ Color . setActive ( state . active_color )
6671 } )
6772
6873 return ( ) => {
0 commit comments