prevent inject on auto-execute

This commit is contained in:
LenAnderson 2024-01-01 23:08:18 +00:00
parent 473326b3fb
commit 70d6e6d37f
3 changed files with 5 additions and 5 deletions

View File

@ -28,7 +28,7 @@ export class AutoExecuteHandler {
for (const qr of qrList) { for (const qr of qrList) {
this.preventAutoExecuteStack.push(qr.preventAutoExecute); this.preventAutoExecuteStack.push(qr.preventAutoExecute);
try { try {
await qr.onExecute(); await qr.execute({ isAutoExecute:true });
} catch (ex) { } catch (ex) {
warn(ex); warn(ex);
} finally { } finally {

View File

@ -464,7 +464,7 @@ export class QuickReply {
const message = this.message.replace(/\{\{arg::([^}]+)\}\}/g, (_, key) => { const message = this.message.replace(/\{\{arg::([^}]+)\}\}/g, (_, key) => {
return args[key] ?? ''; return args[key] ?? '';
}); });
this.onExecute(this, message); this.onExecute(this, message, args.isAutoExecute ?? false);
} }
} }

View File

@ -103,12 +103,12 @@ export class QuickReplySet {
* @param {QuickReply} qr * @param {QuickReply} qr
* @param {String} [message] - optional altered message to be used * @param {String} [message] - optional altered message to be used
*/ */
async execute(qr, message = null) { async execute(qr, message = null, isAutoExecute = false) {
/**@type {HTMLTextAreaElement}*/ /**@type {HTMLTextAreaElement}*/
const ta = document.querySelector('#send_textarea'); const ta = document.querySelector('#send_textarea');
const finalMessage = message ?? qr.message; const finalMessage = message ?? qr.message;
let input = ta.value; let input = ta.value;
if (this.injectInput && input.length > 0) { if (!isAutoExecute && this.injectInput && input.length > 0) {
if (this.placeBeforeInput) { if (this.placeBeforeInput) {
input = `${finalMessage} ${input}`; input = `${finalMessage} ${input}`;
} else { } else {
@ -152,7 +152,7 @@ export class QuickReplySet {
} }
hookQuickReply(qr) { hookQuickReply(qr) {
qr.onExecute = (_, message)=>this.execute(qr, message); qr.onExecute = (_, message, isAutoExecute)=>this.execute(qr, message, isAutoExecute);
qr.onDelete = ()=>this.removeQuickReply(qr); qr.onDelete = ()=>this.removeQuickReply(qr);
qr.onUpdate = ()=>this.save(); qr.onUpdate = ()=>this.save();
} }