format on paste
parent
766ef48411
commit
dbccad2215
|
|
@ -25,6 +25,7 @@ Sometimes, when you type too fast or copy prompts from all over the places, you
|
||||||
- [x] Toggle between auto formatting and manual formatting
|
- [x] Toggle between auto formatting and manual formatting
|
||||||
- In `Auto` mode: The process is ran whenever you click on **Generate**
|
- In `Auto` mode: The process is ran whenever you click on **Generate**
|
||||||
- In `Manual` mode: The process is only ran when you click the **Format** button
|
- In `Manual` mode: The process is only ran when you click the **Format** button
|
||||||
|
- [x] **New:** Trigger the formatting when pasting text
|
||||||
- [x] Toggle whether the above features are enabled / disabled by default in the `Prompt Format` section under the <ins>System</ins> category of the **Settings** tab
|
- [x] Toggle whether the above features are enabled / disabled by default in the `Prompt Format` section under the <ins>System</ins> category of the **Settings** tab
|
||||||
- [x] Pressing `Alt` + `Shift` + `F` can also trigger formatting
|
- [x] Pressing `Alt` + `Shift` + `F` can also trigger formatting
|
||||||
- [x] Assign "[alias](#tag-alias)" that counts as duplicates for the specified tags
|
- [x] Assign "[alias](#tag-alias)" that counts as duplicates for the specified tags
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
- [x] 按下`Auto Format`以在手動與自動間切換
|
- [x] 按下`Auto Format`以在手動與自動間切換
|
||||||
- `自動`: 每次按下 **生成 (Generate)** 時處裡
|
- `自動`: 每次按下 **生成 (Generate)** 時處裡
|
||||||
- `手動`: 手動按下 **Format** 時才處裡
|
- `手動`: 手動按下 **Format** 時才處裡
|
||||||
|
- [x] **新功能:** 處裡貼上的咒語
|
||||||
- [x] 在 **Settings** 頁面 <ins>System</ins> 下的 `Prompt Format` 區可以 開啟/關閉 上述功能
|
- [x] 在 **Settings** 頁面 <ins>System</ins> 下的 `Prompt Format` 區可以 開啟/關閉 上述功能
|
||||||
- [x] 按下 `Alt` + `Shift` + `F` 亦可觸發格式化
|
- [x] 按下 `Alt` + `Shift` + `F` 亦可觸發格式化
|
||||||
- [x] 為指定單字新增 "[同義詞](#同義詞)"
|
- [x] 為指定單字新增 "[同義詞](#同義詞)"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ class pfConfigs {
|
||||||
this.dedupe = this.#defaultDedupe();
|
this.dedupe = this.#defaultDedupe();
|
||||||
this.removeUnderscore = this.#defaultRemoveUnderscore();
|
this.removeUnderscore = this.#defaultRemoveUnderscore();
|
||||||
this.comma = this.#appendComma();
|
this.comma = this.#appendComma();
|
||||||
|
this.paste = this.#onpaste();
|
||||||
this.promptFields = this.#getPromptFields();
|
this.promptFields = this.#getPromptFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,6 +40,12 @@ class pfConfigs {
|
||||||
return config.checked;
|
return config.checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @returns {boolean} */
|
||||||
|
#onpaste() {
|
||||||
|
const config = document.getElementById('setting_pf_onpaste').querySelector('input[type=checkbox]');
|
||||||
|
return config.checked;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache All Prompt Fields
|
* Cache All Prompt Fields
|
||||||
* @returns {HTMLTextAreaElement[]}
|
* @returns {HTMLTextAreaElement[]}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ class LeFormatter {
|
||||||
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);
|
||||||
|
|
||||||
if (!appendComma)
|
if (!appendComma)
|
||||||
textArea.value = lines.join('\n');
|
textArea.value = lines.join('\n');
|
||||||
|
|
@ -49,7 +49,7 @@ class LeFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param {string} input @param {boolean} dedupe @param {boolean} removeUnderscore @returns {string} */
|
/** @param {string} input @param {boolean} dedupe @param {boolean} removeUnderscore @returns {string} */
|
||||||
static #formatString(input, dedupe, removeUnderscore) {
|
static formatString(input, dedupe, removeUnderscore) {
|
||||||
|
|
||||||
// Fix Commas inside Brackets
|
// Fix Commas inside Brackets
|
||||||
input = input
|
input = input
|
||||||
|
|
@ -214,4 +214,24 @@ onUiLoaded(() => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.paste) {
|
||||||
|
for (const field of config.promptFields) {
|
||||||
|
field.addEventListener('paste', (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let paste = (event.clipboardData || window.clipboardData).getData('text');
|
||||||
|
paste = LeFormatter.formatString(paste, config.dedupe, config.removeUnderscore);
|
||||||
|
|
||||||
|
const currentText = field.value;
|
||||||
|
const cursorPosition = field.selectionStart;
|
||||||
|
|
||||||
|
const newText = currentText.slice(0, cursorPosition) + paste + currentText.slice(field.selectionEnd);
|
||||||
|
field.value = newText;
|
||||||
|
field.selectionStart = field.selectionEnd = cursorPosition + paste.length;
|
||||||
|
|
||||||
|
updateInput(field);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ def on_settings():
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
opts.add_option(
|
||||||
|
"pf_onpaste",
|
||||||
|
OptionInfo(False, "Trigger a Format when pasting text", **args),
|
||||||
|
)
|
||||||
|
|
||||||
opts.add_option(
|
opts.add_option(
|
||||||
"pf_exclusion",
|
"pf_exclusion",
|
||||||
OptionInfo(
|
OptionInfo(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue