Browse Source

Fix combining same message entities

master
morethanwords 3 years ago
parent
commit
466a9c5bc1
  1. 15
      src/lib/richtextprocessor.ts

15
src/lib/richtextprocessor.ts

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

Loading…
Cancel
Save