Skip to content

Commit

Permalink
Fixes microsoft#3486: Make constructLines friendly with hidden areas …
Browse files Browse the repository at this point in the history
…(don't remove hidden areas unless needed)
  • Loading branch information
alexdima committed Feb 26, 2016
1 parent e99b957 commit 8b702c2
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions src/vs/editor/common/viewModel/splitLinesCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class SplitLinesCollection implements ILinesCollection {
this.wrappingIndent = wrappingIndent;
this.linePositionMapperFactory = linePositionMapperFactory;

this.constructLines();
this._constructLines(true);

this.tmpIndexOfResult = {
index: 0,
Expand All @@ -294,16 +294,34 @@ export class SplitLinesCollection implements ILinesCollection {
}
}

private constructLines(): void {
private _constructLines(resetHiddenAreas:boolean): void {
this.lines = [];
this.hiddenAreasIds = [];

var line:ISplitLine,
values:number[] = [],
linesContent = this.model.getLinesContent();
if (resetHiddenAreas) {
this.hiddenAreasIds = [];
}

let values:number[] = [];
let linesContent = this.model.getLinesContent();
let lineCount = linesContent.length;

let hiddenAreas = this.hiddenAreasIds.map((areaId) => this.model.getDecorationRange(areaId)).sort(Range.compareRangesUsingStarts);
let hiddenAreaStart = 1, hiddenAreaEnd = 0;
let hiddenAreaIdx = -1;
let nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : lineCount + 2;

for (let i = 0; i < lineCount; i++) {
let lineNumber = i + 1;

if (lineNumber === nextLineNumberToUpdateHiddenArea) {
hiddenAreaIdx++;
hiddenAreaStart = hiddenAreas[hiddenAreaIdx].startLineNumber;
hiddenAreaEnd = hiddenAreas[hiddenAreaIdx].endLineNumber;
nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : lineCount + 2;
}

for (var i = 0, lineCount = linesContent.length; i < lineCount; i++) {
line = createSplitLine(this.linePositionMapperFactory, linesContent[i], this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, true);
let isInHiddenArea = (lineNumber >= hiddenAreaStart && lineNumber <= hiddenAreaEnd);
let line = createSplitLine(this.linePositionMapperFactory, linesContent[i], this.tabSize, this.wrappingColumn, this.columnsForFullWidthChar, this.wrappingIndent, !isInHiddenArea);
values[i] = line.getOutputLineCount();
this.lines[i] = line;
}
Expand Down Expand Up @@ -365,8 +383,8 @@ export class SplitLinesCollection implements ILinesCollection {
}
// END TODO@Martin: Please stop calling this method on each model change!

var newDecorations:editorCommon.IModelDeltaDecoration[] = [];
for (var i = 0; i < newRanges.length; i++) {
let newDecorations:editorCommon.IModelDeltaDecoration[] = [];
for (let i = 0; i < newRanges.length; i++) {
newDecorations.push({
range: newRanges[i],
options: {
Expand All @@ -376,13 +394,13 @@ export class SplitLinesCollection implements ILinesCollection {

this.hiddenAreasIds = this.model.deltaDecorations(this.hiddenAreasIds, newDecorations);

var hiddenAreas = newRanges;
var hiddenAreaStart = 1, hiddenAreaEnd = 0;
var hiddenAreaIdx = -1;
var nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
let hiddenAreas = newRanges;
let hiddenAreaStart = 1, hiddenAreaEnd = 0;
let hiddenAreaIdx = -1;
let nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;

for (var i = 0; i < this.lines.length; i++) {
var lineNumber = i + 1;
for (let i = 0; i < this.lines.length; i++) {
let lineNumber = i + 1;

if (lineNumber === nextLineNumberToUpdateHiddenArea) {
hiddenAreaIdx++;
Expand All @@ -391,7 +409,7 @@ export class SplitLinesCollection implements ILinesCollection {
nextLineNumberToUpdateHiddenArea = (hiddenAreaIdx + 1 < hiddenAreas.length) ? hiddenAreaEnd + 1 : this.lines.length + 2;
}

var lineChanged = false;
let lineChanged = false;
if (lineNumber >= hiddenAreaStart && lineNumber <= hiddenAreaEnd) {
// Line should be hidden
if (this.lines[i].isVisible()) {
Expand All @@ -406,7 +424,7 @@ export class SplitLinesCollection implements ILinesCollection {
}
}
if (lineChanged) {
var newOutputLineCount = this.lines[i].getOutputLineCount();
let newOutputLineCount = this.lines[i].getOutputLineCount();
this.prefixSumComputer.changeValue(i, newOutputLineCount);
}
}
Expand All @@ -420,7 +438,7 @@ export class SplitLinesCollection implements ILinesCollection {
}
this.tabSize = newTabSize;

this.constructLines();
this._constructLines(false);
emit(editorCommon.ViewEventNames.ModelFlushedEvent, null);

return true;
Expand All @@ -432,7 +450,7 @@ export class SplitLinesCollection implements ILinesCollection {
}
this.wrappingIndent = newWrappingIndent;

this.constructLines();
this._constructLines(false);
emit(editorCommon.ViewEventNames.ModelFlushedEvent, null);

return true;
Expand All @@ -444,14 +462,14 @@ export class SplitLinesCollection implements ILinesCollection {
}
this.wrappingColumn = newWrappingColumn;
this.columnsForFullWidthChar = columnsForFullWidthChar;
this.constructLines();
this._constructLines(false);
emit(editorCommon.ViewEventNames.ModelFlushedEvent, null);

return true;
}

public onModelFlushed(versionId:number, emit:(evenType:string, payload:any)=>void): void {
this.constructLines();
this._constructLines(true);
emit(editorCommon.ViewEventNames.ModelFlushedEvent, null);
}

Expand Down

0 comments on commit 8b702c2

Please sign in to comment.