Skip to content

Commit 75dc929

Browse files
committed
feat: Copy functions to all keys when converting list to dict pattern
When converting from list pattern to dict pattern (selecting group_by), copy the current function list to ALL new dict keys instead of creating empty lists for keys after the first one. This provides better UX - users can start with the same functions on all channels/wells/etc and then customize per-key as needed, rather than having to re-add functions to each key manually. Changes: - List-to-dict conversion: Copy current_functions to all component_keys - Adding new components: Copy from first non-empty existing component - Fallback to empty list only if no reference pattern exists
1 parent cfdd1e9 commit 75dc929

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

src/pyqt_reactive/widgets/function_list_editor.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,10 +1805,10 @@ def _update_components(self, new_components):
18051805
self._current_function_tokens = list_tokens
18061806
self._record_selected_pattern_key()
18071807

1808-
# Add other components with empty functions
1808+
# Add other components with copy of current functions
18091809
for component_key in component_keys[1:]:
1810-
self.pattern_data[component_key] = []
1811-
self._pattern_tokens[component_key] = [] # type: ignore[index]
1810+
self.pattern_data[component_key] = list(current_functions)
1811+
self._pattern_tokens[component_key] = list(list_tokens) # type: ignore[index]
18121812
else:
18131813
# Already in dict mode - update components
18141814
old_pattern = self.pattern_data.copy() if isinstance(self.pattern_data, dict) else {}
@@ -1837,6 +1837,15 @@ def _update_components(self, new_components):
18371837
new_tokens: Dict[str, List[str]] = {}
18381838

18391839
# Restore functions for components (from current pattern or storage)
1840+
# Get a reference pattern to copy from (first existing component)
1841+
reference_functions = None
1842+
reference_tokens = None
1843+
for ref_key in component_keys:
1844+
if ref_key in old_pattern and old_pattern[ref_key]:
1845+
reference_functions = old_pattern[ref_key]
1846+
reference_tokens = old_tokens.get(str(ref_key), [])
1847+
break
1848+
18401849
for component_key in component_keys:
18411850
if component_key in old_pattern:
18421851
# Component was already selected - keep its functions
@@ -1852,9 +1861,15 @@ def _update_components(self, new_components):
18521861
)
18531862
logger.debug(f"Restored {len(new_pattern[component_key])} functions for reselected component {component_key}")
18541863
else:
1855-
# New component - start with empty functions
1856-
new_pattern[component_key] = []
1857-
new_tokens[component_key] = []
1864+
# New component - copy from reference pattern if available
1865+
if reference_functions is not None:
1866+
new_pattern[component_key] = list(reference_functions)
1867+
new_tokens[component_key] = list(reference_tokens) if reference_tokens else []
1868+
logger.debug(f"Copied {len(reference_functions)} functions to new component {component_key}")
1869+
else:
1870+
# No reference available - start with empty functions
1871+
new_pattern[component_key] = []
1872+
new_tokens[component_key] = []
18581873

18591874
self.pattern_data = new_pattern
18601875
self._pattern_tokens = new_tokens

0 commit comments

Comments
 (0)