From 6519fa0471dc92906e2496181ac38db62e5d33ee Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:12:34 +0000 Subject: [PATCH] Replace _ with space --- web/js/autocompleter.js | 23 ++++++++++++++++++++++- web/js/common/autocomplete.js | 7 ++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/web/js/autocompleter.js b/web/js/autocompleter.js index 3b0ce7a..8ce2304 100644 --- a/web/js/autocompleter.js +++ b/web/js/autocompleter.js @@ -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 diff --git a/web/js/common/autocomplete.js b/web/js/common/autocomplete.js index d04567f..862133b 100644 --- a/web/js/common/autocomplete.js +++ b/web/js/common/autocomplete.js @@ -314,6 +314,7 @@ class TextAreaCaretHelper { export class TextAreaAutoComplete { static globalSeparator = ""; static enabled = true; + static replacer = undefined; /** @type {Record>} */ 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);