optimization: remove document fragment

This commit is contained in:
Jörg Breitbart
2023-07-29 23:58:15 +02:00
parent 5f98db9b76
commit 64d04f0712
3 changed files with 76 additions and 76 deletions
+2 -2
View File
@@ -369,7 +369,7 @@ export class DomRenderer extends Disposable implements IRenderer {
break; break;
} }
rowElement.replaceChildren( rowElement.replaceChildren(
this._rowFactory.createRow( ...this._rowFactory.createRow(
lineData, lineData,
row, row,
row === cursorAbsoluteY, row === cursorAbsoluteY,
@@ -436,7 +436,7 @@ export class DomRenderer extends Disposable implements IRenderer {
break; break;
} }
rowElement.replaceChildren( rowElement.replaceChildren(
this._rowFactory.createRow( ...this._rowFactory.createRow(
bufferline, bufferline,
row, row,
row === cursorAbsoluteY, row === cursorAbsoluteY,
@@ -47,8 +47,8 @@ describe('DomRendererRowFactory', () => {
describe('createRow', () => { describe('createRow', () => {
it('should not create anything for an empty row', () => { it('should not create anything for an empty row', () => {
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'' ''
); );
}); });
@@ -58,24 +58,24 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, '語', 2, '語'.charCodeAt(0)])); lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, '語', 2, '語'.charCodeAt(0)]));
// There should be no element for the following "empty" cell // There should be no element for the following "empty" cell
lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, '', 0, 0])); lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, '', 0, 0]));
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span>語</span>' '<span>語</span>'
); );
}); });
it('should add class for cursor and cursor style', () => { it('should add class for cursor and cursor style', () => {
for (const style of ['block', 'bar', 'underline']) { for (const style of ['block', 'bar', 'underline']) {
const fragment = rowFactory.createRow(lineData, 0, true, style, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, true, style, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
`<span class="xterm-cursor xterm-cursor-${style}"> </span>` `<span class="xterm-cursor xterm-cursor-${style}"> </span>`
); );
} }
}); });
it('should add class for cursor blink', () => { it('should add class for cursor blink', () => {
const fragment = rowFactory.createRow(lineData, 0, true, 'block', 0, true, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, true, 'block', 0, true, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
`<span class="xterm-cursor xterm-cursor-blink xterm-cursor-block"> </span>` `<span class="xterm-cursor xterm-cursor-blink xterm-cursor-block"> </span>`
); );
}); });
@@ -85,8 +85,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.fg = DEFAULT_ATTR_DATA.fg | FgFlags.BOLD; cell.fg = DEFAULT_ATTR_DATA.fg | FgFlags.BOLD;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bold">a</span>' '<span class="xterm-bold">a</span>'
); );
}); });
@@ -95,8 +95,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.ITALIC; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.ITALIC;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-italic">a</span>' '<span class="xterm-italic">a</span>'
); );
}); });
@@ -105,8 +105,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.DIM; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.DIM;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-dim">a</span>' '<span class="xterm-dim">a</span>'
); );
}); });
@@ -118,8 +118,8 @@ describe('DomRendererRowFactory', () => {
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED;
cell.extended.underlineStyle = UnderlineStyle.SINGLE; cell.extended.underlineStyle = UnderlineStyle.SINGLE;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-underline-1">a</span>' '<span class="xterm-underline-1">a</span>'
); );
}); });
@@ -129,8 +129,8 @@ describe('DomRendererRowFactory', () => {
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED;
cell.extended.underlineStyle = UnderlineStyle.DOUBLE; cell.extended.underlineStyle = UnderlineStyle.DOUBLE;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-underline-2">a</span>' '<span class="xterm-underline-2">a</span>'
); );
}); });
@@ -140,8 +140,8 @@ describe('DomRendererRowFactory', () => {
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED;
cell.extended.underlineStyle = UnderlineStyle.CURLY; cell.extended.underlineStyle = UnderlineStyle.CURLY;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-underline-3">a</span>' '<span class="xterm-underline-3">a</span>'
); );
}); });
@@ -151,8 +151,8 @@ describe('DomRendererRowFactory', () => {
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED;
cell.extended.underlineStyle = UnderlineStyle.DOTTED; cell.extended.underlineStyle = UnderlineStyle.DOTTED;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-underline-4">a</span>' '<span class="xterm-underline-4">a</span>'
); );
}); });
@@ -162,8 +162,8 @@ describe('DomRendererRowFactory', () => {
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.HAS_EXTENDED;
cell.extended.underlineStyle = UnderlineStyle.DASHED; cell.extended.underlineStyle = UnderlineStyle.DASHED;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-underline-5">a</span>' '<span class="xterm-underline-5">a</span>'
); );
}); });
@@ -173,8 +173,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.OVERLINE; cell.bg = DEFAULT_ATTR_DATA.bg | BgFlags.OVERLINE;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-overline">a</span>' '<span class="xterm-overline">a</span>'
); );
}); });
@@ -183,8 +183,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.fg = DEFAULT_ATTR_DATA.fg | FgFlags.STRIKETHROUGH; cell.fg = DEFAULT_ATTR_DATA.fg | FgFlags.STRIKETHROUGH;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-strikethrough">a</span>' '<span class="xterm-strikethrough">a</span>'
); );
}); });
@@ -196,8 +196,8 @@ describe('DomRendererRowFactory', () => {
cell.fg &= ~Attributes.PCOLOR_MASK; cell.fg &= ~Attributes.PCOLOR_MASK;
cell.fg |= i; cell.fg |= i;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
`<span class="xterm-fg-${i}">a</span>` `<span class="xterm-fg-${i}">a</span>`
); );
} }
@@ -210,8 +210,8 @@ describe('DomRendererRowFactory', () => {
cell.bg &= ~Attributes.PCOLOR_MASK; cell.bg &= ~Attributes.PCOLOR_MASK;
cell.bg |= i; cell.bg |= i;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
`<span class="xterm-bg-${i}">a</span>` `<span class="xterm-bg-${i}">a</span>`
); );
} }
@@ -222,8 +222,8 @@ describe('DomRendererRowFactory', () => {
cell.fg |= Attributes.CM_P16 | 2 | FgFlags.INVERSE; cell.fg |= Attributes.CM_P16 | 2 | FgFlags.INVERSE;
cell.bg |= Attributes.CM_P16 | 1; cell.bg |= Attributes.CM_P16 | 1;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-2 xterm-fg-1">a</span>' '<span class="xterm-bg-2 xterm-fg-1">a</span>'
); );
}); });
@@ -233,8 +233,8 @@ describe('DomRendererRowFactory', () => {
cell.fg |= FgFlags.INVERSE; cell.fg |= FgFlags.INVERSE;
cell.bg |= Attributes.CM_P16 | 1; cell.bg |= Attributes.CM_P16 | 1;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-257 xterm-fg-1">a</span>' '<span class="xterm-bg-257 xterm-fg-1">a</span>'
); );
}); });
@@ -243,8 +243,8 @@ describe('DomRendererRowFactory', () => {
const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]); const cell = CellData.fromCharData([0, 'a', 1, 'a'.charCodeAt(0)]);
cell.fg |= Attributes.CM_P16 | 1 | FgFlags.INVERSE; cell.fg |= Attributes.CM_P16 | 1 | FgFlags.INVERSE;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-1 xterm-fg-257">a</span>' '<span class="xterm-bg-1 xterm-fg-257">a</span>'
); );
}); });
@@ -256,8 +256,8 @@ describe('DomRendererRowFactory', () => {
cell.fg &= ~Attributes.PCOLOR_MASK; cell.fg &= ~Attributes.PCOLOR_MASK;
cell.fg |= i; cell.fg |= i;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
`<span class="xterm-bold xterm-fg-${i + 8}">a</span>` `<span class="xterm-bold xterm-fg-${i + 8}">a</span>`
); );
} }
@@ -268,8 +268,8 @@ describe('DomRendererRowFactory', () => {
cell.fg |= Attributes.CM_RGB | 1 << 16 | 2 << 8 | 3; cell.fg |= Attributes.CM_RGB | 1 << 16 | 2 << 8 | 3;
cell.bg |= Attributes.CM_RGB | 4 << 16 | 5 << 8 | 6; cell.bg |= Attributes.CM_RGB | 4 << 16 | 5 << 8 | 6;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span style="background-color:#040506;color:#010203;">a</span>' '<span style="background-color:#040506;color:#010203;">a</span>'
); );
}); });
@@ -279,8 +279,8 @@ describe('DomRendererRowFactory', () => {
cell.fg |= Attributes.CM_RGB | 1 << 16 | 2 << 8 | 3 | FgFlags.INVERSE; cell.fg |= Attributes.CM_RGB | 1 << 16 | 2 << 8 | 3 | FgFlags.INVERSE;
cell.bg |= Attributes.CM_RGB | 4 << 16 | 5 << 8 | 6; cell.bg |= Attributes.CM_RGB | 4 << 16 | 5 << 8 | 6;
lineData.setCell(0, cell); lineData.setCell(0, cell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span style="background-color:#010203;color:#040506;">a</span>' '<span style="background-color:#010203;color:#040506;">a</span>'
); );
}); });
@@ -291,16 +291,16 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)])); lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]));
lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)])); lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)]));
rowFactory.handleSelectionChanged([1, 0], [2, 0], false); rowFactory.handleSelectionChanged([1, 0], [2, 0], false);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span>a</span><span class="xterm-decoration-top">b</span>' '<span>a</span><span class="xterm-decoration-top">b</span>'
); );
}); });
it('should force whitespace cells to be rendered above the background', () => { it('should force whitespace cells to be rendered above the background', () => {
lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)])); lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]));
rowFactory.handleSelectionChanged([0, 0], [2, 0], false); rowFactory.handleSelectionChanged([0, 0], [2, 0], false);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-decoration-top"> </span><span class="xterm-decoration-top">a</span>' '<span class="xterm-decoration-top"> </span><span class="xterm-decoration-top">a</span>'
); );
}); });
@@ -316,8 +316,8 @@ describe('DomRendererRowFactory', () => {
}); });
it('should not create anything for an empty row', () => { it('should not create anything for an empty row', () => {
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'' ''
); );
}); });
@@ -326,8 +326,8 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)])); lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]));
lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)])); lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)]));
lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'c', 1, 'c'.charCodeAt(0)])); lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'c', 1, 'c'.charCodeAt(0)]));
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span>abc</span>' '<span>abc</span>'
); );
}); });
@@ -337,8 +337,8 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)])); lineData.setCell(0, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]));
lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, '€', 1, '€'.charCodeAt(0)])); lineData.setCell(1, CellData.fromCharData([DEFAULT_ATTR, '€', 1, '€'.charCodeAt(0)]));
lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'c', 1, 'c'.charCodeAt(0)])); lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'c', 1, 'c'.charCodeAt(0)]));
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span>a</span><span style="letter-spacing: 3px;">€</span><span>c</span>' '<span>a</span><span style="letter-spacing: 3px;">€</span><span>c</span>'
); );
}); });
@@ -352,8 +352,8 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(1, aColor1); lineData.setCell(1, aColor1);
lineData.setCell(2, bColor2); lineData.setCell(2, bColor2);
lineData.setCell(3, bColor2); lineData.setCell(3, bColor2);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-fg-1">aa</span><span class="xterm-fg-2">bb</span>' '<span class="xterm-fg-1">aa</span><span class="xterm-fg-2">bb</span>'
); );
}); });
@@ -364,8 +364,8 @@ describe('DomRendererRowFactory', () => {
lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'X', 1, 'X'.charCodeAt(0)])); lineData.setCell(2, CellData.fromCharData([DEFAULT_ATTR, 'X', 1, 'X'.charCodeAt(0)]));
lineData.setCell(3, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)])); lineData.setCell(3, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)]));
lineData.setCell(4, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)])); lineData.setCell(4, CellData.fromCharData([DEFAULT_ATTR, 'b', 1, 'b'.charCodeAt(0)]));
const fragment = rowFactory.createRow(lineData, 0, true, undefined, 2, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, true, undefined, 2, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span>aa</span><span class="xterm-cursor xterm-cursor-block">X</span><span>bb</span>' '<span>aa</span><span class="xterm-cursor xterm-cursor-block">X</span><span>bb</span>'
); );
}); });
@@ -377,8 +377,8 @@ describe('DomRendererRowFactory', () => {
nullCell.bg = Attributes.CM_P16 | 2; nullCell.bg = Attributes.CM_P16 | 2;
lineData.setCell(3, nullCell); lineData.setCell(3, nullCell);
lineData.setCell(4, nullCell); lineData.setCell(4, nullCell);
const fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); const spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span> </span><span class="xterm-bg-1"> </span><span class="xterm-bg-2"> </span>' '<span> </span><span class="xterm-bg-1"> </span><span class="xterm-bg-2"> </span>'
); );
}); });
@@ -387,33 +387,33 @@ describe('DomRendererRowFactory', () => {
const nullCell = lineData.loadCell(0, new CellData()); const nullCell = lineData.loadCell(0, new CellData());
nullCell.bg = Attributes.CM_P16 | 1; nullCell.bg = Attributes.CM_P16 | 1;
lineData.setCell(0, nullCell); lineData.setCell(0, nullCell);
let fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); let spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-1"> </span>' '<span class="xterm-bg-1"> </span>'
); );
lineData.setCell(1, nullCell); lineData.setCell(1, nullCell);
fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-1"> </span>' '<span class="xterm-bg-1"> </span>'
); );
lineData.setCell(2, nullCell); lineData.setCell(2, nullCell);
lineData.setCell(3, nullCell); lineData.setCell(3, nullCell);
fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-1"> </span>' '<span class="xterm-bg-1"> </span>'
); );
lineData.setCell(4, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)])); lineData.setCell(4, CellData.fromCharData([DEFAULT_ATTR, 'a', 1, 'a'.charCodeAt(0)]));
fragment = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1); spans = rowFactory.createRow(lineData, 0, false, undefined, 0, false, 5, EMPTY_WIDTH, -1, -1);
assert.equal(getFragmentHtml(fragment), assert.equal(extractHtml(spans),
'<span class="xterm-bg-1"> </span><span>a</span>' '<span class="xterm-bg-1"> </span><span>a</span>'
); );
}); });
}); });
function getFragmentHtml(fragment: DocumentFragment): string { function extractHtml(spans: HTMLSpanElement[]): string {
const element = dom.window.document.createElement('div'); const element = dom.window.document.createElement('div');
element.appendChild(fragment); element.replaceChildren(...spans);
return element.innerHTML; return element.innerHTML;
} }
@@ -65,9 +65,9 @@ export class DomRendererRowFactory {
widthCache: WidthCache, widthCache: WidthCache,
linkStart: number, linkStart: number,
linkEnd: number linkEnd: number
): DocumentFragment { ): HTMLSpanElement[] {
const fragment = this._document.createDocumentFragment(); const elements: HTMLSpanElement[] = [];
const joinedRanges = this._characterJoinerService.getJoinedCharacters(row); const joinedRanges = this._characterJoinerService.getJoinedCharacters(row);
const colors = this._themeService.colors; const colors = this._themeService.colors;
@@ -394,7 +394,7 @@ export class DomRendererRowFactory {
charElement.style.letterSpacing = `${spacing}px`; charElement.style.letterSpacing = `${spacing}px`;
} }
fragment.appendChild(charElement); elements.push(charElement);
x = lastCharX; x = lastCharX;
} }
@@ -403,7 +403,7 @@ export class DomRendererRowFactory {
charElement.textContent = text; charElement.textContent = text;
} }
return fragment; return elements;
} }
private _applyMinimumContrast(element: HTMLElement, bg: IColor, fg: IColor, cell: ICellData, bgOverride: IColor | undefined, fgOverride: IColor | undefined): boolean { private _applyMinimumContrast(element: HTMLElement, bg: IColor, fg: IColor, cell: ICellData, bgOverride: IColor | undefined, fgOverride: IColor | undefined): boolean {