bmarian / token-tooltip-alt

A module that adds a tooltip next to the currently hovered token to show some useful information for players and DMs.
MIT License
9 stars 15 forks source link

Fix for token tooltips not being shown when ALT is held #112

Open operation404 opened 1 year ago

operation404 commented 1 year ago

It seems this module relied on the 'hoverToken' hook to show all visible tokens' tooltips when ALT was held because that would also cause Foundry to highlight all visible tokens and when doing so considered those tokens hovered, and so the hoverToken hook was called. But it seems at some point Foundry v10 either added a new hook 'refreshToken' or started to use it instead of hoverToken whenever ALT was held down to highlight tokens, causing the handler for this module to not be called and no tooltips to be show. I simply added the original hoverToken handler to the refreshToken hook as well, so it is once again called when the ALT key is pressed.

I also noticed from a console warning that a line of code was still using 'token.data' as an accessor which v10 marks as deprecated, so that has been changed to 'token.document'.

operation404 commented 1 year ago

I've noted that with some testing this band-aid solution doesn't seem to be perfect, as there are some times refreshToken is called and even when ALT is not held and the token is not hovered it will render the tooltips. An example of this is when a group of tokens is selected by dragging a box over them, the tooltip will render for each selected token even if not hovered and ALT is not held. I'm not sure if they are intended to be considered as hovered or not.

bmarian commented 1 year ago

Thank you for the fix, I will investigate it as soon as I have some free time

operation404 commented 1 year ago

I added a dedicated handler for refreshToken, if alt is held during the call handler the tooltip is rendered, otherwise it is removed.

It's not perfect but it at least doesn't seem to render tooltips when it shouldn't anymore. But it does appear that if a token is hovered then alt is pressed and released, the tooltip is removed even if the token is still hovered. I'm not sure if this is intended behavior or not, but it is a fairly minor inconvenience as well.

Testbaby02 commented 1 year ago

There is an issue with the way the new handler registered for refreshToken behaves in v11 (I have not tested any earlier version of foundry), which prevents the tooltip from displaying when hovered normally. Adding in OR to the altHeldRenderTooltip condition a check on token._isHoverIn fixes this. What happens is that the refreshTokencall fires even when a token is hovered in, AFTER the hoverTokencall. This means that the tooltip will be drawn by hoverToken, and then deleted by refreshToken. This edit prevents that.