windingwind / zotero-actions-tags

Customize your Zotero workflow.
GNU Affero General Public License v3.0
1.94k stars 48 forks source link

[Bug] In script mode, sometimes the selected item is given null. #324

Closed 454116278 closed 6 months ago

454116278 commented 6 months ago

Is there an existing issue for this?

Are you using the latest Zotero and the latest plugin?

Environment

Describe the bug

see the code from line 195 in actions.ts.

async function applyAction(action: ActionData, args: ActionArgs) { const item = (Zotero.Items.get(args.itemID || -1) as Zotero.Item | false) || null; // If the item is not found and the operation is not script, early return. if (action.operation !== ActionOperationTypes.script && !item) { return false; }

// if operation == script and item == null ,here dont return false. // please check it is right or not.

Debug Output

I always get item == null in my script.

Anything else?

No response

454116278 commented 6 months ago

image const now = new Date(); if(!item) return ${now} 空条目出现;

454116278 commented 6 months ago

I have debugged the codes, find out the dispatchActionByKey is called twice. // await addon.api.actionManager.dispatchActionByKey(key, { // itemIDs, // collectionID: collection?.id, // triggerType: "menu", // }); // Trigger action for each item for (const itemID of itemIDs) { await addon.api.actionManager.dispatchActionByKey(key, { itemID, collectionID: collection?.id, triggerType: "menu", }); }