Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe('collapse function', () => {
const ttree = makeTTree('<span><span>foo </span><span> bar</span></span>');
expect(ttree).toMatchSnapshot();
});
it('should preserve boundary spaces wrapped in nested inline phrasing tags', () => {
const ttree = makeTTree(
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
);
const [firstSpan, secondSpan] = ttree.children;
expect(firstSpan.tagName).toBe('span');
expect(firstSpan.children).toHaveLength(2);
expect((firstSpan.children[0] as TTextImpl).data).toBe('foo');
expect((firstSpan.children[1] as TTextImpl).data).toBe(' ');
expect(secondSpan.tagName).toBe('span');
expect(secondSpan.children).toHaveLength(1);
expect((secondSpan.children[0] as TTextImpl).data).toBe('bar');
});
it('should handle nested anchors', () => {
const ttree = makeTTree(nestedHyperlinksSource);
expect(ttree).toMatchSnapshot();
Expand Down
8 changes: 6 additions & 2 deletions packages/transient-render-engine/src/tree/TPhrasingCtor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ TPhrasingCtor.prototype.collapseChildren = function collapseChildren() {
}
previous = childK;
});
this.trimLeft();
this.trimRight();
// Preserve boundary spaces for named inline wrappers (e.g. styled spans) so
// their parent phrasing container can collapse sibling boundaries correctly.
if (this.tagName === null) {
this.trimLeft();
this.trimRight();
}
return null;
};

Expand Down