mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-18 23:49:20 +01:00
Move to react for newlines, emoji, and links in message body
This commit is contained in:
40
ts/components/conversation/AddNewLines.tsx
Normal file
40
ts/components/conversation/AddNewLines.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
|
||||
interface Props {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export class AddNewLines extends React.Component<Props, {}> {
|
||||
public render() {
|
||||
const { text } = this.props;
|
||||
const results: Array<any> = [];
|
||||
const FIND_NEWLINES = /\n/g;
|
||||
|
||||
let match = FIND_NEWLINES.exec(text);
|
||||
let last = 0;
|
||||
let count = 1;
|
||||
|
||||
if (!match) {
|
||||
return <span>{text}</span>;
|
||||
}
|
||||
|
||||
while (match) {
|
||||
if (last < match.index) {
|
||||
const textWithNoNewline = text.slice(last, match.index);
|
||||
results.push(<span key={count++}>{textWithNoNewline}</span>);
|
||||
}
|
||||
|
||||
results.push(<br key={count++} />);
|
||||
|
||||
// @ts-ignore
|
||||
last = FIND_NEWLINES.lastIndex;
|
||||
match = FIND_NEWLINES.exec(text);
|
||||
}
|
||||
|
||||
if (last < text.length) {
|
||||
results.push(<span key={count++}>{text.slice(last)}</span>);
|
||||
}
|
||||
|
||||
return <span>{results}</span>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user