Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions web/js/autocompleter.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,31 @@ app.registerExtension({
}),
]
),
$el(
"label",
{
textContent: "Debounce in ms: ",
style: {
display: "block",
},
},
[
$el("input", {
type: "number",
value: +TextAreaAutoComplete.debounceMs || 75,
min: 0,
step: 10,
style: {
width: "80px"
},
onchange: (event) => {
const value = Math.max(0, +event.target.value || 0);
TextAreaAutoComplete.debounceMs = value;
localStorage.setItem(id + ".DebounceMs", value);
},
}),
]
),
$el("button", {
textContent: "Manage Custom Words",
onclick: () => {
Expand Down Expand Up @@ -520,12 +545,13 @@ 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";
TextAreaAutoComplete.lorasEnabled = localStorage.getItem(id + ".ShowLoras") === "true";
TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || 20;
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";
TextAreaAutoComplete.lorasEnabled = localStorage.getItem(id + ".ShowLoras") === "true";
TextAreaAutoComplete.suggestionCount = +localStorage.getItem(id + ".SuggestionCount") || 20;
TextAreaAutoComplete.debounceMs = +localStorage.getItem(id + ".DebounceMs") || 75;
},
setup() {
async function addEmbeddings() {
Expand Down
13 changes: 11 additions & 2 deletions web/js/common/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,19 @@ export class TextAreaAutoComplete {
this.dropdown = $el("div.pysssss-autocomplete");
this.overrideWords = words;
this.overrideSeparator = separator;
this.debouncedUpdate = this.#debounce(this.#update.bind(this), 75);

this.#setup();
}

#debounce(func, delay) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), delay);
};
}

#setup() {
this.el.addEventListener("keydown", this.#keyDown.bind(this));
this.el.addEventListener("keypress", this.#keyPress.bind(this));
Expand Down Expand Up @@ -457,7 +466,7 @@ export class TextAreaAutoComplete {
}

if (!e.defaultPrevented) {
this.#update();
this.debouncedUpdate();
}
}

Expand All @@ -475,7 +484,7 @@ export class TextAreaAutoComplete {
return;
}
if (!e.defaultPrevented) {
this.#update();
this.debouncedUpdate();
}
}

Expand Down