If the `world-info` has no comment, show it's keys in the placeholder. (#4681) * Show keys in commentInput's placeholder. * Fixed. https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450822592 https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450827302 https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450834282 https://github.com/SillyTavern/SillyTavern/pull/4681#discussion_r2450844011 * Update comment backfill logic * Don't update placeholder with secondary keys * Fix MAX_COMMENT_LENGTH to enforce a limit of 100 characters --------- Co-authored-by: user <user@exmaple.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

2df8e52d48febd1e2bd3dae21094063d6df8ab94

DeclineThyself <FallenHaze@tutamail.com>

Signed
1 files changed, +28 -1Ignore whitespace
public/scripts/world-info.js+28 -1
@@ -96,6 +96,7 @@ export const METADATA_KEY = 'world_info';
96export const DEFAULT_DEPTH = 4;96export const DEFAULT_DEPTH = 4;
97export const DEFAULT_WEIGHT = 100;97export const DEFAULT_WEIGHT = 100;
98export const MAX_SCAN_DEPTH = 1000;98export const MAX_SCAN_DEPTH = 1000;
99const MAX_COMMENT_LENGTH = 100;
99const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];100const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];
100101
101// Typedef area102// Typedef area
@@ -2423,7 +2424,7 @@ async function displayWorldEntries(name, data, navigation = navigation_option.no
2423 let counter = 0;2424 let counter = 0;
2424 for (const entry of Object.values(data.entries)) {2425 for (const entry of Object.values(data.entries)) {
2425 if (!entry.comment && Array.isArray(entry.key) && entry.key.length > 0) {2426 if (!entry.comment && Array.isArray(entry.key) && entry.key.length > 0) {
2426 entry.comment = entry.key[0];2427 entry.comment = entry.key.join(', ').slice(0, MAX_COMMENT_LENGTH);
2427 setWIOriginalDataValue(data, entry.uid, 'comment', entry.comment);2428 setWIOriginalDataValue(data, entry.uid, 'comment', entry.comment);
2428 counter++;2429 counter++;
2429 }2430 }
@@ -2846,6 +2847,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal
2846 await saveWorldInfo(name, data);2847 await saveWorldInfo(name, data);
2847 }2848 }
2848 $(this).toggleClass('empty', !data.entries[uid][entryPropName].length);2849 $(this).toggleClass('empty', !data.entries[uid][entryPropName].length);
2850 // Update the commentInput's placeholder for primary keys
2851 if (entryPropName === 'key') {
2852 const commentInput = $(_event.currentTarget).closest('.world_entry_form').find('textarea[name="comment"]');
2853 setCommentPlaceholder(data.entries[uid][entryPropName].join(', '), commentInput);
2854 }
2849 });2855 });
28502856
2851 input.toggleClass('empty', !entry[entryPropName].length);2857 input.toggleClass('empty', !entry[entryPropName].length);
@@ -2881,6 +2887,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal
2881 await saveWorldInfo(name, data);2887 await saveWorldInfo(name, data);
2882 $(this).toggleClass('empty', !data.entries[uid][entryPropName].length);2888 $(this).toggleClass('empty', !data.entries[uid][entryPropName].length);
2883 }2889 }
2890 // Update the commentInput's placeholder for primary keys
2891 if (entryPropName === 'key') {
2892 const commentInput = $(_event.currentTarget).closest('.world_entry_form').find('textarea[name="comment"]');
2893 setCommentPlaceholder(value, commentInput);
2894 }
2884 });2895 });
2885 input.val(entry[entryPropName].join(', ')).trigger('input', { skipReset: true });2896 input.val(entry[entryPropName].join(', ')).trigger('input', { skipReset: true });
2886 }2897 }
@@ -3190,6 +3201,17 @@ function handleEntryKillSwitchHelper({ entryKillSwitch, entry, data, name, templ
3190}3201}
31913202
3192/**3203/**
3204 * Update commentInput's placeholder.
3205 * @param {string} keys Text to display in commentInput's placeholder.
3206 * @param {JQuery<HTMLElement>} commentInput The comment input element.
3207 */
3208function setCommentPlaceholder(keys, commentInput) {
3209 // Limit placeholder text to avoid performance issues.
3210 keys = keys.slice(0, MAX_COMMENT_LENGTH);
3211 commentInput.attr('placeholder', (keys || t`Entry Title/Memo`));
3212}
3213
3214/**
3193 * Main function to build the WI entry editor template.3215 * Main function to build the WI entry editor template.
3194 * @param {string} name - The name of the world info file.3216 * @param {string} name - The name of the world info file.
3195 * @param {object} data - The world info data object.3217 * @param {object} data - The world info data object.
@@ -3206,6 +3228,11 @@ export async function getWorldEntry(name, data, entry) {
32063228
3207 // Comment3229 // Comment
3208 const commentInput = headerTemplate.find('textarea[name="comment"]');3230 const commentInput = headerTemplate.find('textarea[name="comment"]');
3231
3232 //Update the commentInput's placeholder.
3233 const keys = entry['key'].join(', ');
3234 setCommentPlaceholder(keys, commentInput);
3235
3209 commentInput.data('uid', entry.uid);3236 commentInput.data('uid', entry.uid);
3210 commentInput.on('input', async function (_, { skipReset = false, noSave = false } = {}) {3237 commentInput.on('input', async function (_, { skipReset = false, noSave = false } = {}) {
3211 const uid = $(this).data('uid');3238 const uid = $(this).data('uid');