Skip to content

Commit 3d440e2

Browse files
authored
Merge pull request #4763 from tisilent/fix-selection-background-domrenderer
DomRenderer draw selection inactive background correctly when unfocused
2 parents 2f2154c + a101135 commit 3d440e2

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

demo/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const xtermjsTheme = {
125125
foreground: '#F8F8F8',
126126
background: '#2D2E2C',
127127
selectionBackground: '#5DA5D533',
128+
selectionInactiveBackground: '#555555AA',
128129
black: '#1E1E1D',
129130
brightBlack: '#262625',
130131
red: '#CE5C5C',

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ <h3>Test</h3>
104104

105105
<dt>Weblinks Addon</dt>
106106
<dd><button id="weblinks-test" title="Various url conditions from demo data, hover&click to test">Test URLs</button></dd>
107-
107+
108108
<dt>Image Test</dt>
109109
<dd><button id="image-demo1">snake (sixel)</button></dd>
110110
<dd><button id="image-demo2">oranges (sixel)</button></dd>

src/browser/renderer/dom/DomRenderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export class DomRenderer extends Disposable implements IRenderer {
299299

300300
public handleBlur(): void {
301301
this._rowContainer.classList.remove(FOCUS_CLASS);
302+
this.renderRows(0, this._bufferService.rows - 1);
302303
}
303304

304305
public handleFocus(): void {

test/playwright/SharedRendererTests.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,32 @@ export function injectSharedRendererTests(ctx: ISharedRendererTestContext): void
961961
});
962962
});
963963

964+
(ctx.skipCanvasExceptions ? test.describe.skip : test.describe)('selectionInactiveBackground', async () => {
965+
test('should render the the inactive selection when not focused', async () => {
966+
const theme: ITheme = {
967+
selectionBackground: '#FF000080',
968+
selectionInactiveBackground: '#0000FF80'
969+
};
970+
await ctx.value.page.evaluate(`window.term.options.theme = ${JSON.stringify(theme)};`);
971+
await ctx.value.proxy.focus();
972+
// Check both the cursor line and another line
973+
await ctx.value.proxy.writeln('_ ');
974+
await ctx.value.proxy.write('_ ');
975+
await ctx.value.page.evaluate(`window.term.selectAll()`);
976+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [128, 0, 0, 255]);
977+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 1), [128, 0, 0, 255]);
978+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 2), [128, 0, 0, 255]);
979+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 2), [128, 0, 0, 255]);
980+
await ctx.value.page.evaluate(`document.activeElement.blur()`);
981+
frameDetails = undefined;
982+
// Selection only cell needs to be first to ensure renderer has kicked in
983+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 128, 255]);
984+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 1), [0, 0, 128, 255]);
985+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 2), [0, 0, 128, 255]);
986+
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 2), [0, 0, 128, 255]);
987+
});
988+
});
989+
964990
test.describe('allowTransparency', async () => {
965991
test.beforeEach(() => ctx.value.page.evaluate(`term.options.allowTransparency = true`));
966992

test/playwright/TestUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() =
400400
deepStrictEqual(result, val, ([
401401
`pollFor max duration exceeded.`,
402402
(`Last comparison: ` +
403-
`${typeof result === 'object' ? JSON.stringify(result) : result} !== ` +
404-
`${typeof val === 'object' ? JSON.stringify(val) : val}`),
403+
`${typeof result === 'object' ? JSON.stringify(result) : result} (actual) !== ` +
404+
`${typeof val === 'object' ? JSON.stringify(val) : val} (expected)`),
405405
`Stack: ${stack}`
406406
].join('\n')));
407407
}

0 commit comments

Comments
 (0)