Fix cursor render when after focusing underline/bar

This commit is contained in:
Daniel Imms
2017-09-01 23:11:39 -07:00
parent f8ece108c6
commit 06b54585a1
+18 -9
View File
@@ -13,7 +13,7 @@ import { COLOR_CODES } from './ColorManager';
const BLINK_INTERVAL = 600; const BLINK_INTERVAL = 600;
export class CursorRenderLayer extends BaseRenderLayer { export class CursorRenderLayer extends BaseRenderLayer {
private _state: [number, number, string]; private _state: [number, number, boolean, string];
private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void}; private _cursorRenderers: {[key: string]: (terminal: ITerminal, x: number, y: number, charData: CharData) => void};
private _cursorBlinkStateManager: CursorBlinkStateManager; private _cursorBlinkStateManager: CursorBlinkStateManager;
private _isFocused: boolean; private _isFocused: boolean;
@@ -40,14 +40,14 @@ export class CursorRenderLayer extends BaseRenderLayer {
public onBlur(terminal: ITerminal): void { public onBlur(terminal: ITerminal): void {
if (this._cursorBlinkStateManager) { if (this._cursorBlinkStateManager) {
// this._cursorBlinkStateManager.pause(); this._cursorBlinkStateManager.pause();
} }
terminal.refresh(terminal.buffer.y, terminal.buffer.y); terminal.refresh(terminal.buffer.y, terminal.buffer.y);
} }
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.refresh(terminal.buffer.y, terminal.buffer.y);
} }
@@ -107,6 +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];
return; return;
} }
@@ -120,7 +121,8 @@ export class CursorRenderLayer extends BaseRenderLayer {
// The cursor is already in the correct spot, don't redraw // The cursor is already in the correct spot, don't redraw
if (this._state[0] === terminal.buffer.x && if (this._state[0] === terminal.buffer.x &&
this._state[1] === viewportRelativeCursorY && this._state[1] === viewportRelativeCursorY &&
this._state[2] === terminal.options.cursorStyle) { this._state[2] === terminal.isFocused &&
this._state[3] === terminal.options.cursorStyle) {
// TODO: Ideally cursorStyle would be stored as a number here to prevent the string compare // TODO: Ideally cursorStyle would be stored as a number here to prevent the string compare
return; return;
} }
@@ -131,7 +133,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.options.cursorStyle]; this._state = [terminal.buffer.x, viewportRelativeCursorY, terminal.isFocused, terminal.options.cursorStyle];
} }
private _clearCursor(): void { private _clearCursor(): void {
@@ -261,11 +263,18 @@ class CursorBlinkStateManager {
}, timeToStart); }, timeToStart);
} }
private _pauseBlinkAnimation(): void { public pause(): void {
// TODO: Pause the blink animation on blur this.isCursorVisible = true;
window.clearInterval(this._blinkInterval);
this._blinkInterval = null;
if (this._animationFrame) {
window.cancelAnimationFrame(this._animationFrame);
this._animationFrame = null;
}
} }
private _resumeBlinkAnimation(): void { public resume(): void {
// TODO: Resume the blink animation on focus console.log('resume');
this._restartInterval();
} }
} }