earlSt1 / vtt-compendium-folders

Collapsable folders in the compendium directory and folder structures inside compendiums for FoundryVTT
21 stars 18 forks source link

Folder context options all being set to the same list #67

Closed schultzcole closed 3 years ago

schultzcole commented 3 years ago

In the setup hook, compendium folders adds a new context option to all folder types. However in doing so, it inadvertently sets all folders to have the same context menu options as the SceneDirectory due to the way it reuses the oldFn variable. If another module changes the SceneDirectory context menu, all of those changes propagate to folders for the other entity types as well.

Recommended fix:

    let oldActorFolderCtxOptions = ActorDirectory.prototype._getFolderContextOptions
    ActorDirectory.prototype._getFolderContextOptions = () => oldActorFolderCtxOptions().concat(newContextOption);

    let oldItemFolderCtxOptions = ItemDirectory.prototype._getFolderContextOptions
    ItemDirectory.prototype._getFolderContextOptions = () => oldItemFolderCtxOptions().concat(newContextOption);

    let oldJournalFolderCtxOptions = JournalDirectory.prototype._getFolderContextOptions
    JournalDirectory.prototype._getFolderContextOptions = () => oldJournalFolderCtxOptions().concat(newContextOption);

    let oldRollTableFolderCtxOptions = RollTableDirectory.prototype._getFolderContextOptions
    RollTableDirectory.prototype._getFolderContextOptions = () => oldRollTableFolderCtxOptions().concat(newContextOption);

    let oldSceneFolderCtxOptions = SceneDirectory.prototype._getFolderContextOptions
    SceneDirectory.prototype._getFolderContextOptions = () => oldSceneFolderCtxOptions().concat(newContextOption);
earlSt1 commented 3 years ago

Ah, thanks for pointing that out. I assumed reusing a variable like oldFn would be sufficient (thats my lack of javascript knowledge showing :smile:). I'll include your proposed fix in the next release.

earlSt1 commented 3 years ago

Tested and fixed in v2.2.41