Regex: Fix markdown format bugs

If a regex cannot be parsed, silently return out and don't run the
script. May be a good idea to display a toast message saying the
script didn't run.

Also only reload the chat if a chat is actually loaded.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-07-05 15:08:03 -04:00
parent 13ba5cec49
commit 8212206d50
2 changed files with 25 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { callPopup, eventSource, event_types, reloadCurrentChat, saveSettingsDebounced } from "../../../script.js";
import { callPopup, eventSource, event_types, getCurrentChatId, reloadCurrentChat, saveSettingsDebounced } from "../../../script.js";
import { extension_settings } from "../../extensions.js";
import { uuidv4, waitUntilCondition } from "../../utils.js";
import { regex_placement } from "./engine.js";
@@ -50,7 +50,10 @@ async function saveRegexScript(regexScript, existingScriptIndex) {
// Markdown is global, so reload the chat.
if (regexScript.placement.includes(regex_placement.MD_DISPLAY)) {
await reloadCurrentChat();
const currentChatId = getCurrentChatId();
if (currentChatId !== undefined && currentChatId !== null) {
await reloadCurrentChat();
}
}
}