This commit is contained in:
Daniel Imms
2018-09-13 19:44:02 -07:00
parent 7401567856
commit cd2ac929c3
2 changed files with 7 additions and 5 deletions
+7 -4
View File
@@ -408,14 +408,17 @@ export class BufferStringIterator implements IBufferStringIterator {
private _start: number; private _start: number;
private _end: number; private _end: number;
private _current: number; private _current: number;
constructor (private _buffer: IBuffer, private _trimRight: boolean, startIndex?: number, endIndex?: number) { constructor (private _buffer: IBuffer, private _trimRight: boolean, startIndex?: number, endIndex?: number) {
this._start = startIndex || 0; this._start = startIndex || 0;
this._end = endIndex || this._buffer.lines.length; this._end = endIndex || this._buffer.lines.length;
this._current = this._start; this._current = this._start;
} }
public hasNext(): boolean { public hasNext(): boolean {
return this._current < this._end; return this._current < this._end;
} }
public next(withRanges: boolean = false): string | [{first: number, last: number}, string] { public next(withRanges: boolean = false): string | [{first: number, last: number}, string] {
const range = this._buffer.getWrappedRangeForLine(this._current); const range = this._buffer.getWrappedRangeForLine(this._current);
let result = ''; let result = '';
@@ -423,12 +426,12 @@ export class BufferStringIterator implements IBufferStringIterator {
// TODO: always apply trimRight after fixing #1685 // TODO: always apply trimRight after fixing #1685
result += this._buffer.translateBufferLineToString(i, (this._trimRight) ? i === range.last : false); result += this._buffer.translateBufferLineToString(i, (this._trimRight) ? i === range.last : false);
} }
this._current = range.last; this._current = range.last + 1;
this._current++;
return (withRanges) ? [range, result] : result; return (withRanges) ? [range, result] : result;
} }
toArray(): string[] {
const result: string[] = []; public toArray(): string[] {
const result = [];
while (this.hasNext()) { while (this.hasNext()) {
result.push(this.next() as string); result.push(this.next() as string);
} }
-1
View File
@@ -271,7 +271,6 @@ export interface ITerminalOptions extends IPublicTerminalOptions {
export interface IBufferStringIterator { export interface IBufferStringIterator {
hasNext(): boolean; hasNext(): boolean;
next(withRanges: boolean): string | [{first: number, last: number}, string]; next(withRanges: boolean): string | [{first: number, last: number}, string];
toArray(): string[];
} }
export interface IBuffer { export interface IBuffer {