@@ -7,21 +7,18 @@ import { NodeInfo } from './node-info.js';
77 *
88 * Format conditions:
99 * 1. Skip formatting if node is in blocklist
10- * 2. Skip formatting if text contains only numbers or single letters (separated by commas)
11- * 3. Format if text contains "word + comma" pattern at least twice
12- * 4. Otherwise, don't format
10+ * 2. If text is empty after trimming, format only if trimSurroundingSpaces is enabled, otherwise don't format
11+ * 3. Skip formatting if text contains only numbers or single letters (separated by commas)
12+ * 4. Format if text contains "word + comma" pattern
13+ * 5. Format if trimSurroundingSpaces is enabled and there are surrounding spaces or line breaks
14+ * 6. Otherwise, don't format
1315 *
1416 * @param {NodeInfo } nodeInfo - The node information.
1517 * @returns {boolean } - True if the text should be formatted, false otherwise.
1618 */
1719function shouldAutoFormat ( text , nodeInfo ) {
1820 if ( ! text ) return false ;
1921
20- // If trimSurroundingSpaces is enabled and there are surrounding spaces, return true to format
21- if ( settingValues . trimSurroundingSpaces && text !== text . trim ( ) ) return true ;
22-
23- if ( text . trim ( ) . length === 0 ) return false ;
24-
2522 // 1. Check if the node name is in the blocklist
2623 const blocklist = [
2724 [ "Power Puter (rgthree)" , "code" ] ,
@@ -39,10 +36,14 @@ function shouldAutoFormat(text, nodeInfo) {
3936 // console.debug(`[Autocomplete-Plus] auto-formatter on blur => nodeType: ${nodeInfo.nodeType}, inputName: ${nodeInfo.inputName}`);
4037 }
4138
42-
4339 const trimmedText = text . trim ( ) ;
4440
45- // 2. Check if the text is purely numeric data or single-letter placeholders with commas
41+ // 2. Check if the text is completely empty after trimming
42+ if ( trimmedText . length === 0 ) {
43+ return settingValues . trimSurroundingSpaces ;
44+ }
45+
46+ // 3. Check if the text is purely numeric data or single-letter placeholders with commas
4647 // (e.g., "0,0,0,1,1,1" or "0.5, -1.2, 0.8" or "A,B,R" for LoRA Block Weight)
4748 const elements = trimmedText . split ( ',' ) . map ( el => el . trim ( ) ) ;
4849 const isSingleLetterOrNumeric = elements . every ( el => {
@@ -55,15 +56,18 @@ function shouldAutoFormat(text, nodeInfo) {
5556 return false ; // Don't format numeric data or single-letter template patterns
5657 }
5758
58- // 3. Check if the text contains the pattern "word + comma"
59+ // 4. If text contains "word + comma" pattern, format it
5960 const wordCommaPattern = / \w + \s * , / g;
60- const matches = trimmedText . match ( wordCommaPattern ) ;
61-
62- if ( matches == null ) {
63- return false ;
61+ if ( trimmedText . match ( wordCommaPattern ) ) {
62+ return true ;
6463 }
6564
66- return true ; // Text should be formatted
65+ // 5. If trimSurroundingSpaces is enabled and there are surrounding spaces, format to trim them
66+ if ( settingValues . trimSurroundingSpaces && text !== trimmedText ) {
67+ return true ;
68+ }
69+
70+ return false ; // Otherwise, don't format
6771}
6872
6973/**
0 commit comments