svghmi/widget_switch.ysl2
changeset 3518 c663d1f9f03b
parent 3516 d3cf85a3c282
--- a/svghmi/widget_switch.ysl2	Wed Jun 15 11:46:48 2022 +0200
+++ b/svghmi/widget_switch.ysl2	Mon Jun 20 09:19:56 2022 +0200
@@ -43,7 +43,7 @@
                     }
                 } else {
                     if(choice.parent != undefined){
-                        choice.parent.appendChild(choice.elt);
+                        choice.parent.insertBefore(choice.elt,choice.sibling);
                         choice.parent = undefined;
                     }
                 }
@@ -60,11 +60,21 @@
     const "subwidgets", "$subelts//*[@id = $hmi_widgets/@id]";
     const "accepted", "$subelts[not(ancestor-or-self::*/@id = $subwidgets/@id)]";
 
-    foreach "$accepted[regexp:test(@inkscape:label,$regex)]" {
+    const "choices", "$accepted[regexp:test(@inkscape:label,$regex)]";
+    foreach "$choices" {
         const "literal", "regexp:match(@inkscape:label,$regex)[2]";
+        const "sibling", "following-sibling::*[not(@id = $choices/@id)][position()=1]";
     |         {
     |             elt:id("«@id»"),
     |             parent:undefined,
+    choose {
+        when "count($sibling)=0" {
+    |             sibling:null,
+        }
+        otherwise {
+    |             sibling:id("«$sibling/@id»"),
+        }
+    }
     |             value:«$literal»
     |         }`if "position()!=last()" > ,`
     }