mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 21:35:52 +08:00
fix(CodeEditor): save to db (#7504)
This commit is contained in:
parent
1f09c8a022
commit
5e0cae06db
@ -17,9 +17,9 @@ import { estimateHistoryTokens } from '@renderer/services/TokenService'
|
|||||||
import store, { useAppDispatch } from '@renderer/store'
|
import store, { useAppDispatch } from '@renderer/store'
|
||||||
import { messageBlocksSelectors, updateOneBlock } from '@renderer/store/messageBlock'
|
import { messageBlocksSelectors, updateOneBlock } from '@renderer/store/messageBlock'
|
||||||
import { newMessagesActions } from '@renderer/store/newMessage'
|
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 { Assistant, Topic } from '@renderer/types'
|
||||||
import { type Message, MessageBlockType } from '@renderer/types/newMessage'
|
import { type Message, MessageBlock, MessageBlockType } from '@renderer/types/newMessage'
|
||||||
import {
|
import {
|
||||||
captureScrollableDivAsBlob,
|
captureScrollableDivAsBlob,
|
||||||
captureScrollableDivAsDataURL,
|
captureScrollableDivAsDataURL,
|
||||||
@ -211,7 +211,15 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
|
|||||||
if (msgBlock && isTextLikeBlock(msgBlock) && msgBlock.type !== MessageBlockType.ERROR) {
|
if (msgBlock && isTextLikeBlock(msgBlock) && msgBlock.type !== MessageBlockType.ERROR) {
|
||||||
try {
|
try {
|
||||||
const updatedRaw = updateCodeBlock(msgBlock.content, codeBlockId, newContent)
|
const updatedRaw = updateCodeBlock(msgBlock.content, codeBlockId, newContent)
|
||||||
|
const updatedBlock: MessageBlock = {
|
||||||
|
...msgBlock,
|
||||||
|
content: updatedRaw,
|
||||||
|
updatedAt: new Date().toISOString()
|
||||||
|
}
|
||||||
|
|
||||||
dispatch(updateOneBlock({ id: msgBlockId, changes: { content: updatedRaw } }))
|
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' })
|
window.message.success({ content: t('code_block.edit.save.success'), key: 'save-code' })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to save code block ${codeBlockId} content to message block ${msgBlockId}:`, error)
|
console.error(`Failed to save code block ${codeBlockId} content to message block ${msgBlockId}:`, error)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user