Fix remaining cursor animation state issues
This commit is contained in:
@@ -42,14 +42,14 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
if (this._cursorBlinkStateManager) {
|
if (this._cursorBlinkStateManager) {
|
||||||
this._cursorBlinkStateManager.pause();
|
this._cursorBlinkStateManager.pause();
|
||||||
}
|
}
|
||||||
terminal.refresh(terminal.buffer.y, terminal.buffer.y);
|
terminal.emit('cursormove');
|
||||||
}
|
}
|
||||||
|
|
||||||
public onFocus(terminal: ITerminal): void {
|
public onFocus(terminal: ITerminal): void {
|
||||||
if (this._cursorBlinkStateManager) {
|
if (this._cursorBlinkStateManager) {
|
||||||
this._cursorBlinkStateManager.resume();
|
this._cursorBlinkStateManager.resume();
|
||||||
}
|
}
|
||||||
terminal.refresh(terminal.buffer.y, terminal.buffer.y);
|
terminal.emit('cursormove');
|
||||||
}
|
}
|
||||||
|
|
||||||
public onOptionsChanged(terminal: ITerminal): void {
|
public onOptionsChanged(terminal: ITerminal): void {
|
||||||
@@ -78,7 +78,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
|
|
||||||
public onGridChanged(terminal: ITerminal, startRow: number, endRow: number): void {
|
public onGridChanged(terminal: ITerminal, startRow: number, endRow: number): void {
|
||||||
// Only render if the animation frame is not active
|
// Only render if the animation frame is not active
|
||||||
if (!this._cursorBlinkStateManager) {
|
if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
|
||||||
this._render(terminal, false);
|
this._render(terminal, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
||||||
this._renderBlurCursor(terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
this._renderBlurCursor(terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
||||||
this._ctx.restore();
|
this._ctx.restore();
|
||||||
this._state = [terminal.buffer.x, viewportRelativeCursorY, terminal.isFocused, terminal.options.cursorStyle];
|
this._state = [terminal.buffer.x, viewportRelativeCursorY, false, terminal.options.cursorStyle];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,6 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
this._state[1] === viewportRelativeCursorY &&
|
this._state[1] === viewportRelativeCursorY &&
|
||||||
this._state[2] === terminal.isFocused &&
|
this._state[2] === terminal.isFocused &&
|
||||||
this._state[3] === terminal.options.cursorStyle) {
|
this._state[3] === terminal.options.cursorStyle) {
|
||||||
// TODO: Ideally cursorStyle would be stored as a number here to prevent the string compare
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._clearCursor();
|
this._clearCursor();
|
||||||
@@ -133,7 +132,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
|
|||||||
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
this._ctx.fillStyle = this.colors.ansi[COLOR_CODES.WHITE];
|
||||||
this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, terminal.buffer.x, viewportRelativeCursorY, charData);
|
||||||
this._ctx.restore();
|
this._ctx.restore();
|
||||||
this._state = [terminal.buffer.x, viewportRelativeCursorY, terminal.isFocused, terminal.options.cursorStyle];
|
this._state = [terminal.buffer.x, viewportRelativeCursorY, true, terminal.options.cursorStyle];
|
||||||
}
|
}
|
||||||
|
|
||||||
private _clearCursor(): void {
|
private _clearCursor(): void {
|
||||||
@@ -189,12 +188,22 @@ class CursorBlinkStateManager {
|
|||||||
private renderCallback: () => void
|
private renderCallback: () => void
|
||||||
) {
|
) {
|
||||||
this.isCursorVisible = true;
|
this.isCursorVisible = true;
|
||||||
this._restartInterval();
|
if (terminal.isFocused) {
|
||||||
|
this._restartInterval();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get isPaused(): boolean { return !(this._blinkStartTimeout || this._blinkInterval); }
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
window.clearInterval(this._blinkInterval);
|
if (this._blinkInterval) {
|
||||||
this._blinkInterval = null;
|
window.clearInterval(this._blinkInterval);
|
||||||
|
this._blinkInterval = null;
|
||||||
|
}
|
||||||
|
if (this._blinkStartTimeout) {
|
||||||
|
window.clearTimeout(this._blinkStartTimeout);
|
||||||
|
this._blinkStartTimeout = null;
|
||||||
|
}
|
||||||
if (this._animationFrame) {
|
if (this._animationFrame) {
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
window.cancelAnimationFrame(this._animationFrame);
|
||||||
this._animationFrame = null;
|
this._animationFrame = null;
|
||||||
@@ -202,6 +211,9 @@ class CursorBlinkStateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public restartBlinkAnimation(terminal: ITerminal): void {
|
public restartBlinkAnimation(terminal: ITerminal): void {
|
||||||
|
if (this.isPaused) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Save a timestamp so that the restart can be done on the next interval
|
// Save a timestamp so that the restart can be done on the next interval
|
||||||
this._animationTimeRestarted = Date.now();
|
this._animationTimeRestarted = Date.now();
|
||||||
// Force a cursor render to ensure it's visible and in the correct position
|
// Force a cursor render to ensure it's visible and in the correct position
|
||||||
@@ -230,8 +242,10 @@ class CursorBlinkStateManager {
|
|||||||
if (this._animationTimeRestarted) {
|
if (this._animationTimeRestarted) {
|
||||||
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
const time = BLINK_INTERVAL - (Date.now() - this._animationTimeRestarted);
|
||||||
this._animationTimeRestarted = null;
|
this._animationTimeRestarted = null;
|
||||||
this._restartInterval(time);
|
if (time > 0) {
|
||||||
return;
|
this._restartInterval(time);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the cursor
|
// Hide the cursor
|
||||||
@@ -265,8 +279,14 @@ class CursorBlinkStateManager {
|
|||||||
|
|
||||||
public pause(): void {
|
public pause(): void {
|
||||||
this.isCursorVisible = true;
|
this.isCursorVisible = true;
|
||||||
window.clearInterval(this._blinkInterval);
|
if (this._blinkInterval) {
|
||||||
this._blinkInterval = null;
|
window.clearInterval(this._blinkInterval);
|
||||||
|
this._blinkInterval = null;
|
||||||
|
}
|
||||||
|
if (this._blinkStartTimeout) {
|
||||||
|
window.clearTimeout(this._blinkStartTimeout);
|
||||||
|
this._blinkStartTimeout = null;
|
||||||
|
}
|
||||||
if (this._animationFrame) {
|
if (this._animationFrame) {
|
||||||
window.cancelAnimationFrame(this._animationFrame);
|
window.cancelAnimationFrame(this._animationFrame);
|
||||||
this._animationFrame = null;
|
this._animationFrame = null;
|
||||||
@@ -274,7 +294,7 @@ class CursorBlinkStateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public resume(): void {
|
public resume(): void {
|
||||||
console.log('resume');
|
this._animationTimeRestarted = null;
|
||||||
this._restartInterval();
|
this._restartInterval();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ export class Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setTheme(theme: ITheme): void {
|
public setTheme(theme: ITheme): void {
|
||||||
console.log('setTheme');
|
|
||||||
this._colorManager.setTheme(theme);
|
this._colorManager.setTheme(theme);
|
||||||
// Clear layers and force a full render
|
// Clear layers and force a full render
|
||||||
this._renderLayers.forEach(l => {
|
this._renderLayers.forEach(l => {
|
||||||
|
|||||||
Reference in New Issue
Block a user