Return undefined if cell or line doesn't exist

This commit is contained in:
Daniel Imms
2019-05-11 20:46:55 -07:00
parent cd3f2609d6
commit f41e00ed97
2 changed files with 10 additions and 5 deletions
+7 -2
View File
@@ -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);
}
+3 -3
View File
@@ -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.
*/