orcnog / autocomplete-whisper

Foundry VTT module to enhance chat whisper targeting with typeahead suggestions
GNU General Public License v3.0
4 stars 2 forks source link

Compatibility with DSA5 #37

Closed Danii0206 closed 1 year ago

Danii0206 commented 3 years ago

Hello,

this module makes all rolls from the chat roll 2 times when the system "Das Schwarze Auge/The Dark Eye (5th Edition)" is used. Can you please have a look?

Kind regards Danii

Rahjenaos commented 3 years ago

it also duplicates chat messages (including whispering)

Rahjenaos commented 3 years ago

could this maybe help? https://github.com/League-of-Foundry-Developers/Chat-Commands-Lib/issues/7#issuecomment-808924890

Danii0206 commented 3 years ago

I don't know in which file and where to put that. Can you help?

orcnog commented 3 years ago

I've spoken with @cswendrowski about a possible change to core that could solve this for everyone, provided we all follow up by altering our own code to leverage that change.

You can view the issue I created here: https://gitlab.com/foundrynet/foundryvtt/-/issues/5300

If this gets implemented, I'll fix autocomplete whisper so that it's not breaking any other modules competing for this same keybind... Chat-Commands-Lib and DSA5 need to do their part as well.

DJ4ddi commented 3 years ago

Running into similar issues with my own system.

This does not require a namespace (or other adjustments) to fix. The "recommended" way (in quotation marks because StackOverflow is not a universal truth) is to bind your event handler as the first one and then use regular event propagation.

Example code:

function onFirst(element, eventName, selector, eventHandler) {
    element.on(eventName, selector, eventHandler);

    let handlers = jQuery._data(element[0]).events[eventName.split('.')[0]];
    handlers.unshift(handlers.pop());
    return element;
}

// Instead of unbinding the original handler...
// $("#chat-message").off("keydown");
// $("#chat-message").on("keydown.menufocus", jumpToMenuHandler);

// ...make sure that the new one runs first:
onFirst($("#chat-message"), "keydown.menufocus", jumpToMenuHandler);

You can then use return false in your handler to prevent propagation and return true/return to propagate normally.

orcnog commented 2 years ago

THIS is the solution. Right here. CC: @cswendrowski

This is precisely how I wanted it to function when I first developed this module, but couldn't figure out how. I have now tested this solution with my module in DSA (and D&D5e) and while running Library: Chat Commands, and it appears to work in all scenarios. Can't thank you enough for finding this perfect solution.

Side note, I know this ain't exactly a timely response here. My apologies. I've been very busy but I don't know how I missed this comment for nearly a year.

Thanks again. Awesome solution @DJ4ddi.