I ended up using most of your code in the procedure that I named edit-modifiers
instead of select-modsB
; just refactored it to be displayed on a line rather than vertically and a few minor tweaks. I also included a conditional to check if a modifier can be leveled or not (not all of them can be, and if they can’t be, they should remain at level 1 and not allow users to access their level), as well as a call to the lvl-mods-sum
procedure for visibility, that calculates the total effect of the mods:
\procedure update-mod-level()
\function updated() [<segment>split[ ]butlast[]] [<newLevel>] +[join[ ]]
<$action-setfield $tiddler=<<book>>
$field=<<advantage>>
$value={{{ [<current>search-replace<segment>,<updated>] }}} />
<$action-deletetiddler $tiddler=<<tempLevel>> />
\end
\procedure edit-modifiers(advantage, book)
<$let
book={{{ [<book>!match[]] ~[<currentTiddler>] }}}
current={{{ [<book>get<advantage>] }}}
>
<% if [<current>!match[]] %>
<table>
<tr><td><$macrocall $name="lvl-mods-sum" advbook=<<book>> adv=<<advantage>>/></td><$list filter="[<current>split[, ]!is[blank]]" variable="segment">
<$let
mod={{{ [<segment>split[ ]butlast[]join[ ]] }}}
currentLevel={{{ [<segment>split[ ]last[]else[1]] }}}
tempLevel=`$:/temp/$(book)$/$(mod)$/level`
>
<td><$link to=<<mod>>/></td>
<td>
<% if [<mod>get[levelable]match[yes]] %><$select tiddler=<<tempLevel>> default=<<currentLevel>>>
<$list filter="[range[20]]">
<!-- ^ use the maximum level possible -->
<option>{{!!title}}</option>
</$list>
</$select>
<$list filter="[<tempLevel>get[text]]" variable="newLevel">
<$button actions=<<update-mod-level>>>{{$:/core/images/save-button}}</$button>
</$list><% else %>Not levelable<% endif %>
</td>
</$let>
</$list>
</tr></table>
<% endif %>
<$macrocall $name=select-mods advantage=<<advantage>> book=<<book>>/>
</$let>
\end
However, I have a bug to squash, as when one adds a modifier through the select, then removes it, the <advantage>
field in the <book>
is left with an extra empty mod that throws things off:

As you’ll see in the code above, I have a “cosmetic” workaround in place for now through the addition of !is[blank]
after the split expression of the <$list>
widget in the edit-modifiers
procedure, but the root cause is most likely in the mod-select-actions
procedure below (copied the whole thing as it stands currently for easier reference):
\procedure mod-select-actions()
<$let
currentTiddler=<<book>>
current={{{ [<book>get<advantage>] }}}
selected={{$:/temp/generated-list-mod-state}}
new=`$(selected)$ 1`
existing=`$(selected)$ \d+(,\s?)?`
>
<% if [<current>search<selected>] %>
<$action-setfield
$field=<<advantage>>
$value={{{ [<current>search-replace::regexp<existing>,[]] }}} />
<% else %>
<$action-setfield
$field=<<advantage>>
$value={{{ [<current>!match[]] [<new>] +[join[, ]] }}} />
<% endif %>
<$action-deletetiddler $tiddler="$:/temp/generated-list-mod-state" />
\end
\procedure mod-select-option()
<option value={{!!title}}>
{{!!title}} ({{{ [{!!title}get[modifier-value]] }}}%)
<$list filter=`[<book>search:$(advantage)${!!title}]`>✔</$list>
</option>
\end
\procedure select-mods(advantage, book)
<$let book={{{ [<book>!match[]] ~[<currentTiddler>] }}}>
<$select tiddler="$:/temp/generated-list-mod-state"
default=""
actions=<<mod-select-actions>>
>
<option value="" disabled>Select modifier</option>
<optgroup label="Special">
<$list filter="[tag[GURPS Modifier]search:to-advantages:<advantage>]">
<<mod-select-option>>
</$list>
</optgroup>
<optgroup label="Global modifiers">
<$list filter="[tag[GURPS Modifier]!has[to-advantages]] -[[Modifier template]]">
<<mod-select-option>>
</$list>
</optgroup>
</$select></$let>
\end
My guess is there may be something off with the backtick substitution in $value={{{ [<current>search-replace::regexp<existing>,[]] }}} />
, or the behaviour of the $value={{{ [<current>!match[]] [<new>] +[join[, ]] }}} />
line?
I’m not always able to reproduce it, unfortunately, that’s why I’m not entirely sure how/when it happens. It may be around acting on the first or last mod
of the list. I’m trying to figure it out right now.
It occurs when you add a first mod, then a second, then remove the second and re-add it.
- in fact, when you add a first mod, then a second, then remove the second, the ", "
remains after the first:
- Adding a first mod:
- Adding a second mod:
- remove the second mod:
← here’s the culprit, I think
- Re-adding the second mod:
It seems to be that adding then removing the last mod of the list, the list then ends with ", "
rather than nothing, and ", "
remains there afterwards because there’s no blank mod and one can’t access it through the Select.
Adding and removing the last mod of the list several times: 
