mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-10 20:17:32 +01:00
Refactor loop
Don't handle last element separately Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
03b971d898
commit
577883a1d4
@ -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));
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user