From b6d4fb559070ce8b4be399a5f5ebccb6dbfe9489 Mon Sep 17 00:00:00 2001 From: BlakeNeko Date: Sun, 23 Nov 2025 11:28:45 +0800 Subject: [PATCH] feat: Add setting for trailing comma in auto-formatting --- web/js/auto-formatter.js | 4 ++-- web/js/main.js | 11 +++++++++++ web/js/settings.js | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/web/js/auto-formatter.js b/web/js/auto-formatter.js index a47fc01..b3e7a84 100644 --- a/web/js/auto-formatter.js +++ b/web/js/auto-formatter.js @@ -100,8 +100,8 @@ export function formatPromptText(text) { // Rejoin cleaned tags with ", " let formattedLine = cleanedTags.join(', '); - // Add a trailing comma and space if the line contains valid tags - if (formattedLine.length > 0) { + // Add a trailing comma and space if the setting is enabled and line contains valid tags + if (formattedLine.length > 0 && settingValues.addTrailingComma) { formattedLine += ', '; } diff --git a/web/js/main.js b/web/js/main.js index ad444a6..18da111 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -512,5 +512,16 @@ app.registerExtension({ settingValues.enableAutoFormat = newVal; }, }, + { + id: id + '.AutoFormatter.AddTrailingComma', + name: 'Add Trailing Comma', + tooltip: 'Add a comma at the end of each line when auto-formatting', + type: 'boolean', + defaultValue: false, + category: [name, 'AutoFormatter', 'Add Trailing Comma'], + onChange: (newVal, oldVal) => { + settingValues.addTrailingComma = newVal; + }, + }, ] }); \ No newline at end of file diff --git a/web/js/settings.js b/web/js/settings.js index 0cbc7b3..6351d2a 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -24,6 +24,7 @@ export const settingValues = { // Auto format settings enableAutoFormat: true, autoFormatTrigger: 'auto', // Options: 'auto' (format on blur + shortcut), 'manual' (shortcut only) + addTrailingComma: false, // Whether to add comma at the end of each line // Internal logic settings