Skip to content

Commit

Permalink
Avoid line feed replacement if possible in getValueInRange.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Mar 13, 2018
1 parent 7caa70c commit 5539eeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,29 @@ export class PieceTreeBase {
return new Position(1, 1);
}

public getValueInRange(range: Range): string {
public getValueInRange(range: Range, eol?: string): string {
if (range.startLineNumber === range.endLineNumber && range.startColumn === range.endColumn) {
return '';
}

let startPosition = this.nodeAt2(range.startLineNumber, range.startColumn);
let endPosition = this.nodeAt2(range.endLineNumber, range.endColumn);

return this.getValueInRange2(startPosition, endPosition);
let value = this.getValueInRange2(startPosition, endPosition);
if (eol) {
if (eol !== this._EOL || !this._EOLNormalized) {
return value.replace(/\r\n|\r|\n/g, eol);
}

if (eol === this.getEOL() && this._EOLNormalized) {
if (eol === '\r\n') {

}
return value;
}
return value.replace(/\r\n|\r|\n/g, eol);
}
return value;
}

public getValueInRange2(startPosition: NodePosition, endPosition: NodePosition): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export class PieceTreeTextBuffer implements ITextBuffer {
}

const lineEnding = this._getEndOfLine(eol);
const text = this._pieceTree.getValueInRange(range);
return text.replace(/\r\n|\r|\n/g, lineEnding);
return this._pieceTree.getValueInRange(range, lineEnding);
}

public getValueLengthInRange(range: Range, eol: EndOfLinePreference = EndOfLinePreference.TextDefined): number {
Expand Down

0 comments on commit 5539eeb

Please sign in to comment.