From 90009de842bdfc3e60d140d9533cb64f2ad50f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Abush=20Clause?= Date: Tue, 17 Feb 2026 09:05:39 +0100 Subject: [PATCH] Fix alternative criteria reordering when adding second alternative When a rule has exactly one alternative, the Rule Editor uses "Simple Mode" and edits it through SimpleSingleNodeCriteriaPanel, whose getData() always targets criteria[0]. Clicking "Add alternatives" correctly inserts the new alternative into the rule's criteria list, then calls RuleEditorDialog.switchToFullEditor() to reload the dialog in full mode. That method unconditionally flushes the currently shown (now stale) single-node panel via updateData(), which writes its widget values -- still reflecting the previous sole alternative -- into criteria[0]. If the new alternative was reordered to the first position, this silently overwrites its freshly entered data with the old alternative's data. Left at the default last position, criteria[0] is still the old alternative, so the overwrite is a no-op, which is why the bug only surfaced when reordering a newly added second alternative to position 1. Fix switchToFullEditor() to accept an opt-out for this flush, and use it from the alternative-creation path where the data has already been persisted through the Criteria Set editor and must not be re-flushed from the stale panel. Also fix the Criteria Set editor's sequence order default, which used an out-of-range fallback constant (nbAlternatives + 1) instead of the last valid position (nbAlternatives - 1). Fixes #62 --- .../webAccess/gui/rule/criteriaEditor.py | 3 ++- addon/globalPlugins/webAccess/gui/rule/editor.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py b/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py index 9a9414bb..d87ae988 100644 --- a/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py +++ b/addon/globalPlugins/webAccess/gui/rule/criteriaEditor.py @@ -471,7 +471,8 @@ def initData(self, context): else: for index in range(nbAlternatives): self.sequenceOrderChoice.Append(str(index + 1)) - index = data.get("criteriaIndex", nbAlternatives + 1) + # Default to the last position (append) if unset, e.g. when adding a new alternative. + index = data.get("criteriaIndex", nbAlternatives - 1) self.sequenceOrderChoice.SetSelection(index) if self.getRuleType() == ruleTypes.ZONE: key = "convert.single" if isDualNode(data) else "convert.dual" diff --git a/addon/globalPlugins/webAccess/gui/rule/editor.py b/addon/globalPlugins/webAccess/gui/rule/editor.py index 2fa00ac5..8ccf62cd 100644 --- a/addon/globalPlugins/webAccess/gui/rule/editor.py +++ b/addon/globalPlugins/webAccess/gui/rule/editor.py @@ -1092,7 +1092,12 @@ def onCriteriaChange(self, change: Change, index: int): parent = self.Parent dlg = parent.Parent.Parent if change is Change.CREATION: - dlg.switchToFullEditor() + # The new alternative has already been inserted into the rule's criteria + # list. Do not flush the currently shown single-node panel: it still holds + # the widget values of the previous sole alternative and, since indices may + # have shifted, could otherwise overwrite the newly created alternative's + # data with stale data (e.g. when it is reordered to the first position). + dlg.switchToFullEditor(updateData=False) return parent.switchToAppropriatePanel() parent.shownPanel.initData(self.context) @@ -1417,11 +1422,12 @@ def onCharHook(self, evt): return super().onCharHook(evt) - def switchToFullEditor(self): + def switchToFullEditor(self, updateData=True): if not self.simpleMode: wx.Bell() return - self.currentCategory.updateData() + if updateData: + self.currentCategory.updateData() tree = self.catListCtrl treePath = [] child = tree.GetSelection()