feat: Apply preset regexes before scoped regexes + avoid unnecessary popping up (#4672) * feat: apply preset regexes before scoped regexes * feat: apply preset regexes before scoped regexes for debugger list * fix: don't notify reload regexes when save preset through ui button * docs: add comment for SCRIPT_TYPES order * fix: updatePreset is wrongly reset preset

4bda4444e47640788ea72d7d18aece9940f86397

StageDog <aksanajw845@gmail.com>

Signed
6 files changed, +47 -44Showing whitespace changes
public/scripts/extensions/regex/dropdown.html+23 -23
@@ -12,14 +12,14 @@
1212 <i class="fa-solid fa-pen-to-square"></i>
1313 <small data-i18n="ext_regex_new_global_script">+ Global</small>
1414 </div>
15- <div id="open_scoped_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_scoped_script_desc" title="New scoped regex script">
16- <i class="fa-solid fa-address-card"></i>
17- <small data-i18n="ext_regex_new_scoped_script">+ Scoped</small>
18- </div>
1915 <div id="open_preset_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_preset_script_desc" title="New preset regex script">
2016 <i class="fa-solid fa-sliders"></i>
2117 <small data-i18n="ext_regex_new_preset_script">+ Preset</small>
2218 </div>
19+ <div id="open_scoped_editor" class="menu_button menu_button_icon" data-i18n="[title]ext_regex_new_scoped_script_desc" title="New scoped regex script">
20+ <i class="fa-solid fa-address-card"></i>
21+ <small data-i18n="ext_regex_new_scoped_script">+ Scoped</small>
22+ </div>
2323 <div id="import_regex" class="menu_button menu_button_icon">
2424 <i class="fa-solid fa-file-import"></i>
2525 <small data-i18n="ext_regex_import_script">Import</small>
@@ -52,14 +52,14 @@
5252 <i class="fa-solid fa-globe"></i>
5353 <small data-i18n="ext_regex_move_to_global">Move to global scripts</small>
5454 </div>
55- <div id="bulk_regex_move_to_scoped" class="menu_button menu_button_icon" hidden>
56- <i class="fa-solid fa-address-card"></i>
57- <small data-i18n="ext_regex_move_to_scoped">Move to scoped scripts</small>
58- </div>
5955 <div id="bulk_regex_move_to_preset" class="menu_button menu_button_icon" hidden>
6056 <i class="fa-solid fa-sliders"></i>
6157 <small data-i18n="ext_regex_move_to_preset">Move to preset scripts</small>
6258 </div>
59+ <div id="bulk_regex_move_to_scoped" class="menu_button menu_button_icon" hidden>
60+ <i class="fa-solid fa-address-card"></i>
61+ <small data-i18n="ext_regex_move_to_scoped">Move to scoped scripts</small>
62+ </div>
6363 <div id="bulk_export_regex" class="menu_button menu_button_icon">
6464 <i class="fa-solid fa-file-export"></i>
6565 <small data-i18n="Export">Export</small>
@@ -96,6 +96,21 @@
9696 <div id="saved_regex_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div>
9797 </div>
9898 <hr />
99+ <div id="preset_scripts_block">
100+ <div class="flex-container alignItemsBaseline">
101+ <strong class="flex1" data-i18n="ext_regex_preset_scripts">Preset Scripts</strong>
102+ <label id="toggle_preset_regex" class="checkbox flex-container" for="regex_preset_toggle">
103+ <input type="checkbox" id="regex_preset_toggle" class="enable_scoped" />
104+ <span class="regex-toggle-on fa-solid fa-toggle-on fa-lg" data-i18n="[title]ext_regex_disallow_preset" title="Disallow using preset regex"></span>
105+ <span class="regex-toggle-off fa-solid fa-toggle-off fa-lg" data-i18n="[title]ext_regex_allow_preset" title="Allow using preset regex"></span>
106+ </label>
107+ </div>
108+ <small data-i18n="ext_regex_preset_scripts_desc">
109+ Only available for this preset. Saved to the preset data.
110+ </small>
111+ <div id="saved_preset_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div>
112+ </div>
113+ <hr />
99114 <div id="scoped_scripts_block">
100115 <div class="flex-container alignItemsBaseline">
101116 <strong class="flex1" data-i18n="ext_regex_scoped_scripts">Scoped Scripts</strong>
@@ -110,21 +125,6 @@
110125 </small>
111126 <div id="saved_scoped_scripts" no-scripts-text="No scripts found" data-i18n="[no-scripts-text]No scripts found" class="flex-container regex-script-container flexFlowColumn"></div>
112127 </div>
113- <hr />
114- <div id="preset_scripts_block">
115- <div class="flex-container alignItemsBaseline">
116- <strong class="flex1" data-i18n="ext_regex_preset_scripts">Preset Scripts</strong>
117- <label id="toggle_preset_regex" class="checkbox flex-container" for="regex_preset_toggle">
118- <input type="checkbox" id="regex_preset_toggle" class="enable_scoped" />
119- <span class="regex-toggle-on fa-solid fa-toggle-on fa-lg" data-i18n="[title]ext_regex_disallow_preset" title="Disallow using preset regex"></span>
120- <span class="regex-toggle-off fa-solid fa-toggle-off fa-lg" data-i18n="[title]ext_regex_allow_preset" title="Allow using preset regex"></span>
121- </label>
122- </div>
123- <small data-i18n="ext_regex_preset_scripts_desc">
124- Only available for this preset. Saved to the preset data.
125- </small>
126- <div id="saved_preset_scripts" class="flex-container regex-script-container flexFlowColumn"></div>
127- </div>
128128 </div>
129129 </div>
130130</div>
public/scripts/extensions/regex/engine.js+2 -1
@@ -9,9 +9,10 @@ import { lodash } from '../../../lib.js';
99 * @readonly
1010 */
1111export const SCRIPT_TYPES = {
12+ // ORDER MATTERS: defines the regex script priority
1213 GLOBAL: 0,
13- SCOPED: 1,
1414 PRESET: 2,
15+ SCOPED: 1,
1516};
1617
1718/**
public/scripts/extensions/regex/index.js+8 -8
@@ -1088,7 +1088,7 @@ function populateDebuggerRuleList(container) {
10881088 }
10891089 });
10901090
10911091 container.data('allScripts', [...globalScripts, ...scopedScriptspresetScripts, ...presetScriptsscopedScripts]);
10921092
10931093 const renderRule = (script) => {
10941094 if (!script.id) script.id = uuidv4();
@@ -1147,19 +1147,19 @@ function populateDebuggerRuleList(container) {
11471147 rulesContainer.append(globalList);
11481148 }
11491149
1150- if (scopedScripts.length > 0) {
1151- rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Scoped Rules` + '</div>');
1152- const scopedList = $('<ul id="regex_debugger_rules_scoped" class="sortable-list"></ul>');
1153- scopedScripts.forEach(script => scopedList.append(renderRule(script)));
1154- rulesContainer.append(scopedList);
1155- }
1156-
11571150 if (presetScripts.length > 0) {
11581151 rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Preset Rules` + '</div>');
11591152 const presetList = $('<ul id="regex_debugger_rules_preset" class="sortable-list"></ul>');
11601153 presetScripts.forEach(script => presetList.append(renderRule(script)));
11611154 rulesContainer.append(presetList);
11621155 }
1156+
1157+ if (scopedScripts.length > 0) {
1158+ rulesContainer.append('<div class="list-header regex-debugger-list-header">' + t`Scoped Rules` + '</div>');
1159+ const scopedList = $('<ul id="regex_debugger_rules_scoped" class="sortable-list"></ul>');
1160+ scopedScripts.forEach(script => scopedList.append(renderRule(script)));
1161+ rulesContainer.append(scopedList);
1162+ }
11631163}
11641164
11651165/**
public/scripts/extensions/regex/scriptTemplate.html+3 -3
@@ -16,12 +16,12 @@
1616 <div class="move_to_global menu_button" data-i18n="[title]ext_regex_move_to_global" title="Move to global scripts">
1717 <i class="fa-solid fa-globe"></i>
1818 </div>
19- <div class="move_to_scoped menu_button" data-i18n="[title]ext_regex_move_to_scoped" title="Move to scoped scripts">
20- <i class="fa-solid fa-address-card"></i>
21- </div>
2219 <div class="move_to_preset menu_button" data-i18n="[title]ext_regex_move_to_preset" title="Move to preset scripts">
2320 <i class="fa-solid fa-sliders"></i>
2421 </div>
22+ <div class="move_to_scoped menu_button" data-i18n="[title]ext_regex_move_to_scoped" title="Move to scoped scripts">
23+ <i class="fa-solid fa-address-card"></i>
24+ </div>
2525 <div class="export_regex menu_button" data-i18n="[title]ext_regex_export_script" title="Export script">
2626 <i class="fa-solid fa-file-export"></i>
2727 </div>
public/scripts/openai.js+1 -1
@@ -6275,7 +6275,7 @@ export function initOpenAI() {
62756275
62766276 $('#update_oai_preset').on('click', async function () {
62776277 const name = oai_settings.preset_settings_openai;
62786278 await saveOpenAIPreset(name, oai_settings, false);
62796279 toastr.success(t`Preset updated`);
62806280 });
62816281
public/scripts/preset-manager.js+10 -8
@@ -19,12 +19,14 @@ import {
1919 this_chid,
2020} from '../script.js';
2121import { groups, selected_group } from './group-chats.js';
22+import { t } from './i18n.js';
2223import { instruct_presets } from './instruct-mode.js';
2324import { kai_settings } from './kai-settings.js';
2425import { convertNovelPreset } from './nai-settings.js';
2526import { openai_settingsoai_settings, openai_setting_names, oai_settingsopenai_settings } from './openai.js';
2627import { Popup, POPUP_RESULT, POPUP_TYPE, Popup } from './popup.js';
2728import { context_presets, getContextSettings, power_user } from './power-user.js';
29+import { reasoning_templates } from './reasoning.js';
2830import { SlashCommand } from './slash-commands/SlashCommand.js';
2931import { ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js';
3032import { enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
@@ -33,13 +35,11 @@ import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
3335import { checkForSystemPromptInInstructTemplate, system_prompts } from './sysprompt.js';
3436import { renderTemplateAsync } from './templates.js';
3537import {
38+ textgenerationwebui_settings as textgen_settings,
3639 textgenerationwebui_preset_names,
3740 textgenerationwebui_presets,
38- textgenerationwebui_settings as textgen_settings,
3941} from './textgen-settings.js';
4042import { download, ensurePlainObject, equalsIgnoreCaseAndAccents, getSanitizedFilename, parseJsonFile, waitUntilCondition } from './utils.js';
41-import { t } from './i18n.js';
42-import { reasoning_templates } from './reasoning.js';
4343
4444const presetManagers = {};
4545
@@ -397,8 +397,10 @@ class PresetManager {
397397
398398 /**
399399 * Updates the preset select element with the current API presets.
400+ * @param {object} [options] Options for saving the preset
401+ * @param {boolean} [options.skipUpdate=false] If true, skips updating the preset list after saving.
400402 */
401403 async updatePreset(option = { skipUpdate: false }) {
402404 const selected = $(this.select).find('option:selected');
403405 console.log(selected);
404406
@@ -408,7 +410,7 @@ class PresetManager {
408410 }
409411
410412 const name = selected.text();
411413 await this.savePreset(name, null, option);
412414
413415 const successToast = !this.isAdvancedFormatting() ? t`Preset updated` : t`Template updated`;
414416 toastr.success(successToast);
@@ -1000,7 +1002,7 @@ export async function initPresetManager() {
10001002 return;
10011003 }
10021004
10031005 await presetManager.updatePreset({ skipUpdate: true });
10041006 });
10051007
10061008 $(document).on('click', '[data-preset-manager-new]', async function () {