Fix combining same message entities

This commit is contained in:
morethanwords 2022-01-15 06:28:44 +04:00
parent 6a913e9271
commit 466a9c5bc1

View File

@ -422,6 +422,16 @@ namespace RichTextProcessor {
return currentEntities;
}
const CAN_COMBINE_ENTITIES: Set<MessageEntity['_']> = new Set([
'messageEntityBold',
'messageEntityItalic',
'messageEntityCode',
'messageEntityPre',
'messageEntityUnderline',
'messageEntityStrike',
'messageEntityBlockquote',
'messageEntitySpoiler'
]);
export function combineSameEntities(entities: MessageEntity[]) {
//entities = entities.slice();
for(let i = 0; i < entities.length; ++i) {
@ -429,7 +439,10 @@ namespace RichTextProcessor {
let nextEntityIdx = -1;
do {
nextEntityIdx = entities.findIndex((e, _i) => _i !== i && e._ === entity._ && (e.offset - entity.length) === entity.offset);
nextEntityIdx = entities.findIndex((e, _i) => {
return CAN_COMBINE_ENTITIES.has(e._) && _i !== i && e._ === entity._ && (e.offset - entity.length) === entity.offset;
});
if(nextEntityIdx !== -1) {
const nextEntity = entities[nextEntityIdx];
entity.length += nextEntity.length;