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';
9696export const DEFAULT_DEPTH = 4;
9797export const DEFAULT_WEIGHT = 100;
9898export const MAX_SCAN_DEPTH = 1000;
99+const MAX_COMMENT_LENGTH = 100;
99100const KNOWN_DECORATORS = ['@@activate', '@@dont_activate'];
100101
101102// Typedef area
@@ -2423,7 +2424,7 @@ async function displayWorldEntries(name, data, navigation = navigation_option.no
24232424 let counter = 0;
24242425 for (const entry of Object.values(data.entries)) {
24252426 if (!entry.comment && Array.isArray(entry.key) && entry.key.length > 0) {
24262427 entry.comment = entry.key[.join(', ').slice(0], MAX_COMMENT_LENGTH);
24272428 setWIOriginalDataValue(data, entry.uid, 'comment', entry.comment);
24282429 counter++;
24292430 }
@@ -2846,6 +2847,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal
28462847 await saveWorldInfo(name, data);
28472848 }
28482849 $(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+ }
28492855 });
28502856
28512857 input.toggleClass('empty', !entry[entryPropName].length);
@@ -2881,6 +2887,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal
28812887 await saveWorldInfo(name, data);
28822888 $(this).toggleClass('empty', !data.entries[uid][entryPropName].length);
28832889 }
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+ }
28842895 });
28852896 input.val(entry[entryPropName].join(', ')).trigger('input', { skipReset: true });
28862897 }
@@ -3190,6 +3201,17 @@ function handleEntryKillSwitchHelper({ entryKillSwitch, entry, data, name, templ
31903201}
31913202
31923203/**
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+ */
3208+function 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+/**
31933215 * Main function to build the WI entry editor template.
31943216 * @param {string} name - The name of the world info file.
31953217 * @param {object} data - The world info data object.
@@ -3206,6 +3228,11 @@ export async function getWorldEntry(name, data, entry) {
32063228
32073229 // Comment
32083230 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+
32093236 commentInput.data('uid', entry.uid);
32103237 commentInput.on('input', async function (_, { skipReset = false, noSave = false } = {}) {
32113238 const uid = $(this).data('uid');