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>
Signed| @@ -96,6 +96,7 @@ export const METADATA_KEY = 'world_info'; | ||
| 96 | 96 | export const DEFAULT_DEPTH = 4; |
| 97 | 97 | export const DEFAULT_WEIGHT = 100; |
| 98 | 98 | export const MAX_SCAN_DEPTH = 1000; |
| 99 | +const MAX_COMMENT_LENGTH = 100; | |
| 99 | 100 | const KNOWN_DECORATORS = ['@@activate', '@@dont_activate']; |
| 100 | 101 | |
| 101 | 102 | // Typedef area |
| @@ -2423,7 +2424,7 @@ async function displayWorldEntries(name, data, navigation = navigation_option.no | ||
| 2423 | 2424 | let counter = 0; |
| 2424 | 2425 | for (const entry of Object.values(data.entries)) { |
| 2425 | 2426 | if (!entry.comment && Array.isArray(entry.key) && entry.key.length > 0) { |
| 2426 | 2427 | entry.comment = entry.key[.join(', ').slice(0], MAX_COMMENT_LENGTH); |
| 2427 | 2428 | setWIOriginalDataValue(data, entry.uid, 'comment', entry.comment); |
| 2428 | 2429 | counter++; |
| 2429 | 2430 | } |
| @@ -2846,6 +2847,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal | ||
| 2846 | 2847 | await saveWorldInfo(name, data); |
| 2847 | 2848 | } |
| 2848 | 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 | }); |
| 2850 | 2856 | |
| 2851 | 2857 | input.toggleClass('empty', !entry[entryPropName].length); |
| @@ -2881,6 +2887,11 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal | ||
| 2881 | 2887 | await saveWorldInfo(name, data); |
| 2882 | 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 | 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 | } |
| 3191 | 3202 | |
| 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 | + */ | |
| 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 | +/** | |
| 3193 | 3215 | * Main function to build the WI entry editor template. |
| 3194 | 3216 | * @param {string} name - The name of the world info file. |
| 3195 | 3217 | * @param {object} data - The world info data object. |
| @@ -3206,6 +3228,11 @@ export async function getWorldEntry(name, data, entry) { | ||
| 3206 | 3228 | |
| 3207 | 3229 | // Comment |
| 3208 | 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 | 3236 | commentInput.data('uid', entry.uid); |
| 3210 | 3237 | commentInput.on('input', async function (_, { skipReset = false, noSave = false } = {}) { |
| 3211 | 3238 | const uid = $(this).data('uid'); |