Skip to content

Commit

Permalink
Merge pull request #2212 from alixander/set-with-label
Browse files Browse the repository at this point in the history
fix set with explicit label
  • Loading branch information
alixander authored Nov 14, 2024
2 parents 7b9f2d1 + 51950f0 commit 2400602
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 1 deletion.
7 changes: 6 additions & 1 deletion d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
m = obj.Map
}

if (obj.Label.MapKey != nil && writeableLabelMK) && m == nil && (!found || reserved || len(mk.Edges) > 0) {
if (obj.Label.MapKey != nil && writeableLabelMK) && m == nil && (!found || reserved || len(mk.Edges) > 0) &&
// Label is not set like `hey.label: mylabel`
// This should only work when label is set like `hey: mylabel`
(obj.Label.MapKey.Key == nil ||
len(obj.Label.MapKey.Key.Path) == 0 ||
obj.Label.MapKey.Key.Path[len(obj.Label.MapKey.Key.Path)-1].Unbox().ScalarString() != "label") {
m2 := &d2ast.Map{
Range: d2ast.MakeRange(",1:0:0-1:0:0"),
}
Expand Down
10 changes: 10 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,16 @@ square.style.opacity: 0.2
key: `square.top`,
value: go2.Pointer(`200`),
exp: `square: {top: 200}
`,
},
{
name: "labeled_set_position",
text: `hey.label: what
`,
key: `hey.top`,
value: go2.Pointer(`200`),
exp: `hey.label: what
hey.top: 200
`,
},
{
Expand Down
212 changes: 212 additions & 0 deletions testdata/d2oracle/TestSet/labeled_set_position.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2400602

Please sign in to comment.