Fix checkpoint create auto generate (and more) - Fix empty checkpoint name on mes click to auto generate - Change /checkpoint-create to not require name and auto generate - Fix popup input type returning empty string instead of null on empty input field

73c14711e1b80addf23d0cca4d3bcc12a275cd13

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +13 -9Showing whitespace changes
public/scripts/bookmarks.js+10 -9
@@ -61,11 +61,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
6161 const chatNames = await getExistingChatNames();
6262
6363 const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace });
6464 let name = forceName ||?? await Popup.show.input('Create Checkpoint', body);
65- if (name === null) {
65+ // Special handling for confirmed empty input (=> auto-generate name)
66- return null;
66+ if (name === '') {
67- }
68- else if (name === '') {
6967 for (let i = chatNames.length; i < 1000; i++) {
7068 name = bookmarkNameToken + i;
7169 if (!chatNames.includes(name)) {
@@ -73,6 +71,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
7371 }
7472 }
7573 }
74+ if (!name) {
75+ return null;
76+ }
7677
7778 return `${name} - ${humanizedDateTime()}`;
7879}
@@ -447,8 +448,8 @@ function registerBookmarksSlashCommands() {
447448 const mesId = Number(args.mesId ?? getLastMessageId());
448449 if (!validateMessageId(mesId, 'Create Checkpoint')) return '';
449450
450451 if (!text || typeof text !== 'string') {
451452 toastr.warning('Checkpoint name must be provideda string or empty', 'Create Checkpoint');
452453 return '';
453454 }
454455
@@ -467,12 +468,12 @@ function registerBookmarksSlashCommands() {
467468 SlashCommandArgument.fromProps({
468469 description: 'Checkpoint name',
469470 typeList: [ARGUMENT_TYPE.STRING],
470- isRequired: true,
471471 }),
472472 ],
473473 helpString: `
474474 <div>
475475 Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message.<br />
476+ Leave the checkpoint name empty to auto-generate one.
476477 </div>
477478 <div>
478479 A created checkpoint will be permanently linked with the message.<br />
public/scripts/popup.js+3 -0
@@ -83,6 +83,9 @@ const showPopupHelper = {
8383 const content = PopupUtils.BuildTextWithHeader(header, text);
8484 const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions);
8585 const value = await popup.show();
86+ // Return values: If empty string, we explicitly handle that as returning that empty string as "success" provided.
87+ // Otherwise, all non-truthy values (false, null, undefined) are treated as "cancel" and return null.
88+ if (value === '') return '';
8689 return value ? String(value) : null;
8790 },
8891