getTextAndMentionsFromOps: Trim start of first op if it's a string

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
automated-signal 2022-03-09 12:01:25 -08:00 committed by GitHub
parent 2e58e77bd2
commit 8a1c213af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -65,9 +65,10 @@ export const getTextAndMentionsFromOps = (
const mentions: Array<BodyRangeType> = []; const mentions: Array<BodyRangeType> = [];
const text = ops const text = ops
.reduce((acc, op) => { .reduce((acc, op, index) => {
if (typeof op.insert === 'string') { if (typeof op.insert === 'string') {
return acc + op.insert; const toAdd = index === 0 ? op.insert.trimStart() : op.insert;
return acc + toAdd;
} }
if (isInsertEmojiOp(op)) { if (isInsertEmojiOp(op)) {
@ -87,7 +88,7 @@ export const getTextAndMentionsFromOps = (
return acc; return acc;
}, '') }, '')
.trim(); .trimEnd(); // Trimming the start of this string will mess up mention indices
return [text, mentions]; return [text, mentions];
}; };