Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/model/utils.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { CharCode } from '../../../base/common/charCode.js';
7
8
/**
9
* Returns:
10
* - -1 => the line consists of whitespace
11
* - otherwise => the indent level is returned value
12
*/
13
export function computeIndentLevel(line: string, tabSize: number): number {
14
let indent = 0;
15
let i = 0;
16
const len = line.length;
17
18
while (i < len) {
19
const chCode = line.charCodeAt(i);
20
if (chCode === CharCode.Space) {
21
indent++;
22
} else if (chCode === CharCode.Tab) {
23
indent = indent - indent % tabSize + tabSize;
24
} else {
25
break;
26
}
27
i++;
28
}
29
30
if (i === len) {
31
return -1; // line only consists of whitespace
32
}
33
34
return indent;
35
}
36
37