fix array length check (#6320)

This commit is contained in:
Jack Kavanagh 2023-08-18 10:30:57 +02:00 committed by GitHub
parent f83ccbb36f
commit 32394fb8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,26 +34,27 @@ export function registerElectronHandlers() {
.sort((a, b) => fnOrString(a.templateTag.displayName).localeCompare(fnOrString(b.templateTag.displayName))) .sort((a, b) => fnOrString(a.templateTag.displayName).localeCompare(fnOrString(b.templateTag.displayName)))
.map(l => { .map(l => {
const actions = l.templateTag.args?.[0]; const actions = l.templateTag.args?.[0];
const otherArgs = l.templateTag.args?.slice(1); const additionalArgs = l.templateTag.args?.slice(1);
const hasSubmenu = actions?.options?.length; const hasSubmenu = actions?.options?.length;
return { return {
label: fnOrString(l.templateTag.displayName), label: fnOrString(l.templateTag.displayName),
...(hasSubmenu ? {} : { ...(!hasSubmenu ?
click: () => { {
const tag = `{% ${l.templateTag.name} ${l.templateTag.args?.map(getTemplateValue).join(', ')} %}`;
event.sender.send('context-menu-command', { key: options.key, tag });
},
}),
...(hasSubmenu ? {
submenu: actions?.options?.map(action => ({
label: fnOrString(action.displayName),
click: () => { click: () => {
const defaultTagArgs = otherArgs ? ', ' + otherArgs.map(getTemplateValue).join(', ') : ''; const tag = `{% ${l.templateTag.name} ${l.templateTag.args?.map(getTemplateValue).join(', ')} %}`;
const tag = `{% ${l.templateTag.name} '${action.value}'${defaultTagArgs} %}`;
event.sender.send('context-menu-command', { key: options.key, tag }); event.sender.send('context-menu-command', { key: options.key, tag });
}, },
})), } :
} : {}), {
submenu: actions?.options?.map(action => ({
label: fnOrString(action.displayName),
click: () => {
const additionalTagFields = additionalArgs.length ? ', ' + additionalArgs.map(getTemplateValue).join(', ') : '';
const tag = `{% ${l.templateTag.name} '${action.value}'${additionalTagFields} %}`;
event.sender.send('context-menu-command', { key: options.key, tag });
},
})),
}),
}; };
}), }),