-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
51 lines (40 loc) · 1.37 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const vscode = require('vscode');
exports.activate = context => {
const registeredFoldingCommand = vscode.commands.registerTextEditorCommand(
'fold.foldLevelDefault',
editor => foldLevelDefault(editor.document.uri)
);
let documents = vscode.workspace.textDocuments;
const changedVisibleTextEditorsListener = vscode.window.onDidChangeVisibleTextEditors(
editors => {
const activeTextEditor = vscode.window.activeTextEditor;
if (editors.length !== 0 && activeTextEditor) {
const activeTextDocument = activeTextEditor.document;
if (!documents.includes(activeTextDocument)) {
foldLevelDefault(activeTextDocument.uri);
}
documents = vscode.workspace.textDocuments;
}
}
);
context.subscriptions.push(
registeredFoldingCommand,
changedVisibleTextEditorsListener
);
};
/**
* Folds regions of default level and all their inner regions up to level 7.
* @param resourceUri
*/
function foldLevelDefault(resourceUri) {
const configuration = vscode.workspace.getConfiguration('fold', resourceUri);
let level = configuration.get('level');
if (level <= 0 || level > 7) {
level = 2 // Extension default set in package.json
}
vscode.commands.executeCommand('editor.unfoldAll');
for (let i = level; i <= 7; i++) {
vscode.commands.executeCommand(`editor.foldLevel${i}`);
}
}