@@ -12,8 +12,10 @@ import { AtomicNode } from './VNodes/AtomicNode';
1212import { SeparatorNode } from './VNodes/SeparatorNode' ;
1313import { ModeIdentifier , ModeDefinition , Mode , RuleProperty } from './Mode' ;
1414import { Memory , ChangesLocations } from './Memory/Memory' ;
15- import { makeVersionable } from './Memory/Versionable' ;
15+ import { makeVersionable , markNotVersionable } from './Memory/Versionable' ;
1616import { VersionableArray } from './Memory/VersionableArray' ;
17+ import { VersionableSet } from './Memory/VersionableSet' ;
18+ import { MemoryOrigin } from '../../plugin-devtools/src/components/MemoryComponent' ;
1719import { Point , VNode } from './VNodes/VNode' ;
1820
1921export enum EditorStage {
@@ -85,6 +87,10 @@ export interface PluginMap extends Map<typeof JWPlugin, JWPlugin> {
8587 get < T extends typeof JWPlugin > ( constructor : T ) : InstanceType < T > ;
8688}
8789
90+ interface MemoryInfo extends MemoryOrigin {
91+ uiCommand : boolean ;
92+ }
93+
8894export class JWEditor {
8995 private _stage : EditorStage = EditorStage . CONFIGURATION ;
9096 dispatcher : Dispatcher ;
@@ -101,7 +107,7 @@ export class JWEditor {
101107 deadlockTimeout : 10000 ,
102108 } ;
103109 memory : Memory ;
104- memoryInfo : { commandNames : string [ ] ; uiCommand : boolean } ;
110+ memoryInfo : MemoryInfo ;
105111 private _memoryID = 0 ;
106112 selection : VSelection ;
107113 loaders : Record < string , Loader > = { } ;
@@ -161,7 +167,18 @@ export class JWEditor {
161167 this . memory = new Memory ( ) ;
162168 this . memory . attach ( this . selection . range . start ) ;
163169 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+ } ) ;
165182 this . memory . attach ( this . memoryInfo ) ;
166183 this . memory . create ( this . _memoryID . toString ( ) ) ;
167184
@@ -500,7 +517,10 @@ export class JWEditor {
500517 const origin = this . memory . sliceKey ;
501518 const memorySlice = this . _memoryID . toString ( ) ;
502519 this . memory . switchTo ( memorySlice ) ;
520+ this . memoryInfo . isMaster = false ;
521+ this . memoryInfo . layers = new VersionableSet ( [ memorySlice ] ) ;
503522 this . memoryInfo . commandNames = new VersionableArray ( ) ;
523+ this . memoryInfo . actionID = null ;
504524 this . memoryInfo . uiCommand = false ;
505525 let commandNames = this . memoryInfo . commandNames ;
506526
@@ -510,13 +530,16 @@ export class JWEditor {
510530 if ( typeof commandName === 'function' ) {
511531 const name = '@custom' + ( commandName . name ? ':' + commandName . name : '' ) ;
512532 this . memoryInfo . commandNames . push ( name ) ;
533+ this . memoryInfo . actionID = name ;
513534 await commandName ( this . contextManager . defaultContext ) ;
514535 if ( this . memory . sliceKey !== memorySlice ) {
515536 // Override by the current commandName if the slice changed.
516537 commandNames = [ name ] ;
517538 }
518539 } else {
519540 this . memoryInfo . commandNames . push ( commandName ) ;
541+ if ( params ) markNotVersionable ( params ) ;
542+ this . memoryInfo . actionID = commandName ;
520543 await this . dispatcher . dispatch ( commandName , params ) ;
521544 if ( this . memory . sliceKey !== memorySlice ) {
522545 // Override by the current commandName if the slice changed.
@@ -538,7 +561,14 @@ export class JWEditor {
538561 exec ( ) . then ( resolve , reject ) ;
539562 } ) ;
540563
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.
542572 this . _memoryID ++ ;
543573 const nextMemorySlice = this . _memoryID . toString ( ) ;
544574 this . memory . create ( nextMemorySlice ) ;
@@ -567,6 +597,12 @@ export class JWEditor {
567597
568598 const failedSlice = this . memory . sliceKey ;
569599
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+
570606 // When an error occurs, we go back to part of the functional memory.
571607 this . memory . switchTo ( origin ) ;
572608
@@ -609,12 +645,14 @@ export class JWEditor {
609645 params ?: CommandParamsType < P , C > ,
610646 ) : Promise < void > {
611647 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 ;
615651 await commandName ( this . contextManager . defaultContext ) ;
616652 } else {
617653 this . memoryInfo . commandNames . push ( commandName ) ;
654+ if ( params ) markNotVersionable ( params ) ;
655+ this . memoryInfo . actionID = commandName ;
618656 await this . dispatcher . dispatch ( commandName , params ) ;
619657 }
620658 }
0 commit comments