@@ -102,7 +102,7 @@ export class DiffFile {
102102
103103 #unifiedLastStartIndex?: number ;
104104
105- #listeners: ( ( ) => void ) [ ] = [ ] ;
105+ #listeners: ( ( ( ) => void ) & { isSyncExternal ?: boolean } ) [ ] = [ ] ;
106106
107107 #hasInitRaw: boolean = false ;
108108
@@ -132,6 +132,8 @@ export class DiffFile {
132132
133133 #id: string = "" ;
134134
135+ #clonedInstance = new Map < DiffFile , ( ) => void > ( ) ;
136+
135137 static createInstance (
136138 data : {
137139 oldFile ?: { fileName ?: string | null ; fileLang ?: string | null ; content ?: string | null } ;
@@ -786,26 +788,40 @@ export class DiffFile {
786788 return this . #newFileSyntaxLines?. [ lineNumber ] ;
787789 } ;
788790
789- subscribe = ( listener : ( ) => void ) => {
791+ subscribe = ( listener : ( ( ) => void ) & { isSyncExternal ?: boolean } ) => {
790792 this . #listeners. push ( listener ) ;
791793
792794 return ( ) => {
793795 this . #listeners. filter ( ( i ) => i !== listener ) ;
794796 } ;
795797 } ;
796798
797- notifyAll = ( ) => {
799+ notifyAll = ( skipSyncExternal ?: boolean ) => {
798800 this . #updateCount++ ;
799- this . #listeners. forEach ( ( f ) => f ( ) ) ;
801+ this . #listeners. forEach ( ( f ) => {
802+ if ( skipSyncExternal && f . isSyncExternal ) {
803+ return ;
804+ }
805+ f ( ) ;
806+ } ) ;
800807 } ;
801808
802809 getUpdateCount = ( ) => this . #updateCount;
803810
804811 getNeedShowExpandAll = ( mode : "split" | "unified" ) => {
805812 if ( mode === "split" ) {
806- return this . #splitLastStartIndex && Number . isFinite ( this . #splitLastStartIndex) ;
813+ return (
814+ this . #splitLastStartIndex &&
815+ Number . isFinite ( this . #splitLastStartIndex) &&
816+ ( this . getSplitLeftLine ( this . splitLineLength - 1 ) ?. isHidden ||
817+ this . getSplitRightLine ( this . splitLineLength - 1 ) ?. isHidden )
818+ ) ;
807819 } else {
808- return this . #unifiedLastStartIndex && Number . isFinite ( this . #unifiedLastStartIndex) ;
820+ return (
821+ this . #unifiedLastStartIndex &&
822+ Number . isFinite ( this . #unifiedLastStartIndex) &&
823+ this . getUnifiedLine ( this . unifiedLineLength - 1 ) ?. isHidden
824+ ) ;
809825 }
810826 } ;
811827
@@ -891,6 +907,34 @@ export class DiffFile {
891907 this . notifyAll ( ) ;
892908 } ;
893909
910+ _addClonedInstance = ( instance : DiffFile ) => {
911+ const updateFunc = ( ) => {
912+ this . _notifyOthers ( instance ) ;
913+ } ;
914+
915+ updateFunc . isSyncExternal = true ;
916+
917+ const unsubscribe = instance . subscribe ( updateFunc ) ;
918+
919+ this . #clonedInstance. set ( instance , unsubscribe ) ;
920+ } ;
921+
922+ _notifyOthers = ( instance : DiffFile ) => {
923+ this . #clonedInstance. forEach ( ( _ , i ) => {
924+ if ( i !== instance ) {
925+ i . notifyAll ( true ) ;
926+ }
927+ } ) ;
928+ } ;
929+
930+ _delClonedInstance = ( instance : DiffFile ) => {
931+ const unsubscribe = this . #clonedInstance. get ( instance ) ;
932+
933+ unsubscribe && unsubscribe ( ) ;
934+
935+ this . #clonedInstance. delete ( instance ) ;
936+ } ;
937+
894938 _getFullBundle = ( ) => {
895939 const bundle = this . getBundle ( ) ;
896940 const oldFileResult = this . #oldFileResult;
@@ -914,4 +958,11 @@ export class DiffFile {
914958 this . #diffLines = data . diffLines ;
915959 this . #diffListResults = data . diffListResults ;
916960 } ;
961+
962+ _destroy = ( ) => {
963+ this . clearId ( ) ;
964+ this . #listeners. splice ( 0 , this . #listeners. length ) ;
965+ this . #clonedInstance. forEach ( ( v ) => v ( ) ) ;
966+ this . #clonedInstance. clear ( ) ;
967+ } ;
917968}
0 commit comments