@@ -383,7 +383,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
383
383
break
384
384
}
385
385
obj = o
386
- imported = IsImported (baseAST , obj )
386
+ imported = IsImportedObj (baseAST , obj )
387
387
388
388
var maybeNewScope * d2ast.Map
389
389
if baseAST != g .AST || imported {
@@ -481,8 +481,9 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
481
481
if ! ok {
482
482
return errors .New ("edge not found" )
483
483
}
484
+ imported = IsImportedEdge (baseAST , edge )
484
485
refs := edge .References
485
- if baseAST != g .AST {
486
+ if baseAST != g .AST || imported {
486
487
refs = getWriteableEdgeRefs (edge , baseAST )
487
488
}
488
489
onlyInChain := true
@@ -868,45 +869,52 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
868
869
return g , nil
869
870
}
870
871
871
- refs := e .References
872
- if len (boardPath ) > 0 {
873
- refs := getWriteableEdgeRefs (e , baseAST )
874
- if len (refs ) != len (e .References ) {
875
- mk .Value = d2ast .MakeValueBox (& d2ast.Null {})
876
- }
877
- }
872
+ imported := IsImportedEdge (baseAST , e )
878
873
879
- if _ , ok := mk .Value .Unbox ().(* d2ast.Null ); ! ok {
880
- ref := refs [0 ]
881
- var refEdges []* d2ast.Edge
882
- for _ , ref := range refs {
883
- refEdges = append (refEdges , ref .Edge )
874
+ if imported {
875
+ mk .Value = d2ast .MakeValueBox (& d2ast.Null {})
876
+ appendMapKey (baseAST , mk )
877
+ } else {
878
+ refs := e .References
879
+ if len (boardPath ) > 0 {
880
+ refs := getWriteableEdgeRefs (e , baseAST )
881
+ if len (refs ) != len (e .References ) {
882
+ mk .Value = d2ast .MakeValueBox (& d2ast.Null {})
883
+ }
884
884
}
885
- ensureNode (g , refEdges , ref .ScopeObj , ref .Scope , ref .MapKey , ref .MapKey .Edges [ref .MapKeyEdgeIndex ].Src , true )
886
- ensureNode (g , refEdges , ref .ScopeObj , ref .Scope , ref .MapKey , ref .MapKey .Edges [ref .MapKeyEdgeIndex ].Dst , false )
887
885
888
- for i := len (e .References ) - 1 ; i >= 0 ; i -- {
889
- ref := e .References [i ]
890
- deleteEdge (g , ref .Scope , ref .MapKey , ref .MapKeyEdgeIndex )
891
- }
886
+ if _ , ok := mk .Value .Unbox ().(* d2ast.Null ); ! ok {
887
+ ref := refs [0 ]
888
+ var refEdges []* d2ast.Edge
889
+ for _ , ref := range refs {
890
+ refEdges = append (refEdges , ref .Edge )
891
+ }
892
+ ensureNode (g , refEdges , ref .ScopeObj , ref .Scope , ref .MapKey , ref .MapKey .Edges [ref .MapKeyEdgeIndex ].Src , true )
893
+ ensureNode (g , refEdges , ref .ScopeObj , ref .Scope , ref .MapKey , ref .MapKey .Edges [ref .MapKeyEdgeIndex ].Dst , false )
892
894
893
- edges , ok := obj .FindEdges (mk )
894
- if ok {
895
- for _ , e2 := range edges {
896
- if e2 .Index <= e .Index {
897
- continue
898
- }
899
- for i := len (e2 .References ) - 1 ; i >= 0 ; i -- {
900
- ref := e2 .References [i ]
901
- if ref .MapKey .EdgeIndex != nil {
902
- * ref .MapKey .EdgeIndex .Int --
895
+ for i := len (e .References ) - 1 ; i >= 0 ; i -- {
896
+ ref := e .References [i ]
897
+ deleteEdge (g , ref .Scope , ref .MapKey , ref .MapKeyEdgeIndex )
898
+ }
899
+
900
+ edges , ok := obj .FindEdges (mk )
901
+ if ok {
902
+ for _ , e2 := range edges {
903
+ if e2 .Index <= e .Index {
904
+ continue
905
+ }
906
+ for i := len (e2 .References ) - 1 ; i >= 0 ; i -- {
907
+ ref := e2 .References [i ]
908
+ if ref .MapKey .EdgeIndex != nil {
909
+ * ref .MapKey .EdgeIndex .Int --
910
+ }
903
911
}
904
912
}
905
913
}
914
+ } else {
915
+ // NOTE: it only needs to be after the last ref, but perhaps simplest and cleanest to append all nulls at the end
916
+ appendMapKey (baseAST , mk )
906
917
}
907
- } else {
908
- // NOTE: it only needs to be after the last ref, but perhaps simplest and cleanest to append all nulls at the end
909
- appendMapKey (baseAST , mk )
910
918
}
911
919
if len (boardPath ) > 0 {
912
920
replaced := ReplaceBoardNode (g .AST , baseAST , boardPath )
@@ -925,10 +933,9 @@ func Delete(g *d2graph.Graph, boardPath []string, key string) (_ *d2graph.Graph,
925
933
return g , nil
926
934
}
927
935
928
- imported := IsImported (baseAST , obj )
936
+ imported := IsImportedObj (baseAST , obj )
929
937
930
938
if imported {
931
- println (d2format .Format (boardG .AST ))
932
939
mk .Value = d2ast .MakeValueBox (& d2ast.Null {})
933
940
appendMapKey (baseAST , mk )
934
941
} else {
0 commit comments