main
Haoming 2024-09-25 09:36:33 +08:00
parent 8f6cfa6fc3
commit 92bbcf6c8e
3 changed files with 29 additions and 7 deletions

View File

@ -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));
});
});
});

View File

@ -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() {

View File

@ -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(
"""
<span class='info'>(enable this if you have Extension,
such as <a href="https://github.com/DominikDoom/a1111-sd-webui-tagcomplete">tagcomplete</a>,
that subscribes to text editing event)</span>
"""
),
)
@ -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(