From aaa8db607d7ed1841a28b75fd3dcccec46a028c4 Mon Sep 17 00:00:00 2001 From: dingyongliang Date: Fri, 27 Oct 2023 11:27:40 +0800 Subject: [PATCH] * refactor updatePromptPreview. --- module/ai/js/configuredminiprogram.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/module/ai/js/configuredminiprogram.js b/module/ai/js/configuredminiprogram.js index ea470a3b4b..c6cb8a7d2b 100644 --- a/module/ai/js/configuredminiprogram.js +++ b/module/ai/js/configuredminiprogram.js @@ -450,7 +450,6 @@ function formatContent(content) */ function updatePromptPreview() { - const regex = /<([^>]+)><\/strong> /g; const innerText = $('#autocomplete-textarea').text(); let innerHTML = formatContent(innerText); if(typeof innerHTML === 'string') @@ -463,18 +462,18 @@ function updatePromptPreview() return; } + const regex = /<([^>]+)><\/strong> /g; const matches = innerHTML.match(regex); if(!matches) return; - for(let i = 0; i < matches.length; i++) + matches.forEach((match) => { - const execArr = regex.exec(innerHTML); - const result = execArr[1]; + const result = match.match(/<([^>]+)><\/strong> /)[1]; const fieldIndex = words.get(result); const fieldValue = $(`.field-content [data-id="${fieldIndex}"] .field-type`).prop('value'); - if(!fieldValue) continue; + if(!fieldValue) return; innerHTML = innerHTML.replace(new RegExp(`<${result}>`, 'g'), fieldValue); - } + }); innerHTML = innerHTML.replace(/ /g, ' ') .replace(/\s/g, '')