Don't collapse newlines.

This causes index offset issues with any rich elements in the message.

We could try to fix the offsets, or alternatively replace the collapsed
newlines with spaces (to maintain the original offsets), but I don't
think it's worth the effort since I'm not sure that it's a good idea to
collapse newlines in the first place.
This commit is contained in:
JC Brand 2021-01-18 11:27:01 +01:00
parent 2c7b220453
commit 61bb0cfab7
2 changed files with 12 additions and 7 deletions

View File

@ -607,7 +607,7 @@ describe("A Chat Message", function () {
</message>`);
_converse.connection._dataRecv(mock.createRequest(stanza));
await new Promise(resolve => view.model.messages.once('rendered', resolve));
await u.waitUntil(() => view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '') === 'Hey\n\nHave you heard the news?');
await u.waitUntil(() => view.content.querySelector('converse-chat-message:last-child .chat-msg__text').innerHTML.replace(/<!---->/g, '') === 'Hey\n\n\nHave you heard the news?');
stanza = u.toStanza(`
<message from="${contact_jid}"
type="chat"
@ -617,6 +617,16 @@ describe("A Chat Message", function () {
_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\nthe news?');
stanza = u.toStanza(`
<message from="${contact_jid}"
type="chat"
to="romeo@montague.lit/orchard">
<body>Hey\nHave you heard\n\n\nthe news?\nhttps://conversejs.org</body>
</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');
done();
}));

View File

@ -8,7 +8,6 @@ import { html } from 'lit-html';
const u = converse.env.utils;
const isString = (s) => typeof s === 'string';
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>`;
@ -300,10 +299,6 @@ export class MessageText extends String {
return text.startsWith('/me ');
}
static replaceText (text) {
return convertASCII2Emoji(text.replace(/\n\n+/g, '\n\n'));
}
/**
* Take the annotations and return an array of text and TemplateResult
* instances to be rendered to the DOM.
@ -322,6 +317,6 @@ export class MessageText extends String {
...list
];
});
return list.reduce((acc, i) => isString(i) ? [...acc, MessageText.replaceText(i)] : [...acc, i], []);
return list.reduce((acc, i) => isString(i) ? [...acc, convertASCII2Emoji(i)] : [...acc, i], []);
}
}