From f41e00ed97f6798dbc957bdcb9c3c049c3b56166 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 11 May 2019 20:46:55 -0700 Subject: [PATCH] Return undefined if cell or line doesn't exist --- src/public/Terminal.ts | 9 +++++++-- typings/xterm.d.ts | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/public/Terminal.ts b/src/public/Terminal.ts index ee623ca33..dd07c7358 100644 --- a/src/public/Terminal.ts +++ b/src/public/Terminal.ts @@ -180,14 +180,19 @@ class BufferApiView implements IBufferApi { public get viewportY(): number { return this._buffer.ydisp; } public get baseY(): number { return this._buffer.ybase; } public get length(): number { return this._buffer.lines.length; } - public getLine(y: number): IBufferLineApi { return new BufferLineApiView(this._buffer.lines.get(y)); } + public getLine(y: number): IBufferLineApi | undefined { return new BufferLineApiView(this._buffer.lines.get(y)); } } class BufferLineApiView implements IBufferLineApi { constructor(private _line: IBufferLine) {} public get isWrapped(): boolean { return this._line.isWrapped; } - public getCell(x: number): IBufferCellApi { return new BufferCellApiView(this._line, x); } + public getCell(x: number): IBufferCellApi | undefined { + if (x < 0 && x >= this._line.length) { + return undefined; + } + return new BufferCellApiView(this._line, x); + } public translateToString(trimRight?: boolean, startColumn?: number, endColumn?: number): string { return this._line.translateToString(trimRight, startColumn, endColumn); } diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index 00e7b215e..e9643b639 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -895,11 +895,11 @@ declare module 'xterm' { readonly length: number; /** - * Gets a line from the buffer. + * Gets a line from the buffer, or undefined if the line index does not exist. * * @param y The line index to get. */ - getLine(y: number): IBufferLine; + getLine(y: number): IBufferLine | undefined; } interface IBufferLine { @@ -909,7 +909,7 @@ declare module 'xterm' { readonly isWrapped: boolean; /** - * Gets a cell from the line. + * Gets a cell from the line, or undefined if the line index does not exist. * * @param x The character index to get. */