Add 3-state find substitution select

Fixes #3104
This commit is contained in:
Cohee
2024-11-23 19:39:02 +02:00
parent 5515f28105
commit da42d0a47a
4 changed files with 32 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import { enumIcons } from '../../slash-commands/SlashCommandCommonEnumsProvider.
import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js';
import { download, getFileText, getSortableDelay, uuidv4 } from '../../utils.js';
import { regex_placement, runRegexScript } from './engine.js';
import { regex_placement, runRegexScript, substitute_find_regex } from './engine.js';
import { t } from '../../i18n.js';
/**
@ -227,7 +227,7 @@ async function onRegexEditorOpenClick(existingId, isScoped) {
editorHtml.find('input[name="only_format_display"]').prop('checked', existingScript.markdownOnly ?? false);
editorHtml.find('input[name="only_format_prompt"]').prop('checked', existingScript.promptOnly ?? false);
editorHtml.find('input[name="run_on_edit"]').prop('checked', existingScript.runOnEdit ?? false);
editorHtml.find('input[name="substitute_regex"]').prop('checked', existingScript.substituteRegex ?? false);
editorHtml.find('select[name="substitute_regex"]').val(existingScript.substituteRegex ?? substitute_find_regex.NONE);
editorHtml.find('input[name="min_depth"]').val(existingScript.minDepth ?? '');
editorHtml.find('input[name="max_depth"]').val(existingScript.maxDepth ?? '');
@ -267,7 +267,7 @@ async function onRegexEditorOpenClick(existingId, isScoped) {
findRegex: editorHtml.find('.find_regex').val(),
replaceString: editorHtml.find('.regex_replace_string').val(),
trimStrings: String(editorHtml.find('.regex_trim_strings').val()).split('\n').filter((e) => e.length !== 0) || [],
substituteRegex: editorHtml.find('input[name="substitute_regex"]').prop('checked'),
substituteRegex: Number(editorHtml.find('select[name="substitute_regex"]').val()),
};
const rawTestString = String(editorHtml.find('#regex_test_input').val());
const result = runRegexScript(testScript, rawTestString);
@ -295,7 +295,7 @@ async function onRegexEditorOpenClick(existingId, isScoped) {
markdownOnly: editorHtml.find('input[name="only_format_display"]').prop('checked'),
promptOnly: editorHtml.find('input[name="only_format_prompt"]').prop('checked'),
runOnEdit: editorHtml.find('input[name="run_on_edit"]').prop('checked'),
substituteRegex: editorHtml.find('input[name="substitute_regex"]').prop('checked'),
substituteRegex: Number(editorHtml.find('select[name="substitute_regex"]').val()),
minDepth: parseInt(String(editorHtml.find('input[name="min_depth"]').val())),
maxDepth: parseInt(String(editorHtml.find('input[name="max_depth"]').val())),
};