From 55fa31b14489fd422c31bcc6222951d54db7cdbb Mon Sep 17 00:00:00 2001 From: Will Miao Date: Tue, 27 Jan 2026 14:29:53 +0800 Subject: [PATCH] fix(autocomplete): preserve space after comma when inserting / commands --- web/comfyui/autocomplete.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/comfyui/autocomplete.js b/web/comfyui/autocomplete.js index e92d6212..3ef29925 100644 --- a/web/comfyui/autocomplete.js +++ b/web/comfyui/autocomplete.js @@ -738,8 +738,16 @@ class AutoComplete { // Find the start of the current command being typed const beforeCursor = currentValue.substring(0, caretPos); const segments = beforeCursor.split(/[,\>]+/); - const lastSegment = segments[segments.length - 1]; - const commandStartPos = caretPos - lastSegment.length; + const lastSegment = segments[segments.length - 1] || ''; + let commandStartPos = caretPos - lastSegment.length; + + // Preserve leading space if the last segment starts with a space + // This handles cases like "1girl, /character" where we want to keep the space + // after the comma instead of replacing it + if (lastSegment.length > 0 && lastSegment[0] === ' ') { + // Move start position past the leading space to preserve it + commandStartPos = commandStartPos + 1; + } // Insert command with trailing space const insertText = command + ' ';