implement #12
parent
8f6cfa6fc3
commit
92bbcf6c8e
|
|
@ -13,14 +13,15 @@ class LeFormatter {
|
||||||
* @param {boolean} dedupe
|
* @param {boolean} dedupe
|
||||||
* @param {boolean} removeUnderscore
|
* @param {boolean} removeUnderscore
|
||||||
* @param {boolean} autoRefresh
|
* @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');
|
const lines = textArea.value.split('\n');
|
||||||
|
|
||||||
for (let i = 0; i < lines.length; i++)
|
for (let i = 0; i < lines.length; i++)
|
||||||
lines[i] = this.#formatString(lines[i], dedupe, removeUnderscore);
|
lines[i] = this.#formatString(lines[i], dedupe, removeUnderscore);
|
||||||
|
|
||||||
textArea.value = lines.join('\n');
|
textArea.value = lines.join(appendComma ? ',\n' : '\n');
|
||||||
|
|
||||||
if (autoRefresh)
|
if (autoRefresh)
|
||||||
updateInput(textArea);
|
updateInput(textArea);
|
||||||
|
|
@ -148,13 +149,13 @@ onUiLoaded(() => {
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.altKey && e.shiftKey && e.code === 'KeyF') {
|
if (e.altKey && e.shiftKey && e.code === 'KeyF') {
|
||||||
e.preventDefault();
|
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(
|
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
|
config.autoRun, config.dedupe, config.removeUnderscore
|
||||||
);
|
);
|
||||||
|
|
@ -184,7 +185,7 @@ onUiLoaded(() => {
|
||||||
const button = document.getElementById(id);
|
const button = document.getElementById(id);
|
||||||
button?.addEventListener('click', () => {
|
button?.addEventListener('click', () => {
|
||||||
if (config.autoRun)
|
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));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ class LeFormatterConfig {
|
||||||
this.autoRun = this.#defaultAuto();
|
this.autoRun = this.#defaultAuto();
|
||||||
this.dedupe = this.#defaultDedupe();
|
this.dedupe = this.#defaultDedupe();
|
||||||
this.removeUnderscore = this.#defaultRemoveUnderscore();
|
this.removeUnderscore = this.#defaultRemoveUnderscore();
|
||||||
|
this.comma = this.#appendComma();
|
||||||
this.promptFields = this.#getPromptFields();
|
this.promptFields = this.#getPromptFields();
|
||||||
this.button = this.#createReloadButton();
|
this.button = this.#createReloadButton();
|
||||||
}
|
}
|
||||||
|
|
@ -33,6 +34,12 @@ class LeFormatterConfig {
|
||||||
return config.checked;
|
return config.checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @returns {boolean} */
|
||||||
|
#appendComma() {
|
||||||
|
const config = document.getElementById('setting_pf_appendcomma').querySelector('input[type=checkbox]');
|
||||||
|
return config.checked;
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Cache All Prompt Fields =====
|
// ===== Cache All Prompt Fields =====
|
||||||
/** @returns {HTMLTextAreaElement[]} */
|
/** @returns {HTMLTextAreaElement[]} */
|
||||||
#getPromptFields() {
|
#getPromptFields() {
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,12 @@ def on_settings():
|
||||||
"Disable automatic input updates",
|
"Disable automatic input updates",
|
||||||
section=section,
|
section=section,
|
||||||
category_id="system",
|
category_id="system",
|
||||||
).info(
|
).html(
|
||||||
"check this if you have Extensions, such as [tagcomplete], that subscribe to text editing event"
|
"""
|
||||||
|
<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(
|
opts.add_option(
|
||||||
"pf_exclusion",
|
"pf_exclusion",
|
||||||
OptionInfo(
|
OptionInfo(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue