From 5da51c9f9289e5f02a4ae8a503b64e16804cc6bd Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 26 Jun 2023 14:27:26 -0700 Subject: [PATCH] reparentiddelta --- d2oracle/edit.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 1c4e850db..4e6c3f96d 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -2196,23 +2196,34 @@ func deleteFromMap(m *d2ast.Map, mk *d2ast.Key) bool { return false } -func ReparentIDDelta(g *d2graph.Graph, key, parentKey string) (string, error) { +func ReparentIDDelta(g *d2graph.Graph, boardPath []string, key, parentKey string) (string, error) { mk, err := d2parser.ParseMapKey(key) if err != nil { return "", err } - obj, ok := g.Root.HasChild(d2graph.Key(mk.Key)) + + boardG := g + + if len(boardPath) > 0 { + // When compiling a nested board, we can read from boardG but only write to baseBoardG + boardG = GetBoardGraph(g, boardPath) + if boardG == nil { + return "", fmt.Errorf("board %v not found", boardPath) + } + } + + obj, ok := boardG.Root.HasChild(d2graph.Key(mk.Key)) if !ok { return "", errors.New("not found") } - parent := g.Root + parent := boardG.Root if parentKey != "" { mk2, err := d2parser.ParseMapKey(parentKey) if err != nil { return "", err } - parent, ok = g.Root.HasChild(d2graph.Key(mk2.Key)) + parent, ok = boardG.Root.HasChild(d2graph.Key(mk2.Key)) if !ok { return "", errors.New("not found") }