Replace _ with space

This commit is contained in:
pythongosssss
2024-01-03 20:12:34 +00:00
parent 7279dd260e
commit 6519fa0471
2 changed files with 28 additions and 2 deletions
+22 -1
View File
@@ -356,7 +356,6 @@ app.registerExtension({
},
[
$el("input", {
id: id.replaceAll(".", "-"),
type: "checkbox",
checked: !!TextAreaAutoComplete.globalSeparator,
onchange: (event) => {
@@ -367,6 +366,26 @@ app.registerExtension({
}),
]
),
$el(
"label",
{
textContent: "Replace _ with space ",
style: {
display: "block",
},
},
[
$el("input", {
type: "checkbox",
checked: !!TextAreaAutoComplete.replacer,
onchange: (event) => {
const checked = !!event.target.checked;
TextAreaAutoComplete.replacer = checked ? (v) => v.replaceAll("_", " ") : undefined;
localStorage.setItem(id + ".ReplaceUnderscore", checked);
},
}),
]
),
$el("button", {
textContent: "Manage Custom Words",
onclick: () => {
@@ -384,6 +403,8 @@ app.registerExtension({
},
});
TextAreaAutoComplete.enabled = enabledSetting.value;
TextAreaAutoComplete.replacer = localStorage.getItem(id + ".ReplaceUnderscore") === "true" ? (v) => v.replaceAll("_", " ") : undefined;
},
beforeRegisterNodeDef(_, def) {
// Process each input to see if there is a custom word list for
+6 -1
View File
@@ -314,6 +314,7 @@ class TextAreaCaretHelper {
export class TextAreaAutoComplete {
static globalSeparator = "";
static enabled = true;
static replacer = undefined;
/** @type {Record<string, Record<string, AutoCompleteEntry>>} */
static groups = {};
@@ -565,7 +566,11 @@ export class TextAreaAutoComplete {
{
onclick: () => {
this.el.focus();
this.helper.insertAtCursor((wordInfo.value ?? wordInfo.text) + this.separator, -before.length, wordInfo.caretOffset);
let value = wordInfo.value ?? wordInfo.text;
if(TextAreaAutoComplete.replacer) {
value = TextAreaAutoComplete.replacer(value);
}
this.helper.insertAtCursor(value + this.separator, -before.length, wordInfo.caretOffset);
setTimeout(() => {
this.#update();
}, 150);