Fix live tree selection lost after wiresheet DOM rebuild
After open_wiresheet rebuilds the DOM and tree, re-find the target element by its comp id (not the old tree item ID which no longer exists) and re-select it with the restoring flag to prevent recursion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ so later rebinding would only ever be seen by the module that did it.
|
||||
import configparser
|
||||
import os
|
||||
|
||||
VERSION = "0.0.0.077"
|
||||
VERSION = "0.0.0.078"
|
||||
PROPERTIES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "editor.properties")
|
||||
DEFAULT_GRID_SIZE = 10
|
||||
DEFAULT_ADD_TIMESTAMP = True
|
||||
|
||||
@@ -578,7 +578,7 @@ def on_canvas_wheel_zoom(event):
|
||||
|
||||
def on_tree_select(event):
|
||||
"""Triggered when a branch node is clicked in the Navigation view."""
|
||||
global _pending_link_selection
|
||||
global _pending_link_selection, _restoring_selection
|
||||
|
||||
# Read and cleared first thing, so a link a jump asked for is only ever picked out
|
||||
# by the very selection that jump made. A selection that turns out not to paint a
|
||||
@@ -621,8 +621,18 @@ def on_tree_select(event):
|
||||
ds.build_links_elements(sax_root)
|
||||
app_state.xml_root_element = sax_root
|
||||
sax_file.refresh_treeview_from_dom(sax_root)
|
||||
# re-find the element after DOM rebuild
|
||||
element = app_state.tree_element_map.get(selected_id)
|
||||
# re-find element by comp id after DOM rebuild (tree item IDs changed)
|
||||
element = None
|
||||
for tid, elem in app_state.tree_element_map.items():
|
||||
if elem.get("id") == comp_id_str:
|
||||
element = elem
|
||||
selected_id = tid
|
||||
break
|
||||
if element is not None:
|
||||
_restoring_selection = True
|
||||
tree.selection_set(selected_id)
|
||||
tree.see(selected_id)
|
||||
tree.after_idle(_clear_restoring_flag)
|
||||
app_state.current_sheet_parent = element
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user