mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
WI automation/inclusionGroup not autocompleting to itself
This commit is contained in:
@@ -2029,9 +2029,13 @@ function getWorldEntry(name, data, entry) {
|
|||||||
* @returns {(input: any, output: any) => any} Callback function for the autocomplete
|
* @returns {(input: any, output: any) => any} Callback function for the autocomplete
|
||||||
*/
|
*/
|
||||||
function getInclusionGroupCallback(data) {
|
function getInclusionGroupCallback(data) {
|
||||||
return function (input, output) {
|
return function (control, input, output) {
|
||||||
|
const uid = $(control).data("uid");
|
||||||
|
const thisGroups = String($(control).val()).split(/,\s*/).filter(x => x).map(x => x.toLowerCase());
|
||||||
const groups = new Set();
|
const groups = new Set();
|
||||||
for (const entry of Object.values(data.entries)) {
|
for (const entry of Object.values(data.entries)) {
|
||||||
|
// Skip the groups of this entry, because auto-complete should only suggest the ones that are already available on other entries
|
||||||
|
if (entry.uid == uid) continue;
|
||||||
if (entry.group) {
|
if (entry.group) {
|
||||||
entry.group.split(/,\s*/).filter(x => x).forEach(x => groups.add(x));
|
entry.group.split(/,\s*/).filter(x => x).forEach(x => groups.add(x));
|
||||||
}
|
}
|
||||||
@@ -2041,20 +2045,19 @@ function getInclusionGroupCallback(data) {
|
|||||||
haystack.sort((a, b) => a.localeCompare(b));
|
haystack.sort((a, b) => a.localeCompare(b));
|
||||||
const needle = input.term.toLowerCase();
|
const needle = input.term.toLowerCase();
|
||||||
const hasExactMatch = haystack.findIndex(x => x.toLowerCase() == needle) !== -1;
|
const hasExactMatch = haystack.findIndex(x => x.toLowerCase() == needle) !== -1;
|
||||||
const result = haystack.filter(x => x.toLowerCase().includes(needle));
|
const result = haystack.filter(x => x.toLowerCase().includes(needle) && (!thisGroups.includes(x) || hasExactMatch && thisGroups.filter(g => g == x).length == 1));
|
||||||
|
|
||||||
if (input.term && !hasExactMatch) {
|
|
||||||
result.unshift(input.term);
|
|
||||||
}
|
|
||||||
|
|
||||||
output(result);
|
output(result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAutomationIdCallback(data) {
|
function getAutomationIdCallback(data) {
|
||||||
return function (input, output) {
|
return function (control, input, output) {
|
||||||
|
const uid = $(control).data("uid");
|
||||||
const ids = new Set();
|
const ids = new Set();
|
||||||
for (const entry of Object.values(data.entries)) {
|
for (const entry of Object.values(data.entries)) {
|
||||||
|
// Skip automation id of this entry, because auto-complete should only suggest the ones that are already available on other entries
|
||||||
|
if (entry.uid == uid) continue;
|
||||||
if (entry.automationId) {
|
if (entry.automationId) {
|
||||||
ids.add(String(entry.automationId));
|
ids.add(String(entry.automationId));
|
||||||
}
|
}
|
||||||
@@ -2070,13 +2073,8 @@ function getAutomationIdCallback(data) {
|
|||||||
const haystack = Array.from(ids);
|
const haystack = Array.from(ids);
|
||||||
haystack.sort((a, b) => a.localeCompare(b));
|
haystack.sort((a, b) => a.localeCompare(b));
|
||||||
const needle = input.term.toLowerCase();
|
const needle = input.term.toLowerCase();
|
||||||
const hasExactMatch = haystack.findIndex(x => x.toLowerCase() == needle) !== -1;
|
|
||||||
const result = haystack.filter(x => x.toLowerCase().includes(needle));
|
const result = haystack.filter(x => x.toLowerCase().includes(needle));
|
||||||
|
|
||||||
if (input.term && !hasExactMatch) {
|
|
||||||
result.unshift(input.term);
|
|
||||||
}
|
|
||||||
|
|
||||||
output(result);
|
output(result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2084,7 +2082,7 @@ function getAutomationIdCallback(data) {
|
|||||||
/**
|
/**
|
||||||
* Create an autocomplete for the inclusion group.
|
* Create an autocomplete for the inclusion group.
|
||||||
* @param {JQuery<HTMLElement>} input - Input element to attach the autocomplete to
|
* @param {JQuery<HTMLElement>} input - Input element to attach the autocomplete to
|
||||||
* @param {(input: any, output: any) => any} callback - Source data callbacks
|
* @param {(control: JQuery<HTMLElement>, input: any, output: any) => any} callback - Source data callbacks
|
||||||
* @param {object} [options={}] - Optional arguments
|
* @param {object} [options={}] - Optional arguments
|
||||||
* @param {boolean} [options.allowMultiple=false] - Whether to allow multiple comma-separated values
|
* @param {boolean} [options.allowMultiple=false] - Whether to allow multiple comma-separated values
|
||||||
*/
|
*/
|
||||||
@@ -2106,11 +2104,11 @@ function createEntryInputAutocomplete(input, callback, { allowMultiple = false }
|
|||||||
minLength: 0,
|
minLength: 0,
|
||||||
source: function (request, response) {
|
source: function (request, response) {
|
||||||
if (!allowMultiple) {
|
if (!allowMultiple) {
|
||||||
callback(request, response);
|
callback(input, request, response);
|
||||||
} else {
|
} else {
|
||||||
const term = request.term.split(/,\s*/).pop();
|
const term = request.term.split(/,\s*/).pop();
|
||||||
request.term = term;
|
request.term = term;
|
||||||
callback(request, response);
|
callback(input, request, response);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
select: handleSelect,
|
select: handleSelect,
|
||||||
|
Reference in New Issue
Block a user