Decided to still collapse newlines...
and to solve the offset issue by replacing excessive newlines with the zero-width space unicode character.
This commit is contained in:
parent
61bb0cfab7
commit
1a88aff179
@ -626,7 +626,10 @@ describe("A Chat Message", function () {
|
||||
</message>`);
|
||||
_converse.connection._dataRecv(mock.createRequest(stanza));
|
||||
await new Promise(resolve => view.model.messages.once('rendered', resolve));
|
||||
expect(view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '')).toBe('Hey\nHave you heard\n\n\nthe news?\nhttps://conversejs.org');
|
||||
await u.waitUntil(() => {
|
||||
const text = view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '');
|
||||
return text === 'Hey\nHave you heard\n\u200B\nthe news?\n<a target="_blank" rel="noopener" href="https://conversejs.org/">https://conversejs.org</a>';
|
||||
});
|
||||
done();
|
||||
}));
|
||||
|
||||
|
@ -8,6 +8,11 @@ import { html } from 'lit-html';
|
||||
const u = converse.env.utils;
|
||||
|
||||
const isString = (s) => typeof s === 'string';
|
||||
|
||||
// We don't render more than two line-breaks, replace extra line-breaks with
|
||||
// the zero-width whitespace character
|
||||
const collapseLineBreaks = text => text.replace(/\n\n+/g, m => `\n${"\u200B".repeat(m.length-2)}\n`);
|
||||
|
||||
const tpl_mention_with_nick = (o) => html`<span class="mention mention--self badge badge-info">${o.mention}</span>`;
|
||||
const tpl_mention = (o) => html`<span class="mention">${o.mention}</span>`;
|
||||
|
||||
@ -317,6 +322,6 @@ export class MessageText extends String {
|
||||
...list
|
||||
];
|
||||
});
|
||||
return list.reduce((acc, i) => isString(i) ? [...acc, convertASCII2Emoji(i)] : [...acc, i], []);
|
||||
return list.reduce((acc, i) => isString(i) ? [...acc, convertASCII2Emoji(collapseLineBreaks(i))] : [...acc, i], []);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user