Skip to content

Commit

Permalink
fix imported
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Jan 4, 2024
1 parent db1155e commit a6bfd1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 0 additions & 4 deletions d2graph/d2graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ func (r Reference) InEdge() bool {
return r.Key != r.MapKey.Key
}

// func (r Reference) IsSameBoard() bool {
// return r.Key != r.MapKey.Key
// }

type Style struct {
Opacity *Scalar `json:"opacity,omitempty"`
Stroke *Scalar `json:"stroke,omitempty"`
Expand Down
8 changes: 5 additions & 3 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
toSkip := 1

reserved := false
imported := false

// If you're setting `(x -> y)[0].style.opacity`
// There's 3 cases you need to handle:
Expand Down Expand Up @@ -382,9 +383,10 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
break
}
obj = o
imported = IsImported(baseAST, obj)

var maybeNewScope *d2ast.Map
if baseAST != g.AST {
if baseAST != g.AST || imported {
writeableRefs := getWriteableRefs(obj, baseAST)
for _, ref := range writeableRefs {
if ref.MapKey != nil && ref.MapKey.Value.Map != nil {
Expand All @@ -411,7 +413,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)

writeableLabelMK := true
var objK *d2ast.Key
if baseAST != g.AST {
if baseAST != g.AST || imported {
writeableRefs := getWriteableRefs(obj, baseAST)
if len(writeableRefs) > 0 {
objK = writeableRefs[0].MapKey
Expand Down Expand Up @@ -3112,7 +3114,7 @@ func filterReservedPath(path []*d2ast.StringBox) (filtered []*d2ast.StringBox) {

func getWriteableRefs(obj *d2graph.Object, writeableAST *d2ast.Map) (out []d2graph.Reference) {
for i, ref := range obj.References {
if ref.ScopeAST == writeableAST {
if ref.ScopeAST == writeableAST && ref.Key.Range.Path == writeableAST.Range.Path {
out = append(out, obj.References[i])
}
}
Expand Down
8 changes: 4 additions & 4 deletions d2oracle/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ func GetParentID(g *d2graph.Graph, boardPath []string, absID string) (string, er
return obj.Parent.AbsID(), nil
}

func IsImported(g *d2graph.Graph, obj *d2graph.Object) bool {
func IsImported(ast *d2ast.Map, obj *d2graph.Object) bool {
for _, ref := range obj.References {
if ref.MapKey.Range.Path == g.AST.Range.Path {
return false
if ref.Key.Range.Path != ast.Range.Path {
return true
}
}

return true
return false
}

func GetObj(g *d2graph.Graph, boardPath []string, absID string) *d2graph.Object {
Expand Down

0 comments on commit a6bfd1b

Please sign in to comment.