Make Run on edit actually work Fixes #2958

9e50ff34c99e3d405897e2df0d13fb19a01047dd

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +12 -4Showing whitespace changes
public/script.js+4 -1
@@ -6798,7 +6798,10 @@ function updateMessage(div) {
67986798 text = getRegexedString(
67996799 text,
68006800 regexPlacement,
6801- { characterOverride: mes.extra?.type === 'narrator' ? undefined : mes.name },
6801+ {
6802+ characterOverride: mes.extra?.type === 'narrator' ? undefined : mes.name,
6803+ isEdit: true,
6804+ },
68026805 );
68036806
68046807
public/scripts/extensions/regex/editor.html+1 -1
@@ -117,7 +117,7 @@
117117 <input type="checkbox" name="disabled" />
118118 <span data-i18n="Disabled">Disabled</span>
119119 </label>
120- <label class="checkbox flex-container">
120+ <label class="checkbox flex-container" title="Run the regex script when the message belonging a to specified role(s) is edited.">
121121 <input type="checkbox" name="run_on_edit" />
122122 <span data-i18n="Run On Edit">Run On Edit</span>
123123 </label>
public/scripts/extensions/regex/engine.js+7 -2
@@ -44,9 +44,9 @@ function getScopedRegex() {
4444 * @param {regex_placement} placement The placement of the string
4545 * @param {RegexParams} params The parameters to use for the regex script
4646 * @returns {string} The regexed string
4747 * @typedef {{characterOverride?: string, isMarkdown?: boolean, isPrompt?: boolean, isEdit?: boolean, depth?: number }} RegexParams The parameters to use for the regex script
4848 */
4949function getRegexedString(rawString, placement, { characterOverride, isMarkdown, isPrompt, isEdit, depth } = {}) {
5050 // WTF have you passed me?
5151 if (typeof rawString !== 'string') {
5252 console.warn('getRegexedString: rawString is not a string. Returning empty string.');
@@ -68,6 +68,11 @@ function getRegexedString(rawString, placement, { characterOverride, isMarkdown,
6868 // Script applies to all cases when neither "only"s are true, but there's no need to do it when `isMarkdown`, the as source (chat history) should already be changed beforehand
6969 (!script.markdownOnly && !script.promptOnly && !isMarkdown)
7070 ) {
71+ if (isEdit && !script.runOnEdit) {
72+ console.debug(`getRegexedString: Skipping script ${script.scriptName} because it does not run on edit`);
73+ return;
74+ }
75+
7176 // Check if the depth is within the min/max depth
7277 if (typeof depth === 'number' && depth >= 0) {
7378 if (!isNaN(script.minDepth) && script.minDepth !== null && script.minDepth >= 0 && depth < script.minDepth) {