This is a long-standing problem in driver.love as well:
Solution: create a variant of A called A1 that only does the work of A for a single node id (index) into Nodes.
This requires tracking for every shape we render in Surface, which id it is part of. That way we can selectively delete just shapes belonging to a single id.
Caveat: id is a scalar, so this approach can't handle any nesting, only a flat array of objects. But that's good enough for both driver.love and this app.
HIJWP6Q3CXDRIH7PJXN24JVQJF5Y53JKU7NKFPKCATQWI5DHQA3AC
S3KVM6VWRPNVXDNMFRINE2TTHI35QT4OS6K3RZUXJORWMEP2D2OAC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
SMZJGK56DYOP2CYIYDV3QXVHL5P52IEF34GFBESNMULJDMDLJR2AC
C2REOTRMF7EY6E3DAEL4ICI4O2AFAURWNQ7QCDMEZRNVM6ERM2UQC
J62CVGNGJZSN7TMTE2SG53O47YG4SJGJFTUFKVOZY4TM4KAC566QC
ZUXG2RU4WF5WF7EYU2XQJ6AERLJLOMGDEXWRMGWHT5DR3B7X7MWQC
T7T66GEUFLP3YHZN5UNOVBYK33KISJWJQKCPZU6MQH45KSU7CZZQC
YUQ4YINAT5YTK3CAY4VK3HSYQ4D63FXLLPMC4R3DUFHIZIUQO7WQC
GE7YT55JWPF5YGO2UPE6JDDBUKCP27CPHAE75XQ77IJWGFM2AJIQC
UJ2RZ43LIVRIBWIXHXMLIQIQTL32VVEN4CVU7PEBTITQFPO4EXXQC
A1 = function(id, preserve_screen_top_of_cursor_node)
-- like A, but translate a single node in Nodes to Surface
-- this only works because Nodes is a flat array; we don't support row/col types here yet
print('A1', id)
-- delete previously added shapes for this node:
for i=#Surface,1,-1 do
local x = Surface[i]
if x.id == id then
table.remove(Surface, i)
end
end
-- translate Nodes to Surface
local node = Nodes[id]
compute_layout(node, node.x,node.y, Surface, preserve_screen_top_of_cursor_node)
-- continue the pipeline
B(preserve_screen_top_of_cursor_node)
end
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20,node.y, node.x+node.w+20,node.y+buffer_height}})
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20+4,node.y, node.x+node.w+20+4,node.y+buffer_height}})
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20,node.y, node.x+node.w+20,node.y+buffer_height}, id=node.id})
table.insert(nodes_to_render, {type='line', r=0.7,g=0.7,b=0.7, data={node.x+node.w+20+4,node.y, node.x+node.w+20+4,node.y+buffer_height}, id=node.id})