diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js index 2af58f5..a6fbdb9 100644 --- a/javascript/prompt_format.js +++ b/javascript/prompt_format.js @@ -13,14 +13,15 @@ class LeFormatter { * @param {boolean} dedupe * @param {boolean} removeUnderscore * @param {boolean} autoRefresh + * @param {boolean} appendComma */ - static formatPipeline(textArea, dedupe, removeUnderscore, autoRefresh) { + static formatPipeline(textArea, dedupe, removeUnderscore, autoRefresh, appendComma) { const lines = textArea.value.split('\n'); for (let i = 0; i < lines.length; i++) lines[i] = this.#formatString(lines[i], dedupe, removeUnderscore); - textArea.value = lines.join('\n'); + textArea.value = lines.join(appendComma ? ',\n' : '\n'); if (autoRefresh) updateInput(textArea); @@ -148,13 +149,13 @@ onUiLoaded(() => { document.addEventListener('keydown', (e) => { if (e.altKey && e.shiftKey && e.code === 'KeyF') { e.preventDefault(); - config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, true)); + config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, true, config.comma)); } }); const formatter = LeFormatterUI.setupUIs( () => { - config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, true)); + config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, true, config.comma)); }, config.autoRun, config.dedupe, config.removeUnderscore ); @@ -184,7 +185,7 @@ onUiLoaded(() => { const button = document.getElementById(id); button?.addEventListener('click', () => { if (config.autoRun) - config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, config.refresh)); + config.promptFields.forEach((field) => LeFormatter.formatPipeline(field, config.dedupe, config.removeUnderscore, config.refresh, config.comma)); }); }); }); diff --git a/javascript/prompt_format_Configs.js b/javascript/prompt_format_Configs.js index fb46a1d..8322bbc 100644 --- a/javascript/prompt_format_Configs.js +++ b/javascript/prompt_format_Configs.js @@ -5,6 +5,7 @@ class LeFormatterConfig { this.autoRun = this.#defaultAuto(); this.dedupe = this.#defaultDedupe(); this.removeUnderscore = this.#defaultRemoveUnderscore(); + this.comma = this.#appendComma(); this.promptFields = this.#getPromptFields(); this.button = this.#createReloadButton(); } @@ -33,6 +34,12 @@ class LeFormatterConfig { return config.checked; } + /** @returns {boolean} */ + #appendComma() { + const config = document.getElementById('setting_pf_appendcomma').querySelector('input[type=checkbox]'); + return config.checked; + } + // ===== Cache All Prompt Fields ===== /** @returns {HTMLTextAreaElement[]} */ #getPromptFields() { diff --git a/scripts/pf_settings.py b/scripts/pf_settings.py index 3513bf4..21b1578 100644 --- a/scripts/pf_settings.py +++ b/scripts/pf_settings.py @@ -14,8 +14,12 @@ def on_settings(): "Disable automatic input updates", section=section, category_id="system", - ).info( - "check this if you have Extensions, such as [tagcomplete], that subscribe to text editing event" + ).html( + """ + (enable this if you have Extension, + such as tagcomplete, + that subscribes to text editing event) + """ ), ) @@ -44,6 +48,16 @@ def on_settings(): ), ) + opts.add_option( + "pf_appendcomma", + OptionInfo( + True, + "Append a comma at the end of a line", + section=section, + category_id="system", + ).info("only active when there are more than one line"), + ) + opts.add_option( "pf_exclusion", OptionInfo(