diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 295706a8..6eb18a2f 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -4178,13 +4178,14 @@ export default class ChatBubbles { } default: + attachmentDiv = undefined; bubble.classList.remove('is-message-empty'); messageDiv.append(i18n(UNSUPPORTED_LANG_PACK_KEY), timeSpan); this.log.warn('unrecognized media type:', messageMedia._, message); break; } - if(!processingWebPage) { + if(!processingWebPage && attachmentDiv) { bubbleContainer.append(attachmentDiv); } diff --git a/src/lib/richTextProcessor/findConflictingEntity.ts b/src/lib/richTextProcessor/findConflictingEntity.ts index 977ce627..060ec0eb 100644 --- a/src/lib/richTextProcessor/findConflictingEntity.ts +++ b/src/lib/richTextProcessor/findConflictingEntity.ts @@ -7,11 +7,22 @@ import { PASS_CONFLICTING_ENTITIES } from "."; import { MessageEntity } from "../../layer"; +const SINGLE_ENTITIES: Set = new Set(['messageEntityPre', 'messageEntityCode']); + export default function findConflictingEntity(currentEntities: MessageEntity[], newEntity: MessageEntity) { + let singleEnd = -1; return currentEntities.find((currentEntity) => { - const isConflictingTypes = newEntity._ === currentEntity._ || - (!PASS_CONFLICTING_ENTITIES.has(newEntity._) && !PASS_CONFLICTING_ENTITIES.has(currentEntity._)); + if(SINGLE_ENTITIES.has(currentEntity._)) { + singleEnd = currentEntity.offset + currentEntity.length; + } + if(newEntity.offset < singleEnd && !PASS_CONFLICTING_ENTITIES.has(newEntity._)) { + return true; + } + + const isConflictingTypes = newEntity._ === currentEntity._ || + (!PASS_CONFLICTING_ENTITIES.has(newEntity._) && !PASS_CONFLICTING_ENTITIES.has(currentEntity._)); + if(!isConflictingTypes) { return false; } diff --git a/src/lib/richTextProcessor/wrapRichText.ts b/src/lib/richTextProcessor/wrapRichText.ts index b7f9acb7..7edc9b83 100644 --- a/src/lib/richTextProcessor/wrapRichText.ts +++ b/src/lib/richTextProcessor/wrapRichText.ts @@ -434,7 +434,15 @@ export default function wrapRichText(text: string, options: Partial<{ // (lastElement || fragment).append(element ?? partText); // } - if(entity.length > partText.length && element) { + if(nasty.usedLength <= endOffset) { + if(nasty.usedLength < endOffset) { + (element || fragment).append(nasty.text.slice(nasty.usedLength, endOffset)); + nasty.usedLength = endOffset; + } + + lastElement = fragment; + nasty.lastEntity = undefined; + } else if(entity.length > partText.length && element) { lastElement = element; } else { lastElement = fragment; @@ -455,3 +463,5 @@ export default function wrapRichText(text: string, options: Partial<{ return fragment; } + +(window as any).wrapRichText = wrapRichText;