diff --git a/src/apps/chat/components/message/fragments-attachment-doc/DocumentFragmentEditor.tsx b/src/apps/chat/components/message/fragments-attachment-doc/DocumentFragmentEditor.tsx index 56d157759..d36cabdf3 100644 --- a/src/apps/chat/components/message/fragments-attachment-doc/DocumentFragmentEditor.tsx +++ b/src/apps/chat/components/message/fragments-attachment-doc/DocumentFragmentEditor.tsx @@ -10,7 +10,7 @@ import { AutoBlocksRenderer } from '~/modules/blocks/AutoBlocksRenderer'; import type { ContentScaling } from '~/common/app.theme'; import type { DMessageRole } from '~/common/stores/chat/chat.message'; -import { createDMessageDataInlineText, DMessageAttachmentFragment, DMessageFragmentId, specialShallowReplaceDocData } from '~/common/stores/chat/chat.fragments'; +import { createDMessageDataInlineText, createDocAttachmentFragment, DMessageAttachmentFragment, DMessageFragmentId } from '~/common/stores/chat/chat.fragments'; import { marshallWrapText } from '~/common/stores/chat/chat.tokens'; import { ContentPartTextEditor } from '../fragments-content/ContentPartTextEditor'; @@ -64,12 +64,24 @@ export function DocumentFragmentEditor(props: { setIsDeleteArmed(false); if (editedText === undefined) return; - if (editedText?.length > 0 && fragment.part.pt === 'doc') { - onFragmentReplace(fragmentId, { ...fragment, part: specialShallowReplaceDocData(fragment.part, createDMessageDataInlineText(editedText)) }); - // NOTE: since the former function changes the ID of the fragment, the - // whole editor will disappear as a side effect - } else + + // only edit DOCs + if (fragment.part.pt !== 'doc') { + console.warn('handleEditApply: unexpected part type:', fragment.part.pt); + return; + } + + if (editedText.length > 0) { + const newData = createDMessageDataInlineText(editedText, fragment.part.data.mimeType); + const newAttachment = createDocAttachmentFragment(fragment.title, fragment.caption, fragment.part.type, newData, fragment.part.ref, fragment.part.meta); + // reuse the same fragment ID, which makes the screen not flash (otherwise the whole editor would disappear as the ID does not exist anymore) + newAttachment.fId = fragmentId; + onFragmentReplace(fragmentId, newAttachment); + setIsEditing(false); + } else { + // if the user deleted all text, let's remove the part handleFragmentDelete(); + } }, [editedText, fragment, fragmentId, handleFragmentDelete, onFragmentReplace]); diff --git a/src/modules/blocks/code/RenderCode.tsx b/src/modules/blocks/code/RenderCode.tsx index 003bf910c..5aa537cca 100644 --- a/src/modules/blocks/code/RenderCode.tsx +++ b/src/modules/blocks/code/RenderCode.tsx @@ -96,9 +96,9 @@ export const overlayButtonsSx: SxProps = { interface RenderCodeBaseProps { codeBlock: CodeBlock, fitScreen?: boolean, + initialShowHTML?: boolean, noCopyButton?: boolean, optimizeLightweight?: boolean, - initialShowHTML?: boolean, sx?: SxProps, } @@ -176,7 +176,7 @@ function RenderCodeImpl(props: RenderCodeImplProps) { const canStackBlitz = blockComplete && isStackBlitzSupported(inferredCodeLanguage); - let showBlockTitle = blockTitle != inferredCodeLanguage && (blockTitle.includes('.') || blockTitle.includes('://')); + let showBlockTitle = (blockTitle != inferredCodeLanguage) && (blockTitle.includes('.') || blockTitle.includes('://')); // hide the block title when rendering HTML if (renderHTML) showBlockTitle = false;