Skip to content

Commit

Permalink
Exposes and adopts IViewLineTokens.getLineContent
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Nov 3, 2021
1 parent 0e72666 commit 7a6414a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/vs/editor/common/core/lineTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IViewLineTokens {
getClassName(tokenIndex: number): string;
getInlineStyle(tokenIndex: number, colorMap: string[]): string;
findTokenIndexAtOffset(offset: number): number;
getLineContent(): string;
}

export class LineTokens implements IViewLineTokens {
Expand Down Expand Up @@ -246,6 +247,10 @@ export class SlicedLineTokens implements IViewLineTokens {
}
}

public getLineContent(): string {
return this._source.getLineContent().substring(this._startOffset, this._endOffset);
}

public equals(other: IViewLineTokens): boolean {
if (other instanceof SlicedLineTokens) {
return (
Expand Down
9 changes: 1 addition & 8 deletions src/vs/editor/common/viewModel/modelLineProjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export class ModelLineProjection implements IModelLineProjection {
const injectionOffsets = lineBreakData.injectionOffsets;
const injectionOptions = lineBreakData.injectionOptions;

let lineContent: string;
let tokens: IViewLineTokens;
let inlineDecorations: null | SingleLineInlineDecoration[];
if (injectionOffsets) {
Expand All @@ -160,7 +159,6 @@ export class ModelLineProjection implements IModelLineProjection {
const lineStartOffsetInInputWithInjections = outputLineIndex > 0 ? lineBreakData.breakOffsets[outputLineIndex - 1] : 0;
const lineEndOffsetInInputWithInjections = lineBreakData.breakOffsets[outputLineIndex];

lineContent = lineTokens.getLineContent().substring(lineStartOffsetInInputWithInjections, lineEndOffsetInInputWithInjections);
tokens = lineTokens.sliceAndInflate(lineStartOffsetInInputWithInjections, lineEndOffsetInInputWithInjections, deltaStartIndex);
inlineDecorations = new Array<SingleLineInlineDecoration>();

Expand Down Expand Up @@ -194,16 +192,11 @@ export class ModelLineProjection implements IModelLineProjection {
const startOffset = this.getInputStartOffsetOfOutputLineIndex(outputLineIndex);
const endOffset = this.getInputEndOffsetOfOutputLineIndex(outputLineIndex);
const lineTokens = model.getLineTokens(modelLineNumber);
lineContent = model.getValueInRange({
startLineNumber: modelLineNumber,
startColumn: startOffset + 1,
endLineNumber: modelLineNumber,
endColumn: endOffset + 1
});
tokens = lineTokens.sliceAndInflate(startOffset, endOffset, deltaStartIndex);
inlineDecorations = null;
}

let lineContent = tokens.getLineContent();
if (outputLineIndex > 0) {
lineContent = spaces(lineBreakData.wrappedTextIndentLength) + lineContent;
}
Expand Down

0 comments on commit 7a6414a

Please sign in to comment.