Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: onChangeSelection event in HTML5 can get triggered twice unnecessarily #5079

Open
Baaaaaz opened this issue Dec 1, 2024 · 1 comment
Labels

Comments

@Baaaaaz
Copy link

Baaaaaz commented Dec 1, 2024

Describe the Bug

If you change token selection to a single new unselected token by clicking on the token using the mouse left-hand button, the onChangeSelection event gets triggered twice: once on mouse left-hand button down and again on either mouse left-hand button up or mouse drag.

To Reproduce

  1. Create a blank campaign.
  2. Create some tokens, one being a lib token.
  3. Add the following macro to the lib token and run it:
[h, if(getSelected()==""): broadcast("NO TOKENS SELECTED") ; broadcast(getSelected())]
[h: oCS = macroLinkText(getMacroName() + "@" + getMacroLocation(), "none")]
[frame5("TEST"), code: {
	<head>
		<link rel='onChangeSelection' type='macro' href='[r: oCS]'>
	</head>
	<body>
		[r: getSelected())]
	</body>
}]
  1. Try selecting tokens as described in the bug description.
  2. Observe the triggering twice issue where the message is broadcasted on mouse down, and again on mouse up or mouse drag.

Expected Behaviour

onChangeSelection should only get fired the once in this scenario.

Screenshots

image

MapTool Info

1.15.2

Desktop

Windows 11

Additional Context

The name of the onChangeSelection event is a bit misleading, however the wiki does state that the event is fired when a token is selected (rather than when the token selection is actually changed!).

e.g. if you left mouse click on a single token that is also the sole currently selected token, onChangeSelection will also be triggered on left mouse up (i.e. unnecessarily as the selection has not effectively changed). Right mouse click on an already selected token does not trigger it. Similarly if no tokens are selected. and you left click somewhere else on the map (that is not a token), onChangeSelection is triggered but again the token selection has not effectively changed.

@Baaaaaz Baaaaaz added the bug label Dec 1, 2024
@cwisniew
Copy link
Member

cwisniew commented Dec 1, 2024

This is a documented issue with the onChangeSelection event, which may be called more than once on a change of selection and macro, so this needs to be taken into account. Or at least it used to be documented, but sometimes these warnings get removed from the Wiki. This is due to some internal tomfoolery that happens with how selection works and is never likely to be fixed for the current events

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants