diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 4b52509be..a8d8e3665 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -702,7 +702,7 @@ func renameConflictsToParent(g *d2graph.Graph, key *d2ast.KeyPath) (*d2graph.Gra hoistedAbsKey.Path = append(hoistedAbsKey.Path, ref.Key.Path[:ref.KeyPathIndex]...) hoistedAbsKey.Path = append(hoistedAbsKey.Path, absKey.Path[len(absKey.Path)-1]) - uniqueKeyStr, _, err := generateUniqueKey(g, strings.Join(d2graph.Key(hoistedAbsKey), "."), nil, newIDs) + uniqueKeyStr, _, err := generateUniqueKey(g, strings.Join(d2graph.Key(hoistedAbsKey), "."), obj, newIDs) if err != nil { return nil, err } diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index 09f82c211..0cab38984 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -4834,6 +4834,24 @@ Square: { Text: { Text 2 } +Text 2 +`, + }, + { + name: "conflicts_generated_continued", + text: `Text 4 + +Text: { + Text 2 +} +Text 2 +`, + key: `Text`, + + exp: `Text 4 + +Text + Text 2 `, }, @@ -5399,6 +5417,22 @@ Square: { "Square.Text": "Text 2", "Square.Text 4": "Text", "Square.Text 4.Text 2": "Text.Text 2" +}`, + }, + { + name: "delete_generated_id_conflicts_2_continued", + + text: `Text 4 + +Text: { + Text 2 +} +Text 2 +`, + key: "Text", + + exp: `{ + "Text.Text 2": "Text" }`, }, } diff --git a/testdata/d2oracle/TestDelete/conflicts_generated_continued.exp.json b/testdata/d2oracle/TestDelete/conflicts_generated_continued.exp.json new file mode 100644 index 000000000..00fd618c5 --- /dev/null +++ b/testdata/d2oracle/TestDelete/conflicts_generated_continued.exp.json @@ -0,0 +1,250 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-5:0:21", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-0:6:6", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-0:6:6", + "value": [ + { + "string": "Text 4", + "raw_string": "Text 4" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,2:0:8-2:4:12", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,2:0:8-2:4:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,2:0:8-2:4:12", + "value": [ + { + "string": "Text", + "raw_string": "Text" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,4:0:14-4:6:20", + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,4:0:14-4:6:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,4:0:14-4:6:20", + "value": [ + { + "string": "Text 2", + "raw_string": "Text 2" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "Text 4", + "id_val": "Text 4", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,0:0:0-0:6:6", + "value": [ + { + "string": "Text 4", + "raw_string": "Text 4" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "Text 4" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "Text", + "id_val": "Text", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,2:0:8-2:4:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,2:0:8-2:4:12", + "value": [ + { + "string": "Text", + "raw_string": "Text" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "Text" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "Text 2", + "id_val": "Text 2", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,4:0:14-4:6:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestDelete/conflicts_generated_continued.d2,4:0:14-4:6:20", + "value": [ + { + "string": "Text 2", + "raw_string": "Text 2" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "Text 2" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +}