@@ -1106,8 +1106,8 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
1106
1106
this . event . on ( "selectCopy" , this . _handleSelectCopy . bind ( this ) ) ;
1107
1107
this . event . on ( "pasteElements" , this . _handlePasteElements . bind ( this ) ) ;
1108
1108
this . event . on ( "cancel" , this . _handleCancel . bind ( this ) ) ;
1109
- this . event . on ( "selectMoveable" , this . _handleSelectMoveable . bind ( this ) ) ;
1110
- this . event . on ( "selectHand" , this . _handleSelectHand . bind ( this ) ) ;
1109
+ this . event . on ( "selectMoveable" , ( ) => this . setCreator ( MoveableCreator ) ) ;
1110
+ this . event . on ( "selectHand" , ( ) => this . setCreator ( HandCreator ) ) ;
1111
1111
this . event . on ( "groupAdd" , this . _handleGroupAdd . bind ( this ) ) ;
1112
1112
this . event . on ( "groupRemove" , this . _handleGroupCancel . bind ( this ) ) ;
1113
1113
this . event . on ( "undo" , this . execUndo . bind ( this ) ) ;
@@ -1444,9 +1444,9 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
1444
1444
// 尝试激活控制器
1445
1445
const controller = this . _tryActiveController ( ) ;
1446
1446
if ( controller ) {
1447
- this . _refreshElementsOriginals ( [ ...this . store . selectedElements , this . selection . rangeElement ] , {
1448
- deepSubs : true ,
1449
- } ) ;
1447
+ const elements = [ ...this . store . selectedElements , this . selection . rangeElement ] ;
1448
+ this . store . refreshElementsOriginalAngles ( elements , { deepSubs : true } ) ;
1449
+ this . store . refreshElementsOriginals ( elements , { deepSubs : true } ) ;
1450
1450
}
1451
1451
if ( controller instanceof ElementRotation ) {
1452
1452
this . _preProcessRotationStates ( controller ) ;
@@ -1493,14 +1493,16 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
1493
1493
}
1494
1494
1495
1495
/**
1496
- * 刷新组件原始数据
1497
- *
1498
- * @param elements
1499
- * @param options
1496
+ * 添加一个工具切换的命令
1500
1497
*/
1501
- private _refreshElementsOriginals ( elements : IElement [ ] , options ?: RefreshSubOptions ) : void {
1502
- this . store . refreshElementsOriginalAngles ( elements , options ) ;
1503
- this . store . refreshElementsOriginals ( elements , options ) ;
1498
+ private async _addCreatorChangedCommand ( ) : Promise < void > {
1499
+ // 组件创建生效,生成一个切换绘图工具切换的命令
1500
+ const creatorCommand = await CommandHelper . createCommandByActionParams ( [ ] , ElementsCommandTypes . ElementsCreatorChanged , this . store ) ;
1501
+ Object . assign ( creatorCommand . payload , {
1502
+ prevCreatorType : this . prevCreatorType ,
1503
+ creatorType : this . currentCreator . type ,
1504
+ } ) ;
1505
+ this . undoRedo . add ( creatorCommand ) ;
1504
1506
}
1505
1507
1506
1508
/**
@@ -1522,13 +1524,6 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
1522
1524
}
1523
1525
element = this . store . creatingArbitraryElement ( this . cursor . worldValue , true ) ;
1524
1526
if ( ( element as IElementArbitrary ) . tailCoordIndex === 0 ) {
1525
- // 组件创建生效,生成一个切换绘图工具切换的命令
1526
- const creatorCommand = await CommandHelper . createCommandByActionParams ( [ ] , ElementsCommandTypes . ElementsCreatorChanged , this . store ) ;
1527
- Object . assign ( creatorCommand . payload , {
1528
- prevCreatorType : this . prevCreatorType ,
1529
- creatorType : CreatorTypes . arbitrary ,
1530
- } ) ;
1531
- this . undoRedo . add ( creatorCommand ) ;
1532
1527
uDataList . push ( { type : ElementActionTypes . StartCreating , model : { id : element . id } } ) ;
1533
1528
// 组件创建生效,生成一个组件创建的命令
1534
1529
rDataList . push (
@@ -1926,7 +1921,7 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
1926
1921
* @param elements - 组件列表
1927
1922
*/
1928
1923
private _emitElementsCreated ( elements : IElement [ ] ) : void {
1929
- this . setCreator ( MoveableCreator ) ;
1924
+ this . setCreator ( MoveableCreator , false ) ;
1930
1925
this . emit ( ShieldDispatcherNames . elementCreated , elements ) ;
1931
1926
}
1932
1927
@@ -2027,9 +2022,12 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
2027
2022
*
2028
2023
* @param creator
2029
2024
*/
2030
- async setCreator ( creator : Creator ) : Promise < void > {
2025
+ async setCreator ( creator : Creator , isSupportUndoRedo ?: boolean ) : Promise < void > {
2026
+ if ( creator . type === this . currentCreator ?. type ) return ;
2027
+ isSupportUndoRedo && this . _addCreatorChangedCommand ( ) ;
2031
2028
this . prevCreatorType = this . currentCreator ?. type ;
2032
2029
this . currentCreator = creator ;
2030
+ this . cursor . updateStyle ( ) ;
2033
2031
this . emit ( ShieldDispatcherNames . creatorChanged , creator ) ;
2034
2032
}
2035
2033
@@ -2361,26 +2359,6 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
2361
2359
}
2362
2360
}
2363
2361
2364
- /**
2365
- * 处理组件移动操作
2366
- */
2367
- _handleSelectMoveable ( ) : void {
2368
- if ( this . currentCreator . type === HandCreator . type ) {
2369
- this . setCreator ( MoveableCreator ) ;
2370
- this . cursor . updateStyle ( ) ;
2371
- }
2372
- }
2373
-
2374
- /**
2375
- * 处理组件手型操作
2376
- */
2377
- _handleSelectHand ( ) : void {
2378
- if ( this . currentCreator . type === MoveableCreator . type ) {
2379
- this . setCreator ( HandCreator ) ;
2380
- this . cursor . updateStyle ( ) ;
2381
- }
2382
- }
2383
-
2384
2362
/**
2385
2363
* 处理组件组合操作
2386
2364
*/
@@ -2454,7 +2432,7 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
2454
2432
this . store . deSelectAll ( ) ;
2455
2433
}
2456
2434
if ( tailCommand . payload . type === ElementsCommandTypes . ElementsCreatorChanged ) {
2457
- this . setCreator ( CreatorHelper . getCreatorByType ( isRedo ? tailCommand . payload . creatorType : tailCommand . payload . prevCreatorType || MoveableCreator . type ) ) ;
2435
+ this . setCreator ( CreatorHelper . getCreatorByType ( isRedo ? tailCommand . payload . creatorType : tailCommand . payload . prevCreatorType || MoveableCreator . type ) , false ) ;
2458
2436
}
2459
2437
isRedo ? await this . undoRedo . redo ( ) : await this . undoRedo . undo ( ) ;
2460
2438
if ( isRedo && tailCommand . payload . type === ElementsCommandTypes . ElementsCreating ) {
@@ -2463,7 +2441,7 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
2463
2441
this . store . clearCreatingElements ( ) ;
2464
2442
// 再把组件加回来
2465
2443
await this . undoRedo . redo ( ) ;
2466
- this . setCreator ( MoveableCreator ) ;
2444
+ this . setCreator ( MoveableCreator , false ) ;
2467
2445
tailCommand = this . undoRedo . tailRedoCommand ;
2468
2446
}
2469
2447
}
@@ -2475,7 +2453,7 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
2475
2453
const rDataList = this . undoRedo . tailUndoCommand . payload . rDataList ;
2476
2454
// 数据恢复
2477
2455
await CommandHelper . restoreDataList ( rDataList , true , this . store ) ;
2478
- this . setCreator ( CreatorHelper . getCreatorByType ( rDataList [ 0 ] . model . type ) ) ;
2456
+ this . setCreator ( CreatorHelper . getCreatorByType ( rDataList [ 0 ] . model . type ) , false ) ;
2479
2457
tailCommand = this . undoRedo . tailUndoCommand ;
2480
2458
}
2481
2459
}
0 commit comments