Fix autocomplete 4 part format missing break
Add option for insert keys
This commit is contained in:
+53
-2
@@ -104,7 +104,7 @@ async function addCustomWords(text) {
|
||||
// a1111 csv format?
|
||||
value = n[0];
|
||||
priority = +n[2];
|
||||
const aliases = n[3];
|
||||
const aliases = n[3]?.trim();
|
||||
if (aliases) {
|
||||
const split = aliases.split(",");
|
||||
for (const text of split) {
|
||||
@@ -112,6 +112,7 @@ async function addCustomWords(text) {
|
||||
}
|
||||
}
|
||||
text = value;
|
||||
break;
|
||||
default:
|
||||
// Word,alias,priority
|
||||
text = n[1];
|
||||
@@ -386,6 +387,55 @@ app.registerExtension({
|
||||
}),
|
||||
]
|
||||
),
|
||||
$el(
|
||||
"label",
|
||||
{
|
||||
textContent: "Insert suggestion on: ",
|
||||
style: {
|
||||
display: "block",
|
||||
},
|
||||
},
|
||||
[
|
||||
$el(
|
||||
"label",
|
||||
{
|
||||
textContent: "Tab",
|
||||
style: {
|
||||
display: "block",
|
||||
marginLeft: "20px",
|
||||
},
|
||||
},
|
||||
$el("input", {
|
||||
type: "checkbox",
|
||||
checked: !!TextAreaAutoComplete.insertOnTab,
|
||||
onchange: (event) => {
|
||||
const checked = !!event.target.checked;
|
||||
TextAreaAutoComplete.insertOnTab = checked;
|
||||
localStorage.setItem(id + ".InsertOnTab", checked);
|
||||
},
|
||||
})
|
||||
),
|
||||
$el(
|
||||
"label",
|
||||
{
|
||||
textContent: "Enter",
|
||||
style: {
|
||||
display: "block",
|
||||
marginLeft: "20px",
|
||||
},
|
||||
},
|
||||
$el("input", {
|
||||
type: "checkbox",
|
||||
checked: !!TextAreaAutoComplete.insertOnEnter,
|
||||
onchange: (event) => {
|
||||
const checked = !!event.target.checked;
|
||||
TextAreaAutoComplete.insertOnEnter = checked;
|
||||
localStorage.setItem(id + ".InsertOnEnter", checked);
|
||||
},
|
||||
})
|
||||
),
|
||||
]
|
||||
),
|
||||
$el("button", {
|
||||
textContent: "Manage Custom Words",
|
||||
onclick: () => {
|
||||
@@ -404,7 +454,8 @@ app.registerExtension({
|
||||
});
|
||||
TextAreaAutoComplete.enabled = enabledSetting.value;
|
||||
TextAreaAutoComplete.replacer = localStorage.getItem(id + ".ReplaceUnderscore") === "true" ? (v) => v.replaceAll("_", " ") : undefined;
|
||||
|
||||
TextAreaAutoComplete.insertOnTab = localStorage.getItem(id + ".InsertOnTab") !== "false";
|
||||
TextAreaAutoComplete.insertOnEnter = localStorage.getItem(id + ".InsertOnEnter") !== "false";
|
||||
},
|
||||
beforeRegisterNodeDef(_, def) {
|
||||
// Process each input to see if there is a custom word list for
|
||||
|
||||
@@ -314,6 +314,8 @@ class TextAreaCaretHelper {
|
||||
export class TextAreaAutoComplete {
|
||||
static globalSeparator = "";
|
||||
static enabled = true;
|
||||
static insertOnTab = true;
|
||||
static insertOnEnter = true;
|
||||
static replacer = undefined;
|
||||
|
||||
/** @type {Record<string, Record<string, AutoCompleteEntry>>} */
|
||||
@@ -386,7 +388,9 @@ export class TextAreaAutoComplete {
|
||||
break;
|
||||
case "Tab":
|
||||
e.preventDefault();
|
||||
this.#insertItem();
|
||||
if (TextAreaAutoComplete.insertOnTab) {
|
||||
this.#insertItem();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -403,7 +407,9 @@ export class TextAreaAutoComplete {
|
||||
case "Enter":
|
||||
if (!e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
this.#insertItem();
|
||||
if (TextAreaAutoComplete.insertOnEnter) {
|
||||
this.#insertItem();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -567,7 +573,7 @@ export class TextAreaAutoComplete {
|
||||
onclick: () => {
|
||||
this.el.focus();
|
||||
let value = wordInfo.value ?? wordInfo.text;
|
||||
if(TextAreaAutoComplete.replacer) {
|
||||
if (TextAreaAutoComplete.replacer) {
|
||||
value = TextAreaAutoComplete.replacer(value);
|
||||
}
|
||||
this.helper.insertAtCursor(value + this.separator, -before.length, wordInfo.caretOffset);
|
||||
|
||||
Reference in New Issue
Block a user