fix(CodeEditor): save to db (#7504)

This commit is contained in:
one 2025-06-26 11:19:11 +08:00 committed by GitHub
parent 1f09c8a022
commit 5e0cae06db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,9 +17,9 @@ import { estimateHistoryTokens } from '@renderer/services/TokenService'
import store, { useAppDispatch } from '@renderer/store'
import { messageBlocksSelectors, updateOneBlock } from '@renderer/store/messageBlock'
import { newMessagesActions } from '@renderer/store/newMessage'
import { saveMessageAndBlocksToDB } from '@renderer/store/thunk/messageThunk'
import { saveMessageAndBlocksToDB, updateMessageAndBlocksThunk } from '@renderer/store/thunk/messageThunk'
import type { Assistant, Topic } from '@renderer/types'
import { type Message, MessageBlockType } from '@renderer/types/newMessage'
import { type Message, MessageBlock, MessageBlockType } from '@renderer/types/newMessage'
import {
captureScrollableDivAsBlob,
captureScrollableDivAsDataURL,
@ -211,7 +211,15 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
if (msgBlock && isTextLikeBlock(msgBlock) && msgBlock.type !== MessageBlockType.ERROR) {
try {
const updatedRaw = updateCodeBlock(msgBlock.content, codeBlockId, newContent)
const updatedBlock: MessageBlock = {
...msgBlock,
content: updatedRaw,
updatedAt: new Date().toISOString()
}
dispatch(updateOneBlock({ id: msgBlockId, changes: { content: updatedRaw } }))
await dispatch(updateMessageAndBlocksThunk(topic.id, null, [updatedBlock]))
window.message.success({ content: t('code_block.edit.save.success'), key: 'save-code' })
} catch (error) {
console.error(`Failed to save code block ${codeBlockId} content to message block ${msgBlockId}:`, error)