Skip to content

Commit

Permalink
Update extension
Browse files Browse the repository at this point in the history
- Does not enforces folding when view state was remembered (This behavior is now handled by `workbench.editor.restoreViewState`)
- Validates default fold level configuration value
- Renames configuration section

See #9, https://code.visualstudio.com/updates/v1_28#_do-not-restore-view-state-when-reopening-a-file
  • Loading branch information
felicio committed Nov 25, 2018
1 parent e1dea2e commit 5011151
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jsconfig.json
vsc-extension-quickstart.md
.eslintrc.js
.todo
.checklist
.gitattributes
.prettierrc
.editorconfig
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ indented lines to the default `fold.level` set in User Settings. Already
opened documents can be folded to the default level with **Fold Level
Default** command from **Command Palette**.

## Features

- Automatic folding
- Fold Level Default command


## Usage

Team @code does host a decent documentation suite and
Expand All @@ -16,17 +22,10 @@ chapter is a good example of it. Below is an extract of available fold
actions and their respective keybindings to really help you get the most out
of this extension.

- Unfold (`⌥⌘]`) unfolds the collapsed region at the cursor
- Fold (`⌥⌘[`) folds the innermost uncollapsed region at the cursor
- Unfold All (`⌘K ⌘J`) unfolds all regions in the editor
- Unfold (`⌥⌘]`) unfolds the collapsed region at the cursor
- Fold All (`⌘K ⌘0`) folds all region in the editor

## Known issues

> **Note**: Listed issues are challenging due to the fact
them being rooted in the functionality VS Code extenisbility API exposes, or
the lack thereof.

- Folding does not apply for documents that did **not** gain focus (e.g. Open to Side action triggered by `⌃Click`)
- If document begins with a folding region (e.g. `package.json`) applicable
fold level **cannot** be lower than `2`.
- Unfold All (`⌘K ⌘J`) unfolds all regions in the editor
- Fold All Block Comments (`⌘K ⌘/`) folds all regions that start with a block comment token
- Fold Marker Regions (`⌘K ⌘8`) folds all marker regions
- Unfold Marker Regions (`⌘K ⌘9`) unfolds all marker regions
22 changes: 7 additions & 15 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ exports.activate = context => {
const activeTextDocument = activeTextEditor.document;

if (!documents.includes(activeTextDocument)) {
activeTextEditor.selection = setCursorPosition();

foldLevelDefault(activeTextDocument.uri);
}

Expand All @@ -35,25 +33,19 @@ exports.activate = context => {
};

/**
* Folds regions of default level and all their inner regions.
* 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);
const level = configuration.get('level');
let level = configuration.get('level');

if (level <= 0 || level > 7) {
level = 2 // Extension default set in package.json
}

vscode.commands.executeCommand('editor.unfoldAll');
vscode.commands.executeCommand(`editor.foldLevel${level}`);
for (let i = level + 1; i <= 7; i++) {
for (let i = level; i <= 7; i++) {
vscode.commands.executeCommand(`editor.foldLevel${i}`);
}
}

/**
* Returns empty selection positioned to beginning of text document.
*/
function setCursorPosition() {
const position = new vscode.Position(0, 0);

return new vscode.Selection(position, position);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"configuration": {
"title": "Fold Configuration",
"title": "Fold",
"properties": {
"fold.level": {
"type": "number",
Expand Down

0 comments on commit 5011151

Please sign in to comment.