Make Run on edit actually work Fixes #2958
| @@ -6798,7 +6798,10 @@ function updateMessage(div) { | ||
| 6798 | 6798 | text = getRegexedString( |
| 6799 | 6799 | text, |
| 6800 | 6800 | regexPlacement, |
| 6801 | - { characterOverride: mes.extra?.type === 'narrator' ? undefined : mes.name }, | |
| 6801 | + { | |
| 6802 | + characterOverride: mes.extra?.type === 'narrator' ? undefined : mes.name, | |
| 6803 | + isEdit: true, | |
| 6804 | + }, | |
| 6802 | 6805 | ); |
| 6803 | 6806 | |
| 6804 | 6807 | |
| @@ -117,7 +117,7 @@ | ||
| 117 | 117 | <input type="checkbox" name="disabled" /> |
| 118 | 118 | <span data-i18n="Disabled">Disabled</span> |
| 119 | 119 | </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."> | |
| 121 | 121 | <input type="checkbox" name="run_on_edit" /> |
| 122 | 122 | <span data-i18n="Run On Edit">Run On Edit</span> |
| 123 | 123 | </label> |
| @@ -44,9 +44,9 @@ function getScopedRegex() { | ||
| 44 | 44 | * @param {regex_placement} placement The placement of the string |
| 45 | 45 | * @param {RegexParams} params The parameters to use for the regex script |
| 46 | 46 | * @returns {string} The regexed string |
| 47 | 47 | * @typedef {{characterOverride?: string, isMarkdown?: boolean, isPrompt?: boolean, isEdit?: boolean, depth?: number }} RegexParams The parameters to use for the regex script |
| 48 | 48 | */ |
| 49 | 49 | function getRegexedString(rawString, placement, { characterOverride, isMarkdown, isPrompt, isEdit, depth } = {}) { |
| 50 | 50 | // WTF have you passed me? |
| 51 | 51 | if (typeof rawString !== 'string') { |
| 52 | 52 | console.warn('getRegexedString: rawString is not a string. Returning empty string.'); |
| @@ -68,6 +68,11 @@ function getRegexedString(rawString, placement, { characterOverride, isMarkdown, | ||
| 68 | 68 | // 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 |
| 69 | 69 | (!script.markdownOnly && !script.promptOnly && !isMarkdown) |
| 70 | 70 | ) { |
| 71 | + if (isEdit && !script.runOnEdit) { | |
| 72 | + console.debug(`getRegexedString: Skipping script ${script.scriptName} because it does not run on edit`); | |
| 73 | + return; | |
| 74 | + } | |
| 75 | + | |
| 71 | 76 | // Check if the depth is within the min/max depth |
| 72 | 77 | if (typeof depth === 'number' && depth >= 0) { |
| 73 | 78 | if (!isNaN(script.minDepth) && script.minDepth !== null && script.minDepth >= 0 && depth < script.minDepth) { |