From 61bb0cfab7af86d96b0e23da95a43ec103fda451 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Mon, 18 Jan 2021 11:27:01 +0100 Subject: [PATCH] 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. --- spec/messages.js | 12 +++++++++++- src/shared/message/text.js | 7 +------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/messages.js b/spec/messages.js index 502f6b032..af2a67ee0 100644 --- a/spec/messages.js +++ b/spec/messages.js @@ -607,7 +607,7 @@ describe("A Chat Message", function () { `); _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(` 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(` + + Hey\nHave you heard\n\n\nthe news?\nhttps://conversejs.org + `); + _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(); })); diff --git a/src/shared/message/text.js b/src/shared/message/text.js index 691f51778..aff2a1e72 100644 --- a/src/shared/message/text.js +++ b/src/shared/message/text.js @@ -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`${o.mention}`; const tpl_mention = (o) => html`${o.mention}`; @@ -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], []); } }