From 577883a1d4f5fdbb40f20885dd460caeab8594e1 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 11 May 2021 13:31:33 +0530 Subject: [PATCH] Refactor loop Don't handle last element separately Signed-off-by: RMidhunSuresh --- src/domain/session/room/timeline/MessageBodyBuilder.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/domain/session/room/timeline/MessageBodyBuilder.js b/src/domain/session/room/timeline/MessageBodyBuilder.js index 7c4f7a56..2831fdd0 100644 --- a/src/domain/session/room/timeline/MessageBodyBuilder.js +++ b/src/domain/session/room/timeline/MessageBodyBuilder.js @@ -8,12 +8,12 @@ export class MessageBodyBuilder { fromText(text) { const components = text.split("\n"); - components.slice(0, -1).forEach(t => { - linkify(t, this.insert.bind(this)); - this.insertNewline(); + components.flatMap(e => ["\n", e]).slice(1).forEach(e => { + if (e === "\n") + this.insertNewline(); + else + linkify(e, this.insert.bind(this)); }); - const [last] = components.slice(-1); - linkify(last, this.insert.bind(this)); } insert(text, isLink) {