From 99ac78031c8ebb1bef723b9aa1e45e11e0c4079a Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Thu, 24 Jan 2019 09:11:16 -0800 Subject: [PATCH] Remove out param from reflow large method --- src/Buffer.ts | 7 +++---- src/BufferReflow.ts | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index 286d1311..52d9572d 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -242,10 +242,9 @@ export class Buffer implements IBuffer { private _reflowLarger(newCols: number): void { const toRemove: number[] = reflowLargerGetLinesToRemove(this.lines, newCols); if (toRemove.length > 0) { - const newLayout: number[] = []; - const countRemoved = reflowLargerCreateNewLayout(this.lines, toRemove, newLayout); - reflowLargerApplyNewLayout(this.lines, newLayout); - this._reflowLargerAdjustViewport(newCols, countRemoved); + const newLayoutResult = reflowLargerCreateNewLayout(this.lines, toRemove); + reflowLargerApplyNewLayout(this.lines, newLayoutResult.layout); + this._reflowLargerAdjustViewport(newCols, newLayoutResult.countRemoved); } } diff --git a/src/BufferReflow.ts b/src/BufferReflow.ts index 51f83c18..003a3c78 100644 --- a/src/BufferReflow.ts +++ b/src/BufferReflow.ts @@ -8,6 +8,11 @@ import { CircularList, IDeleteEvent } from './common/CircularList'; import { IBufferLine } from './Types'; import { FILL_CHAR_DATA } from './Buffer'; +export interface INewLayoutResult { + layout: number[]; + countRemoved: number; +} + export function reflowLargerGetLinesToRemove(lines: CircularList, newCols: number): number[] { // Gather all BufferLines that need to be removed from the Buffer here so that they can be // batched up and only committed once @@ -85,7 +90,8 @@ export function reflowLargerGetLinesToRemove(lines: CircularList, n return toRemove; } -export function reflowLargerCreateNewLayout(lines: CircularList, toRemove: number[], newLayout: number[]): number { +export function reflowLargerCreateNewLayout(lines: CircularList, toRemove: number[]): INewLayoutResult { + const layout: number[] = []; // First iterate through the list and get the actual indexes to use for rows let nextToRemoveIndex = 0; let nextToRemoveStart = toRemove[nextToRemoveIndex]; @@ -104,10 +110,13 @@ export function reflowLargerCreateNewLayout(lines: CircularList, to countRemovedSoFar += countToRemove; nextToRemoveStart = toRemove[++nextToRemoveIndex]; } else { - newLayout.push(i); + layout.push(i); } } - return countRemovedSoFar; + return { + layout, + countRemoved: countRemovedSoFar + }; } export function reflowLargerApplyNewLayout(lines: CircularList, newLayout: number[]): void {