Trim trailing newlines from outgoing messages
This commit is contained in:
parent
fef8c5b2f1
commit
98da8746e8
2 changed files with 13 additions and 3 deletions
|
@ -57,7 +57,8 @@ export const getTextFromOps = (ops: Array<DeltaOperation>): string =>
|
|||
break;
|
||||
}
|
||||
}
|
||||
return acc + textToAdd;
|
||||
const textWithoutNewlines = textToAdd.replace(/\n+$/, '');
|
||||
return acc + textWithoutNewlines;
|
||||
}
|
||||
|
||||
if (insert.emoji) {
|
||||
|
@ -93,7 +94,9 @@ export const getTextAndMentionsFromOps = (
|
|||
break;
|
||||
}
|
||||
}
|
||||
return acc + textToAdd;
|
||||
|
||||
const textWithoutNewlines = textToAdd.replace(/\n+$/, '');
|
||||
return acc + textWithoutNewlines;
|
||||
}
|
||||
|
||||
if (isInsertEmojiOp(op)) {
|
||||
|
|
|
@ -86,11 +86,18 @@ describe('getDeltaToRemoveStaleMentions', () => {
|
|||
describe('getTextAndMentionsFromOps', () => {
|
||||
describe('given only text', () => {
|
||||
it('returns only text trimmed', () => {
|
||||
const ops = [{ insert: ' The ' }, { insert: ' text ' }];
|
||||
const ops = [{ insert: ' The ' }, { insert: ' text \n' }];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, 'The text');
|
||||
assert.equal(resultMentions.length, 0);
|
||||
});
|
||||
|
||||
it('returns trimmed of trailing newlines', () => {
|
||||
const ops = [{ insert: ' The\ntext\n\n\n' }];
|
||||
const [resultText, resultMentions] = getTextAndMentionsFromOps(ops);
|
||||
assert.equal(resultText, 'The\ntext');
|
||||
assert.equal(resultMentions.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('given text, emoji, and mentions', () => {
|
||||
|
|
Loading…
Reference in a new issue