getTextAndRangesFromOps: Don't trim leading whitespace if monospace

This commit is contained in:
Scott Nonnenberg 2023-11-10 15:10:39 -08:00 committed by GitHub
parent 61b4558140
commit 092936b69d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View file

@ -224,6 +224,42 @@ describe('getTextAndRangesFromOps', () => {
]);
});
it('does not trim at beginning of the message if monospace', () => {
const ops = [
{
insert: ' ',
},
{
insert: ' Text with leading ',
attributes: { monospace: true },
},
{
insert: 'whitespace!!',
attributes: { bold: true, italic: true },
},
];
const { text, bodyRanges } = getTextAndRangesFromOps(ops);
assert.equal(text, ' Text with leading whitespace!!');
assert.equal(bodyRanges.length, 3);
assert.deepEqual(bodyRanges, [
{
start: 0,
length: 20,
style: BodyRange.Style.MONOSPACE,
},
{
start: 20,
length: 12,
style: BodyRange.Style.BOLD,
},
{
start: 20,
length: 12,
style: BodyRange.Style.ITALIC,
},
]);
});
it('handles formatting of whitespace at beginning/ending of message', () => {
const ops = [
{