Cancel debounced chat save before clearing chat
| @@ -1979,7 +1979,19 @@ export async function printMessages() { | |||
| 1979 | } | 1979 | } |
| 1980 | } | 1980 | } |
| 1981 | 1981 | ||
| 1982 | /** | ||
| 1983 | * Cancels the debounced chat save if it is currently pending. | ||
| 1984 | */ | ||
| 1985 | export function cancelDebouncedChatSave() { | ||
| 1986 | if (chatSaveTimeout) { | ||
| 1987 | console.debug('Debounced chat save cancelled'); | ||
| 1988 | clearTimeout(chatSaveTimeout); | ||
| 1989 | chatSaveTimeout = null; | ||
| 1990 | } | ||
| 1991 | } | ||
| 1992 | |||
| 1982 | export async function clearChat() { | 1993 | export async function clearChat() { |
| 1994 | cancelDebouncedChatSave(); | ||
| 1983 | closeMessageEditor(); | 1995 | closeMessageEditor(); |
| 1984 | extension_prompts = {}; | 1996 | extension_prompts = {}; |
| 1985 | if (is_delete_mode) { | 1997 | if (is_delete_mode) { |
| @@ -6929,11 +6941,7 @@ export function saveChatDebounced() { | |||
| 6929 | const chid = this_chid; | 6941 | const chid = this_chid; |
| 6930 | const selectedGroup = selected_group; | 6942 | const selectedGroup = selected_group; |
| 6931 | 6943 | ||
| 6932 | if (chatSaveTimeout) { | 6944 | cancelDebouncedChatSave(); |
| 6933 | console.debug('Clearing chat save timeout'); | ||
| 6934 | clearTimeout(chatSaveTimeout); | ||
| 6935 | chatSaveTimeout = null; | ||
| 6936 | } | ||
| 6937 | 6945 | ||
| 6938 | chatSaveTimeout = setTimeout(async () => { | 6946 | chatSaveTimeout = setTimeout(async () => { |
| 6939 | if (selectedGroup !== selected_group) { | 6947 | if (selectedGroup !== selected_group) { |
| @@ -8646,11 +8654,7 @@ export async function saveChatConditional() { | |||
| 8646 | } | 8654 | } |
| 8647 | 8655 | ||
| 8648 | try { | 8656 | try { |
| 8649 | if (chatSaveTimeout) { | 8657 | cancelDebouncedChatSave(); |
| 8650 | console.debug('Debounced chat save canceled'); | ||
| 8651 | clearTimeout(chatSaveTimeout); | ||
| 8652 | chatSaveTimeout = null; | ||
| 8653 | } | ||
| 8654 | 8658 | ||
| 8655 | isChatSaving = true; | 8659 | isChatSaving = true; |
| 8656 | 8660 | ||