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