Skip to content

Commit

Permalink
Merge pull request #4763 from tisilent/fix-selection-background-domre…
Browse files Browse the repository at this point in the history
…nderer

DomRenderer draw selection inactive background correctly when unfocused
  • Loading branch information
Tyriar authored Sep 9, 2023
2 parents 2f2154c + a101135 commit 3d440e2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const xtermjsTheme = {
foreground: '#F8F8F8',
background: '#2D2E2C',
selectionBackground: '#5DA5D533',
selectionInactiveBackground: '#555555AA',
black: '#1E1E1D',
brightBlack: '#262625',
red: '#CE5C5C',
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h3>Test</h3>

<dt>Weblinks Addon</dt>
<dd><button id="weblinks-test" title="Various url conditions from demo data, hover&click to test">Test URLs</button></dd>

<dt>Image Test</dt>
<dd><button id="image-demo1">snake (sixel)</button></dd>
<dd><button id="image-demo2">oranges (sixel)</button></dd>
Expand Down
1 change: 1 addition & 0 deletions src/browser/renderer/dom/DomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export class DomRenderer extends Disposable implements IRenderer {

public handleBlur(): void {
this._rowContainer.classList.remove(FOCUS_CLASS);
this.renderRows(0, this._bufferService.rows - 1);
}

public handleFocus(): void {
Expand Down
26 changes: 26 additions & 0 deletions test/playwright/SharedRendererTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,32 @@ export function injectSharedRendererTests(ctx: ISharedRendererTestContext): void
});
});

(ctx.skipCanvasExceptions ? test.describe.skip : test.describe)('selectionInactiveBackground', async () => {
test('should render the the inactive selection when not focused', async () => {
const theme: ITheme = {
selectionBackground: '#FF000080',
selectionInactiveBackground: '#0000FF80'
};
await ctx.value.page.evaluate(`window.term.options.theme = ${JSON.stringify(theme)};`);
await ctx.value.proxy.focus();
// Check both the cursor line and another line
await ctx.value.proxy.writeln('_ ');
await ctx.value.proxy.write('_ ');
await ctx.value.page.evaluate(`window.term.selectAll()`);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [128, 0, 0, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 1), [128, 0, 0, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 2), [128, 0, 0, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 2), [128, 0, 0, 255]);
await ctx.value.page.evaluate(`document.activeElement.blur()`);
frameDetails = undefined;
// Selection only cell needs to be first to ensure renderer has kicked in
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 1), [0, 0, 128, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 1), [0, 0, 128, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 1, 2), [0, 0, 128, 255]);
await pollFor(ctx.value.page, () => getCellColor(ctx.value, 2, 2), [0, 0, 128, 255]);
});
});

test.describe('allowTransparency', async () => {
test.beforeEach(() => ctx.value.page.evaluate(`term.options.allowTransparency = true`));

Expand Down
4 changes: 2 additions & 2 deletions test/playwright/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ export async function pollFor<T>(page: playwright.Page, evalOrFn: string | (() =
deepStrictEqual(result, val, ([
`pollFor max duration exceeded.`,
(`Last comparison: ` +
`${typeof result === 'object' ? JSON.stringify(result) : result} !== ` +
`${typeof val === 'object' ? JSON.stringify(val) : val}`),
`${typeof result === 'object' ? JSON.stringify(result) : result} (actual) !== ` +
`${typeof val === 'object' ? JSON.stringify(val) : val} (expected)`),
`Stack: ${stack}`
].join('\n')));
}
Expand Down

0 comments on commit 3d440e2

Please sign in to comment.