mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
cache autocomplete elements
This commit is contained in:
@ -35,21 +35,12 @@ export class SlashCommand {
|
||||
/**@type {SlashCommandNamedArgument[]}*/ namedArgumentList = [];
|
||||
/**@type {SlashCommandArgument[]}*/ unnamedArgumentList = [];
|
||||
|
||||
get helpStringFormatted() {
|
||||
let aliases = '';
|
||||
if (this.aliases?.length > 0) {
|
||||
aliases = ' (alias: ';
|
||||
aliases += this.aliases
|
||||
.map(it=>`<span class="monospace">/${it}</span>`)
|
||||
.join(', ')
|
||||
;
|
||||
aliases += ')';
|
||||
}
|
||||
return `<span class="monospace">/${this.name}</span> ${this.helpString}${aliases}`;
|
||||
}
|
||||
/**@type {Object.<string, HTMLElement>}*/ helpCache = {};
|
||||
/**@type {Object.<string, DocumentFragment>}*/ helpDetailsCache = {};
|
||||
|
||||
renderHelpItem(key = null) {
|
||||
key = key ?? this.name;
|
||||
if (!this.helpCache[key]) {
|
||||
const typeIcon = '/';
|
||||
const li = document.createElement('li'); {
|
||||
li.classList.add('item');
|
||||
@ -189,12 +180,15 @@ export class SlashCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
return li;
|
||||
this.helpCache[key] = li;
|
||||
}
|
||||
return this.helpCache[key];
|
||||
}
|
||||
|
||||
renderHelpDetails(key = null) {
|
||||
const frag = document.createDocumentFragment();
|
||||
key = key ?? this.name;
|
||||
if (!this.helpDetailsCache[key]) {
|
||||
const frag = document.createDocumentFragment();
|
||||
const cmd = this;
|
||||
const namedArguments = cmd.namedArgumentList ?? [];
|
||||
const unnamedArguments = cmd.unnamedArgumentList ?? [];
|
||||
@ -358,6 +352,8 @@ export class SlashCommand {
|
||||
frag.append(aliases);
|
||||
}
|
||||
}
|
||||
return frag;
|
||||
this.helpDetailsCache[key] = frag;
|
||||
}
|
||||
return this.helpDetailsCache[key].cloneNode(true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user