From 29cb0dab7e9f2aaaa4c9ad4e10ac3ea1de12f84e Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Thu, 15 May 2025 03:48:19 +0900 Subject: [PATCH] fix: Enhance removePromptWeight function to better handle weights and preserve symbol-only tags --- web/js/utils.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/web/js/utils.js b/web/js/utils.js index 8dc0e79..919295e 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -80,16 +80,31 @@ export function unescapeParentheses(str) { /** * Removes prompt weights from a tag (e.g., "tag:1.2" becomes "tag"). + * Preserves tags with colons like "year:2000" or "foo:bar". + * Preserves symbol-only tags like ";)" or "^_^". * @param {string} str The input tag string. * @returns {string} The tag without weight and without surrounding non-escaped brackets. */ export function removePromptWeight(str) { if (!str) return str; - // First remove weight notation (e.g., ":1.2") - let result = str.replace(/(.+?):\d+(\.\d+)?/, '$1'); + // For symbol-only tags (no letters/numbers), return as-is + if (!isContainsLetterOrNumber(str)) { + return str; + } - // Then remove non-escaped brackets at the beginning and/or end + // Only remove weight notation for patterns that look like actual weights + // (e.g., ":1.2" where the number is between 0-9.9) + let result = str.replace(/(.+?):([0-9](\.\d+)?)$/, (match, p1, p2) => { + // If the number after colon is between 0-9.9, it's likely a weight + if (parseFloat(p2) <= 9.9) { + return p1; + } + // Otherwise preserve the entire string (like "year:2000") + return match; + }); + + // Only remove non-escaped brackets if the string contains letters or numbers // Use negative lookbehind (?