mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	handle overwriting QR set
This commit is contained in:
		| @@ -15,7 +15,6 @@ import { SettingsUi } from './src/ui/SettingsUi.js'; | |||||||
| //TODO context menus | //TODO context menus | ||||||
| //TODO move advanced QR options into own UI class | //TODO move advanced QR options into own UI class | ||||||
| //TODO slash commands | //TODO slash commands | ||||||
| //TODO handle replacing QR set (create->overwrite): update configs that use this set |  | ||||||
| //TODO easy way to CRUD QRs and sets | //TODO easy way to CRUD QRs and sets | ||||||
| //TODO easy way to set global and chat sets | //TODO easy way to set global and chat sets | ||||||
|  |  | ||||||
|   | |||||||
| @@ -210,23 +210,26 @@ export class SettingsUi { | |||||||
|     async deleteQrSet() { |     async deleteQrSet() { | ||||||
|         const confirmed = await callPopup(`Are you sure you want to delete the Quick Reply Set "${this.currentQrSet.name}"? This cannot be undone.`, 'confirm'); |         const confirmed = await callPopup(`Are you sure you want to delete the Quick Reply Set "${this.currentQrSet.name}"? This cannot be undone.`, 'confirm'); | ||||||
|         if (confirmed) { |         if (confirmed) { | ||||||
|             await this.currentQrSet.delete(); |             await this.doDeleteQrSet(this.currentQrSet); | ||||||
|             //HACK should just bubble up from QuickReplySet.delete() but that would require proper or at least more comples onDelete listeners |             this.rerender(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     async doDeleteQrSet(qrs) { | ||||||
|  |         await qrs.delete(); | ||||||
|  |         //TODO (HACK) should just bubble up from QuickReplySet.delete() but that would require proper or at least more comples onDelete listeners | ||||||
|         for (let i = this.settings.config.setList.length - 1; i >= 0; i--) { |         for (let i = this.settings.config.setList.length - 1; i >= 0; i--) { | ||||||
|                 if (this.settings.config.setList[i].set == this.currentQrSet) { |             if (this.settings.config.setList[i].set == qrs) { | ||||||
|                 this.settings.config.setList.splice(i, 1); |                 this.settings.config.setList.splice(i, 1); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (this.settings.chatConfig) { |         if (this.settings.chatConfig) { | ||||||
|             for (let i = this.settings.chatConfig.setList.length - 1; i >= 0; i--) { |             for (let i = this.settings.chatConfig.setList.length - 1; i >= 0; i--) { | ||||||
|                     if (this.settings.config.setList[i].set == this.currentQrSet) { |                 if (this.settings.config.setList[i].set == qrs) { | ||||||
|                     this.settings.config.setList.splice(i, 1); |                     this.settings.config.setList.splice(i, 1); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         this.settings.save(); |         this.settings.save(); | ||||||
|             this.rerender(); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async addQrSet() { |     async addQrSet() { | ||||||
| @@ -236,10 +239,13 @@ export class SettingsUi { | |||||||
|             if (oldQrs) { |             if (oldQrs) { | ||||||
|                 const replace = await callPopup(`A Quick Reply Set named "${name}" already exists.\nDo you want to overwrite the existing Quick Reply Set?\nThe existing set will be deleted. This cannot be undone.`, 'confirm'); |                 const replace = await callPopup(`A Quick Reply Set named "${name}" already exists.\nDo you want to overwrite the existing Quick Reply Set?\nThe existing set will be deleted. This cannot be undone.`, 'confirm'); | ||||||
|                 if (replace) { |                 if (replace) { | ||||||
|  |                     const idx = QuickReplySet.list.indexOf(oldQrs); | ||||||
|  |                     await this.doDeleteQrSet(oldQrs); | ||||||
|                     const qrs = new QuickReplySet(); |                     const qrs = new QuickReplySet(); | ||||||
|                     qrs.name = name; |                     qrs.name = name; | ||||||
|                     qrs.addQuickReply(); |                     qrs.addQuickReply(); | ||||||
|                     QuickReplySet.list[QuickReplySet.list.indexOf(oldQrs)] = qrs; |                     QuickReplySet.list.splice(idx, 0, qrs); | ||||||
|  |                     this.rerender(); | ||||||
|                     this.currentSet.value = name; |                     this.currentSet.value = name; | ||||||
|                     this.onQrSetChange(); |                     this.onQrSetChange(); | ||||||
|                     this.prepareGlobalSetList(); |                     this.prepareGlobalSetList(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user