From e1cff6068c2e150be19e209c863e6064c2fb42db Mon Sep 17 00:00:00 2001 From: Mario Pietsch Date: Tue, 5 May 2026 11:23:36 +0200 Subject: [PATCH] Fix SelectWidget multi-select highlight regression for options containing HTML (#9839) (#9841) PR #8093 used `child.children.length === 0` to distinguish a plain . This test misfires when an support but used `child.children.length === 0` to + // distinguish a plain . That heuristic misfires for + // any " + + "" + + "" + + ""; + var widgetNode = createWidgetNode(parseText(widgetText,wiki),wiki); + var wrapper = renderWidgetNode(widgetNode); + var select = findSelectDom(wrapper); + expect(select === null).toBe(false); + expect(select.children.length).toBe(3); + + // After initial render, options matching the field value should be selected. + // foo (idx 0), bar (idx 1), $:/mumble (idx 2). + expect(selectedFlags(select)).toEqual([true,false,true]); + + // Change the stored field value and refresh - this is where the bug surfaced: + // the "$:/mumble" option (with an child) was wrongly skipped. + wiki.addTiddler({title: "Picks", mylist: "bar $:/mumble"}); + refreshWidgetNode(widgetNode,wrapper,["Picks"]); + + expect(selectedFlags(select)).toEqual([false,true,true]); + // The inner must not be touched - .selected is meaningful only on across refresh, including $:/-prefixed entries with inline HTML",function() { + var wiki = $tw.test.wiki(); + wiki.addTiddlers([ + {title: "Picks", mylist: "1 $:/mumble"} + ]); + // The "high" group mixes a plain option with a $:/-prefixed option whose + // content is wrapped in an auto-link - same pattern that broke #9839 + // for top-level options, exercised here inside an . + var widgetText = "<$select tiddler='Picks' field='mylist' multiple>" + + "" + + "" + + "" + + "" + + "" + + "" + + "$:/mumble" + + "" + + ""; + var widgetNode = createWidgetNode(parseText(widgetText,wiki),wiki); + var wrapper = renderWidgetNode(widgetNode); + var select = findSelectDom(wrapper); + expect(select === null).toBe(false); + expect(select.children.length).toBe(2); + + // Initial state: "1" and "$:/mumble" selected + expect(selectedFlags(select.children[0])).toEqual([true,false]); + expect(selectedFlags(select.children[1])).toEqual([false,true]); + + wiki.addTiddler({title: "Picks", mylist: "2 4"}); + refreshWidgetNode(widgetNode,wrapper,["Picks"]); + expect(selectedFlags(select.children[0])).toEqual([false,true]); + expect(selectedFlags(select.children[1])).toEqual([true,false]); + }); + +});