PDA

View Full Version : Problem with stringcontrol and delaykeyupdate



SilentRuin
September 4th, 2021, 19:58
Ok somehow the backspace key is being treated as a loss of focus (and value changed) - even though the <delaykeyupdate> is set in <stringcontrol>. In fact, so is del key. If I key in characters it works as it should and does not trigger OnValueChanged call. But backspace and delete do trigger it - which is unexpected as until the string is "done editing" one does not expect the logic under the OnValueChanged to be triggered.

I never noticed this happening before - previously, at some point back in time, backspace to edit (remove) characters worked fine.

Moon Wizard
September 4th, 2021, 21:13
Do you have a specific example in the existing rulesets where it is doing this? Or a simple extension showing the issue?

Thanks,
JPG

SilentRuin
September 4th, 2021, 22:13
I tried to find a ruleset example but it appears my Combat Groups extension is the only thing using onValueChange functionality with the delaykeyupdate. Here is the specific ct_host.xml field that triggers it...



<stringcontrol name="EditCTGroup">
<anchored width="200" height="30">
<left parent="combatgroup_visible_button" anchor="right" offset="7" />
<bottom parent="combatgroup" anchor="bottom" offset="0" />
</anchored>
<tooltip textres="combatgroup_editctgroup_tooltip" />
<delaykeyupdate />
<font>sheettext</font>
<script>
function onInit()
CombatGroupsManager.InitEditCTGroup(window);
end
function onValueChanged()
CombatGroupsManager.EditCTGroupChanged(window);
end
function onDoubleClick()
return CombatGroupsManager.fitWindowToGroup(getValue());
end
</script>
<frame name="groupbox" offset="5,5,2,2" />
</stringcontrol>


I suspect simply adding onValueChanged() into ANY control that also uses <delaykeyupdate /> would show it being triggered on backspace/del keys but not any normal text keys. That is the issue - it triggers on backspace/del when I would think the <delaykeyupdate /> would have prevented it triggering until a return/tab key was hit or it lost focus.

SilentRuin
September 4th, 2021, 22:19
I have delivered a workaround to fake it into looking like its working. I preserve cursor position at start of onValueChanged processing and return it to original position when done, as some of the filter processing it triggers will reset the cursor position in the field (as it is processed when I'm still actually editing it - i.e. removing and adding characters).

Moon Wizard
September 4th, 2021, 22:48
Anything that changes a block of text will trigger a full value change event (copy/paste, etc.). Since backspace and delete can be used to delete blocks of text (if selected); then they generate that event.

Regards,
JPG

SilentRuin
September 5th, 2021, 15:15
Anything that changes a block of text will trigger a full value change event (copy/paste, etc.). Since backspace and delete can be used to delete blocks of text (if selected); then they generate that event.

Regards,
JPG

Typically keywords that block processing until the edit is complete don't trigger on anything but return/tab or loss of focus. While I can see block processing triggering a change of focus - simply adding and removing characters (part of the editing process) should not. However, I've worked around it from a visual perspective - if not an actual don't process till done perspective.

Moon Wizard
September 5th, 2021, 18:59
As far as I remember, the code was migrated from FGC, so it didn't make sense to change it and possibly break other code.

JPG