Browse Source

Fix displaying other entities in monospace text

Fix formatting
master
Eduard Kuzmenko 2 years ago
parent
commit
20b2525d51
  1. 3
      src/components/chat/bubbles.ts
  2. 11
      src/lib/richTextProcessor/findConflictingEntity.ts
  3. 12
      src/lib/richTextProcessor/wrapRichText.ts

3
src/components/chat/bubbles.ts

@ -4178,13 +4178,14 @@ export default class ChatBubbles {
} }
default: default:
attachmentDiv = undefined;
bubble.classList.remove('is-message-empty'); bubble.classList.remove('is-message-empty');
messageDiv.append(i18n(UNSUPPORTED_LANG_PACK_KEY), timeSpan); messageDiv.append(i18n(UNSUPPORTED_LANG_PACK_KEY), timeSpan);
this.log.warn('unrecognized media type:', messageMedia._, message); this.log.warn('unrecognized media type:', messageMedia._, message);
break; break;
} }
if(!processingWebPage) { if(!processingWebPage && attachmentDiv) {
bubbleContainer.append(attachmentDiv); bubbleContainer.append(attachmentDiv);
} }

11
src/lib/richTextProcessor/findConflictingEntity.ts

@ -7,8 +7,19 @@
import { PASS_CONFLICTING_ENTITIES } from "."; import { PASS_CONFLICTING_ENTITIES } from ".";
import { MessageEntity } from "../../layer"; import { MessageEntity } from "../../layer";
const SINGLE_ENTITIES: Set<MessageEntity['_']> = new Set(['messageEntityPre', 'messageEntityCode']);
export default function findConflictingEntity(currentEntities: MessageEntity[], newEntity: MessageEntity) { export default function findConflictingEntity(currentEntities: MessageEntity[], newEntity: MessageEntity) {
let singleEnd = -1;
return currentEntities.find((currentEntity) => { return currentEntities.find((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._ || const isConflictingTypes = newEntity._ === currentEntity._ ||
(!PASS_CONFLICTING_ENTITIES.has(newEntity._) && !PASS_CONFLICTING_ENTITIES.has(currentEntity._)); (!PASS_CONFLICTING_ENTITIES.has(newEntity._) && !PASS_CONFLICTING_ENTITIES.has(currentEntity._));

12
src/lib/richTextProcessor/wrapRichText.ts

@ -434,7 +434,15 @@ export default function wrapRichText(text: string, options: Partial<{
// (lastElement || fragment).append(element ?? partText); // (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; lastElement = element;
} else { } else {
lastElement = fragment; lastElement = fragment;
@ -455,3 +463,5 @@ export default function wrapRichText(text: string, options: Partial<{
return fragment; return fragment;
} }
(window as any).wrapRichText = wrapRichText;

Loading…
Cancel
Save