@@ -25,6 +25,7 @@ import {activateColorPicker} from '../reducers/color-picker';
25
25
import { closeExtensionLibrary , openSoundRecorder , openConnectionModal } from '../reducers/modals' ;
26
26
import { activateCustomProcedures , deactivateCustomProcedures } from '../reducers/custom-procedures' ;
27
27
import { setConnectionModalExtensionId } from '../reducers/connection-modal' ;
28
+ import { updateMetrics } from '../reducers/workspace-metrics' ;
28
29
29
30
import {
30
31
activateTab ,
@@ -79,7 +80,6 @@ class Blocks extends React.Component {
79
80
this . ScratchBlocks . recordSoundCallback = this . handleOpenSoundRecorder ;
80
81
81
82
this . state = {
82
- workspaceMetrics : { } ,
83
83
prompt : null
84
84
} ;
85
85
this . onTargetsUpdate = debounce ( this . onTargetsUpdate , 100 ) ;
@@ -301,14 +301,12 @@ class Blocks extends React.Component {
301
301
onWorkspaceMetricsChange ( ) {
302
302
const target = this . props . vm . editingTarget ;
303
303
if ( target && target . id ) {
304
- const workspaceMetrics = Object . assign ( { } , this . state . workspaceMetrics , {
305
- [ target . id ] : {
306
- scrollX : this . workspace . scrollX ,
307
- scrollY : this . workspace . scrollY ,
308
- scale : this . workspace . scale
309
- }
304
+ this . props . updateMetrics ( {
305
+ targetID : target . id ,
306
+ scrollX : this . workspace . scrollX ,
307
+ scrollY : this . workspace . scrollY ,
308
+ scale : this . workspace . scale
310
309
} ) ;
311
- this . setState ( { workspaceMetrics} ) ;
312
310
}
313
311
}
314
312
onScriptGlowOn ( data ) {
@@ -355,7 +353,7 @@ class Blocks extends React.Component {
355
353
this . props . updateToolboxState ( toolboxXML ) ;
356
354
}
357
355
358
- if ( this . props . vm . editingTarget && ! this . state . workspaceMetrics [ this . props . vm . editingTarget . id ] ) {
356
+ if ( this . props . vm . editingTarget && ! this . props . workspaceMetrics [ this . props . vm . editingTarget . id ] ) {
359
357
this . onWorkspaceMetricsChange ( ) ;
360
358
}
361
359
@@ -381,8 +379,8 @@ class Blocks extends React.Component {
381
379
}
382
380
this . workspace . addChangeListener ( this . props . vm . blockListener ) ;
383
381
384
- if ( this . props . vm . editingTarget && this . state . workspaceMetrics [ this . props . vm . editingTarget . id ] ) {
385
- const { scrollX, scrollY, scale} = this . state . workspaceMetrics [ this . props . vm . editingTarget . id ] ;
382
+ if ( this . props . vm . editingTarget && this . props . workspaceMetrics [ this . props . vm . editingTarget . id ] ) {
383
+ const { scrollX, scrollY, scale} = this . props . workspaceMetrics [ this . props . vm . editingTarget . id ] ;
386
384
this . workspace . scrollX = scrollX ;
387
385
this . workspace . scrollY = scrollY ;
388
386
this . workspace . scale = scale ;
@@ -506,7 +504,7 @@ class Blocks extends React.Component {
506
504
} ) ;
507
505
}
508
506
render ( ) {
509
- /* eslint-disable no-unused-vars */
507
+ /* eslint-disable no-unused-vars, no-shadow */
510
508
const {
511
509
anyModalVisible,
512
510
canUseCloud,
@@ -525,9 +523,11 @@ class Blocks extends React.Component {
525
523
onRequestCloseExtensionLibrary,
526
524
onRequestCloseCustomProcedures,
527
525
toolboxXML,
526
+ workspaceMetrics,
527
+ updateMetrics,
528
528
...props
529
529
} = this . props ;
530
- /* eslint-enable no-unused-vars */
530
+ /* eslint-enable no-unused-vars, no-shadow */
531
531
return (
532
532
< React . Fragment >
533
533
< DroppableBlocks
@@ -654,7 +654,8 @@ const mapStateToProps = state => ({
654
654
locale : state . locales . locale ,
655
655
messages : state . locales . messages ,
656
656
toolboxXML : state . scratchGui . toolbox . toolboxXML ,
657
- customProceduresVisible : state . scratchGui . customProcedures . active
657
+ customProceduresVisible : state . scratchGui . customProcedures . active ,
658
+ workspaceMetrics : state . scratchGui . workspaceMetrics
658
659
} ) ;
659
660
660
661
const mapDispatchToProps = dispatch => ( {
@@ -676,6 +677,9 @@ const mapDispatchToProps = dispatch => ({
676
677
} ,
677
678
updateToolboxState : toolboxXML => {
678
679
dispatch ( updateToolbox ( toolboxXML ) ) ;
680
+ } ,
681
+ updateMetrics : metrics => {
682
+ dispatch ( updateMetrics ( metrics ) ) ;
679
683
}
680
684
} ) ;
681
685
0 commit comments