This commit is contained in:
Alexander Wang 2024-03-29 00:16:42 -07:00
parent 06e335799e
commit 6826ee4f69
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
5 changed files with 3273 additions and 3 deletions

View file

@ -500,7 +500,11 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
refs = GetWriteableEdgeRefs(edge, baseAST)
}
onlyInChain := true
for _, ref := range refs {
var earliestRef *d2graph.EdgeReference
for i, ref := range refs {
if earliestRef == nil || ref.MapKey.Range.Before(earliestRef.MapKey.Range) {
earliestRef = &refs[i]
}
// TODO merge flat edgekeys
// E.g. this can group into a map
// (y -> z)[0].style.opacity: 0.4
@ -526,7 +530,15 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
}
}
if onlyInChain {
appendMapKey(scope, mk)
if earliestRef != nil && scope.Range.Before(earliestRef.MapKey.Range) {
// Since the original mk was trimmed to common, we set to the edge that
// the ref's scope is in
mk.Edges[0] = earliestRef.Edge
// We can't reference an edge before it's been defined
earliestRef.Scope.InsertAfter(earliestRef.MapKey, mk)
} else {
appendMapKey(scope, mk)
}
return nil
}
attrs = edge.Attributes

View file

@ -2457,7 +2457,7 @@ a -> b
`,
},
{
name: "nested-edge-chained",
name: "nested-edge-chained/1",
text: `a: {
b: {
@ -2477,6 +2477,31 @@ x -> a.b -> a.b.c
x -> a.b -> a.b.c
(a.b -> a.b.c)[0].style.stroke: green
`,
},
{
name: "nested-edge-chained/2",
text: `z: {
a: {
b: {
c
}
}
x -> a.b -> a.b.c
}
`,
key: `(z.a.b -> z.a.b.c)[0].style.stroke`,
value: go2.Pointer(`green`),
exp: `z: {
a: {
b: {
c
}
}
x -> a.b -> a.b.c
(a.b -> a.b.c)[0].style.stroke: green
}
`,
},
}

1053
testdata/d2oracle/TestSet/nested-edge-chained.exp.json generated vendored Normal file

File diff suppressed because it is too large Load diff

1053
testdata/d2oracle/TestSet/nested-edge-chained/1.exp.json generated vendored Normal file

File diff suppressed because it is too large Load diff

1127
testdata/d2oracle/TestSet/nested-edge-chained/2.exp.json generated vendored Normal file

File diff suppressed because it is too large Load diff