Skip to content

Commit 9ec9dca

Browse files
authored
Merge pull request #5009 from Tyriar/tyriar/4987
Fix dom cursor blink animation and improve readability
2 parents e2dc01c + a4f1299 commit 9ec9dca

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/browser/renderer/dom/DomRenderer.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,23 @@ export class DomRenderer extends Disposable implements IRenderer {
183183
` font-style: italic;` +
184184
`}`;
185185
// Blink animation
186+
const blinkAnimationUnderlineId = `blink_underline_${this._terminalClass}`;
187+
const blinkAnimationBarId = `blink_bar_${this._terminalClass}`;
188+
const blinkAnimationBlockId = `blink_block_${this._terminalClass}`;
186189
styles +=
187-
`@keyframes blink_box_shadow` + `_` + this._terminalClass + ` {` +
190+
`@keyframes ${blinkAnimationUnderlineId} {` +
188191
` 50% {` +
189192
` border-bottom-style: hidden;` +
190193
` }` +
191194
`}`;
192195
styles +=
193-
`@keyframes blink_block` + `_` + this._terminalClass + ` {` +
196+
`@keyframes ${blinkAnimationBarId} {` +
197+
` 50% {` +
198+
` box-shadow: none;` +
199+
` }` +
200+
`}`;
201+
styles +=
202+
`@keyframes ${blinkAnimationBlockId} {` +
194203
` 0% {` +
195204
` background-color: ${colors.cursor.css};` +
196205
` color: ${colors.cursorAccent.css};` +
@@ -202,13 +211,23 @@ export class DomRenderer extends Disposable implements IRenderer {
202211
`}`;
203212
// Cursor
204213
styles +=
205-
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_BLINK_CLASS}:not(.${RowCss.CURSOR_STYLE_BLOCK_CLASS}) {` +
206-
` animation: blink_box_shadow` + `_` + this._terminalClass + ` 1s step-end infinite;` +
214+
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_BLINK_CLASS}.${RowCss.CURSOR_STYLE_UNDERLINE_CLASS} {` +
215+
` animation: ${blinkAnimationUnderlineId} 1s step-end infinite;` +
216+
`}` +
217+
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_BLINK_CLASS}.${RowCss.CURSOR_STYLE_BAR_CLASS} {` +
218+
` animation: ${blinkAnimationBarId} 1s step-end infinite;` +
207219
`}` +
208220
`${this._terminalSelector} .${ROW_CONTAINER_CLASS}.${FOCUS_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_BLINK_CLASS}.${RowCss.CURSOR_STYLE_BLOCK_CLASS} {` +
209-
` animation: blink_block` + `_` + this._terminalClass + ` 1s step-end infinite;` +
221+
` animation: ${blinkAnimationBlockId} 1s step-end infinite;` +
210222
`}` +
223+
// !important helps fix an issue where the cursor will not render on top of the selection,
224+
// however it's very hard to fix this issue and retain the blink animation without the use of
225+
// !important. So this edge case fails when cursor blink is on.
211226
`${this._terminalSelector} .${ROW_CONTAINER_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_STYLE_BLOCK_CLASS} {` +
227+
` background-color: ${colors.cursor.css};` +
228+
` color: ${colors.cursorAccent.css};` +
229+
`}` +
230+
`${this._terminalSelector} .${ROW_CONTAINER_CLASS} .${RowCss.CURSOR_CLASS}.${RowCss.CURSOR_STYLE_BLOCK_CLASS}:not(.${RowCss.CURSOR_BLINK_CLASS}) {` +
212231
` background-color: ${colors.cursor.css} !important;` +
213232
` color: ${colors.cursorAccent.css} !important;` +
214233
`}` +

test/playwright/SharedRendererTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { IImage32, decodePng } from '@lunapaint/png-codec';
77
import { LocatorScreenshotOptions, test } from '@playwright/test';
88
import { ITheme } from '@xterm/xterm';
9-
import { ITestContext, MaybeAsync, openTerminal, pollFor, pollForApproximate, timeout } from './TestUtils';
9+
import { ITestContext, MaybeAsync, openTerminal, pollFor, pollForApproximate } from './TestUtils';
1010

1111
export interface ISharedRendererTestContext {
1212
value: ITestContext;

0 commit comments

Comments
 (0)