diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index 08e268f1801b4693432f18f9ef832f3ff7cc1e2a..2bc38f26a22923c3ca58a1aafeb7e700f49073cd 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -587,11 +587,6 @@ export interface ITextModel { */ getLinesContent(): string[]; - /** - * @internal - */ - getIndentLevel(lineNumber: number): number; - /** * Get the end of line sequence predominantly used in the text buffer. * @return EOL char sequence (e.g.: '\n' or '\r\n'). diff --git a/src/vs/editor/common/model/indentRanges.ts b/src/vs/editor/common/model/indentRanges.ts index 6f7c286abfa170f48236d05b64ef2cccc536f3aa..e913dfd6d52674eef0b12c04974bfc5fcd0de8ce 100644 --- a/src/vs/editor/common/model/indentRanges.ts +++ b/src/vs/editor/common/model/indentRanges.ts @@ -7,6 +7,7 @@ import { ITextModel } from 'vs/editor/common/editorCommon'; import { FoldingMarkers } from 'vs/editor/common/modes/languageConfiguration'; +import { computeIndentLevel } from 'vs/editor/common/model/modelLine'; export const MAX_FOLDING_REGIONS = 0xFFFF; @@ -78,7 +79,10 @@ export class IndentRanges { } public getIndent(index: number) { - return this._model.getIndentLevel(this.getStartLineNumber(index)); + const lineNumber = this.getStartLineNumber(index); + const tabSize = this._model.getOptions().tabSize; + const lineContent = this._model.getLineContent(lineNumber); + return computeIndentLevel(lineContent, tabSize); } public contains(index: number, line: number) { @@ -181,6 +185,8 @@ interface PreviousRegion { indent: number; line: number; marker: boolean; }; export function computeRanges(model: ITextModel, offSide: boolean, markers?: FoldingMarkers, minimumRangeSize: number = 1): IndentRanges { + const tabSize = model.getOptions().tabSize; + let result = new RangesCollector(); let pattern = void 0; @@ -192,7 +198,8 @@ export function computeRanges(model: ITextModel, offSide: boolean, markers?: Fol previousRegions.push({ indent: -1, line: model.getLineCount() + 1, marker: false }); // sentinel, to make sure there's at least one entry for (let line = model.getLineCount(); line > 0; line--) { - let indent = model.getIndentLevel(line); + let lineContent = model.getLineContent(line); + let indent = computeIndentLevel(lineContent, tabSize); let previous = previousRegions[previousRegions.length - 1]; if (indent === -1) { if (offSide && !previous.marker) { @@ -202,7 +209,7 @@ export function computeRanges(model: ITextModel, offSide: boolean, markers?: Fol continue; // only whitespace } let m; - if (pattern && (m = model.getLineContent(line).match(pattern))) { + if (pattern && (m = lineContent.match(pattern))) { // folding pattern match if (m[1]) { // start pattern match // discard all regions until the folding pattern diff --git a/src/vs/editor/common/model/modelLine.ts b/src/vs/editor/common/model/modelLine.ts index b811f40a73f6523b36697ce1ee3894e7599fe7a6..ed39a3ccc5a228f3127a010f736fe1284b4f52e5 100644 --- a/src/vs/editor/common/model/modelLine.ts +++ b/src/vs/editor/common/model/modelLine.ts @@ -27,10 +27,10 @@ var NO_OP_TOKENS_ADJUSTER: ITokensAdjuster = { /** * Returns: - * - 0 => the line consists of whitespace - * - otherwise => the indent level is returned value - 1 + * - -1 => the line consists of whitespace + * - otherwise => the indent level is returned value */ -function computePlusOneIndentLevel(line: string, tabSize: number): number { +export function computeIndentLevel(line: string, tabSize: number): number { let indent = 0; let i = 0; let len = line.length; @@ -48,10 +48,19 @@ function computePlusOneIndentLevel(line: string, tabSize: number): number { } if (i === len) { - return 0; // line only consists of whitespace + return -1; // line only consists of whitespace } - return indent + 1; + return indent; +} + +/** + * Returns: + * - 0 => the line consists of whitespace + * - otherwise => the indent level is returned value - 1 + */ +function computePlusOneIndentLevel(line: string, tabSize: number): number { + return computeIndentLevel(line, tabSize) + 1; } export interface IModelLine { diff --git a/src/vs/editor/common/model/textModel.ts b/src/vs/editor/common/model/textModel.ts index aa93b0ed106e7bae433f7d1a7cd0acd815d4299c..7004916152adf16c9f90663e2adaf577a939696e 100644 --- a/src/vs/editor/common/model/textModel.ts +++ b/src/vs/editor/common/model/textModel.ts @@ -487,15 +487,6 @@ export class TextModel implements editorCommon.ITextModel { return this._lines[lineNumber - 1].text; } - public getIndentLevel(lineNumber: number): number { - this._assertNotDisposed(); - if (lineNumber < 1 || lineNumber > this.getLineCount()) { - throw new Error('Illegal value ' + lineNumber + ' for `lineNumber`'); - } - - return this._lines[lineNumber - 1].getIndentLevel(); - } - public getLinesContent(): string[] { this._assertNotDisposed(); var r: string[] = []; diff --git a/src/vs/editor/contrib/quickFix/browser/lightBulbWidget.ts b/src/vs/editor/contrib/quickFix/browser/lightBulbWidget.ts index 3ab3d31ffe20714335c5b99ce60127a08a48d870..b920ccb714da5bc6b6331cf045d08f1a0cad55c5 100644 --- a/src/vs/editor/contrib/quickFix/browser/lightBulbWidget.ts +++ b/src/vs/editor/contrib/quickFix/browser/lightBulbWidget.ts @@ -12,6 +12,7 @@ import { GlobalMouseMoveMonitor, IStandardMouseMoveEventData, standardMouseMoveM import * as dom from 'vs/base/browser/dom'; import { ICodeEditor, IContentWidget, IContentWidgetPosition, ContentWidgetPositionPreference } from 'vs/editor/browser/editorBrowser'; import { QuickFixComputeEvent } from './quickFixModel'; +import { computeIndentLevel } from 'vs/editor/common/model/modelLine'; export class LightBulbWidget implements IDisposable, IContentWidget { @@ -138,7 +139,9 @@ export class LightBulbWidget implements IDisposable, IContentWidget { } const { lineNumber } = this._model.position; const model = this._editor.getModel(); - const indent = model.getIndentLevel(lineNumber); + const tabSize = model.getOptions().tabSize; + const lineContent = model.getLineContent(lineNumber); + const indent = computeIndentLevel(lineContent, tabSize); const lineHasSpace = config.fontInfo.spaceWidth * indent > 22; let effectiveLineNumber = lineNumber;