@@ -12,8 +12,10 @@ import { AtomicNode } from './VNodes/AtomicNode';
12
12
import { SeparatorNode } from './VNodes/SeparatorNode' ;
13
13
import { ModeIdentifier , ModeDefinition , Mode , RuleProperty } from './Mode' ;
14
14
import { Memory , ChangesLocations } from './Memory/Memory' ;
15
- import { makeVersionable } from './Memory/Versionable' ;
15
+ import { makeVersionable , markNotVersionable } from './Memory/Versionable' ;
16
16
import { VersionableArray } from './Memory/VersionableArray' ;
17
+ import { VersionableSet } from './Memory/VersionableSet' ;
18
+ import { MemoryOrigin } from '../../plugin-devtools/src/components/MemoryComponent' ;
17
19
import { Point , VNode } from './VNodes/VNode' ;
18
20
19
21
export enum EditorStage {
@@ -85,6 +87,10 @@ export interface PluginMap extends Map<typeof JWPlugin, JWPlugin> {
85
87
get < T extends typeof JWPlugin > ( constructor : T ) : InstanceType < T > ;
86
88
}
87
89
90
+ interface MemoryInfo extends MemoryOrigin {
91
+ uiCommand : boolean ;
92
+ }
93
+
88
94
export class JWEditor {
89
95
private _stage : EditorStage = EditorStage . CONFIGURATION ;
90
96
dispatcher : Dispatcher ;
@@ -101,7 +107,7 @@ export class JWEditor {
101
107
deadlockTimeout : 10000 ,
102
108
} ;
103
109
memory : Memory ;
104
- memoryInfo : { commandNames : string [ ] ; uiCommand : boolean } ;
110
+ memoryInfo : MemoryInfo ;
105
111
private _memoryID = 0 ;
106
112
selection : VSelection ;
107
113
loaders : Record < string , Loader > = { } ;
@@ -161,7 +167,18 @@ export class JWEditor {
161
167
this . memory = new Memory ( ) ;
162
168
this . memory . attach ( this . selection . range . start ) ;
163
169
this . memory . attach ( this . selection . range . end ) ;
164
- this . memoryInfo = makeVersionable ( { commandNames : [ ] , uiCommand : false } ) ;
170
+ this . memoryInfo = makeVersionable ( {
171
+ // for dev tools and plugin's values merge
172
+ commandNames : [ ] ,
173
+ uiCommand : false ,
174
+ layers : new Set ( [ ] ) ,
175
+ actionID : '' ,
176
+ actionArgs : { } as object ,
177
+ base : '' ,
178
+ current : this . _memoryID . toString ( ) ,
179
+ isMaster : true ,
180
+ error : null ,
181
+ } ) ;
165
182
this . memory . attach ( this . memoryInfo ) ;
166
183
this . memory . create ( this . _memoryID . toString ( ) ) ;
167
184
@@ -500,7 +517,10 @@ export class JWEditor {
500
517
const origin = this . memory . sliceKey ;
501
518
const memorySlice = this . _memoryID . toString ( ) ;
502
519
this . memory . switchTo ( memorySlice ) ;
520
+ this . memoryInfo . isMaster = false ;
521
+ this . memoryInfo . layers = new VersionableSet ( [ memorySlice ] ) ;
503
522
this . memoryInfo . commandNames = new VersionableArray ( ) ;
523
+ this . memoryInfo . actionID = null ;
504
524
this . memoryInfo . uiCommand = false ;
505
525
let commandNames = this . memoryInfo . commandNames ;
506
526
@@ -510,13 +530,16 @@ export class JWEditor {
510
530
if ( typeof commandName === 'function' ) {
511
531
const name = '@custom' + ( commandName . name ? ':' + commandName . name : '' ) ;
512
532
this . memoryInfo . commandNames . push ( name ) ;
533
+ this . memoryInfo . actionID = name ;
513
534
await commandName ( this . contextManager . defaultContext ) ;
514
535
if ( this . memory . sliceKey !== memorySlice ) {
515
536
// Override by the current commandName if the slice changed.
516
537
commandNames = [ name ] ;
517
538
}
518
539
} else {
519
540
this . memoryInfo . commandNames . push ( commandName ) ;
541
+ if ( params ) markNotVersionable ( params ) ;
542
+ this . memoryInfo . actionID = commandName ;
520
543
await this . dispatcher . dispatch ( commandName , params ) ;
521
544
if ( this . memory . sliceKey !== memorySlice ) {
522
545
// Override by the current commandName if the slice changed.
@@ -538,7 +561,14 @@ export class JWEditor {
538
561
exec ( ) . then ( resolve , reject ) ;
539
562
} ) ;
540
563
541
- // Prepare nex slice and freeze the memory.
564
+ // The running memory slice becomes a master slice.
565
+ if ( ! this . memory . isFrozen ( ) ) {
566
+ this . memoryInfo . isMaster = true ;
567
+ this . memoryInfo . base = memorySlice ;
568
+ this . memoryInfo . current = this . _memoryID . toString ( ) ;
569
+ }
570
+
571
+ // Prepare next slice and freeze the memory.
542
572
this . _memoryID ++ ;
543
573
const nextMemorySlice = this . _memoryID . toString ( ) ;
544
574
this . memory . create ( nextMemorySlice ) ;
@@ -567,6 +597,12 @@ export class JWEditor {
567
597
568
598
const failedSlice = this . memory . sliceKey ;
569
599
600
+ // The failed memory slice becomes a master slice.
601
+ this . memory . create ( failedSlice + '-fail' ) . switchTo ( failedSlice + '-fail' ) ;
602
+ this . memoryInfo . isMaster = false ;
603
+ this . memoryInfo . base = memorySlice ;
604
+ this . memoryInfo . error = error . message ;
605
+
570
606
// When an error occurs, we go back to part of the functional memory.
571
607
this . memory . switchTo ( origin ) ;
572
608
@@ -609,12 +645,14 @@ export class JWEditor {
609
645
params ?: CommandParamsType < P , C > ,
610
646
) : Promise < void > {
611
647
if ( typeof commandName === 'function' ) {
612
- this . memoryInfo . commandNames . push (
613
- '@custom' + ( commandName . name ? ':' + commandName . name : '' ) ,
614
- ) ;
648
+ const name = '@custom' + ( commandName . name ? ':' + commandName . name : '' ) ;
649
+ this . memoryInfo . commandNames . push ( name ) ;
650
+ this . memoryInfo . actionID = name ;
615
651
await commandName ( this . contextManager . defaultContext ) ;
616
652
} else {
617
653
this . memoryInfo . commandNames . push ( commandName ) ;
654
+ if ( params ) markNotVersionable ( params ) ;
655
+ this . memoryInfo . actionID = commandName ;
618
656
await this . dispatcher . dispatch ( commandName , params ) ;
619
657
}
620
658
}
0 commit comments