From bc4f34a99af922f5c720a35c8205805e1fe8d206 Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Thu, 15 May 2025 00:10:19 +0900 Subject: [PATCH] fix: Refine weight extraction logic in getCurrentTagRange to handle simple numbers correctly --- web/js/utils.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/web/js/utils.js b/web/js/utils.js index 79e376f..8dc0e79 100644 --- a/web/js/utils.js +++ b/web/js/utils.js @@ -311,18 +311,22 @@ export function getCurrentTagRange(text, cursorPos) { } // Rule 3: Exclude prompt strength syntax (e.g., ":1.0") but include colons in names. - // (e.g., "standing:1.0" -> "standing", "foo:bar" -> "foo:bar") + // (e.g., "standing:1.0" -> "standing", "foo:bar" -> "foo:bar", "year:2000" -> "year:2000") // This applies to the tag *after* parentheses are handled. - const weightRegex = /(.*?):(\d+(\.\d+)?)$/; + const weightRegex = /(.*?):([0-9](\.\d+)?)$/; const weightMatch = adjustedTag.match(weightRegex); if (weightMatch) { const tagPart = weightMatch[1]; - const fullWeightString = adjustedTag.substring(tagPart.length); - - if (tagPart.length > 0 || (tagPart.length === 0 && fullWeightString === adjustedTag)) { - adjustedEnd -= fullWeightString.length; - adjustedTag = tagPart; + const weightValue = weightMatch[2]; + // Only consider it as a weight if it's a simple number between 0-9 possibly with decimal + // Don't treat larger numbers like :1999 or :2000 as weights + if (parseFloat(weightValue) <= 9.9) { + const fullWeightString = adjustedTag.substring(tagPart.length); + if (tagPart.length > 0 || (tagPart.length === 0 && fullWeightString === adjustedTag)) { + adjustedEnd -= fullWeightString.length; + adjustedTag = tagPart; + } } }