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 } = {}) {
61 const chatNames = await getExistingChatNames();61 const chatNames = await getExistingChatNames();
6262
63 const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace });63 const body = await renderTemplateAsync('createCheckpoint', { isReplace: isReplace });
64 let name = forceName || await Popup.show.input('Create Checkpoint', body);64 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 === '') {
69 for (let i = chatNames.length; i < 1000; i++) {67 for (let i = chatNames.length; i < 1000; i++) {
70 name = bookmarkNameToken + i;68 name = bookmarkNameToken + i;
71 if (!chatNames.includes(name)) {69 if (!chatNames.includes(name)) {
@@ -73,6 +71,9 @@ async function getBookmarkName({ isReplace = false, forceName = null } = {}) {
73 }71 }
74 }72 }
75 }73 }
74 if (!name) {
75 return null;
76 }
7677
77 return `${name} - ${humanizedDateTime()}`;78 return `${name} - ${humanizedDateTime()}`;
78}79}
@@ -447,8 +448,8 @@ function registerBookmarksSlashCommands() {
447 const mesId = Number(args.mesId ?? getLastMessageId());448 const mesId = Number(args.mesId ?? getLastMessageId());
448 if (!validateMessageId(mesId, 'Create Checkpoint')) return '';449 if (!validateMessageId(mesId, 'Create Checkpoint')) return '';
449450
450 if (!text || typeof text !== 'string') {451 if (typeof text !== 'string') {
451 toastr.warning('Checkpoint name must be provided', 'Create Checkpoint');452 toastr.warning('Checkpoint name must be a string or empty', 'Create Checkpoint');
452 return '';453 return '';
453 }454 }
454455
@@ -467,12 +468,12 @@ function registerBookmarksSlashCommands() {
467 SlashCommandArgument.fromProps({468 SlashCommandArgument.fromProps({
468 description: 'Checkpoint name',469 description: 'Checkpoint name',
469 typeList: [ARGUMENT_TYPE.STRING],470 typeList: [ARGUMENT_TYPE.STRING],
470 isRequired: true,
471 }),471 }),
472 ],472 ],
473 helpString: `473 helpString: `
474 <div>474 <div>
475 Create a new checkpoint for the selected message with the provided name. If no message id is provided, will use the last message.475 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.
476 </div>477 </div>
477 <div>478 <div>
478 A created checkpoint will be permanently linked with the message.<br />479 A created checkpoint will be permanently linked with the message.<br />
public/scripts/popup.js+3 -0
@@ -83,6 +83,9 @@ const showPopupHelper = {
83 const content = PopupUtils.BuildTextWithHeader(header, text);83 const content = PopupUtils.BuildTextWithHeader(header, text);
84 const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions);84 const popup = new Popup(content, POPUP_TYPE.INPUT, defaultValue, popupOptions);
85 const value = await popup.show();85 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 '';
86 return value ? String(value) : null;89 return value ? String(value) : null;
87 },90 },
8891