Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vikyd committed Apr 28, 2018
0 parents commit 6992301
Show file tree
Hide file tree
Showing 19 changed files with 2,621 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
out/
node_modules/
.vscode-test/
*.vsix
yarn-error.log
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"eg2.tslint"
]
}
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
}
}
20 changes: 20 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
out/test/**
out/**/*.map
src/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
tslint.json
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log
All notable changes to the "vscode-ext-01" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- Initial release
Binary file added FoldLevel-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Fold Level

Additional Fold Commands for VS Code.

Like PhpStorm: [`Expand to level | 1, 2, 3, 4 or 5`](https://www.jetbrains.com/help/idea/code-folding.html#folding_menu)


# Usage & Commands

Set shortcuts:

* Press
* Mac: `Command + Shift + p`
* Win: `Ctrl + Shift + p`
* `Open Keyboard Shortcuts File`
* Append:
```json
{
"key": "alt+1",
"command": "vikyd.FoldLevel.level1"
},
{
"key": "alt+2",
"command": "vikyd.FoldLevel.level2"
},
{
"key": "alt+3",
"command": "vikyd.FoldLevel.level3"
},
{
"key": "alt+4",
"command": "vikyd.FoldLevel.level4"
},
{
"key": "alt+5",
"command": "vikyd.FoldLevel.level5"
},
{
"key": "alt+6",
"command": "vikyd.FoldLevel.level6"
}
```

# Thanks
- https://github.com/vikyd/vscode-extension-common
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "vscode-fold-level",
"displayName": "Fold Level",
"description": "easier to fold code",
"version": "0.0.3",
"publisher": "vikyd",
"icon": "FoldLevel-logo.png",
"repository": {
"type": "git",
"url": "https://github.com/vikyd/vscode-ext-foldlevel"
},
"engines": {
"vscode": "^1.22.0"
},
"categories": ["Other"],
"activationEvents": [
"onCommand:vikyd.FoldLevel.level1",
"onCommand:vikyd.FoldLevel.level2",
"onCommand:vikyd.FoldLevel.level3",
"onCommand:vikyd.FoldLevel.level4",
"onCommand:vikyd.FoldLevel.level5",
"onCommand:vikyd.FoldLevel.level6"
],
"main": "./out/extension",
"contributes": {
"commands": [
{
"command": "vikyd.FoldLevel.level1",
"title": "Fold All to Level1 (FoldLevel)"
},
{
"command": "vikyd.FoldLevel.level2",
"title": "Fold All to Level2 (FoldLevel)"
},
{
"command": "vikyd.FoldLevel.level3",
"title": "Fold All to Level3 (FoldLevel)"
},
{
"command": "vikyd.FoldLevel.level4",
"title": "Fold All to Level4 (FoldLevel)"
},
{
"command": "vikyd.FoldLevel.level5",
"title": "Fold All to Level5 (FoldLevel)"
},
{
"command": "vikyd.FoldLevel.level6",
"title": "Fold All to Level6 (FoldLevel)"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.6.1",
"vscode": "^1.1.6",
"tslint": "^5.8.0",
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42"
}
}
74 changes: 74 additions & 0 deletions src/FoldLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"use strict";
import * as vscode from "vscode";
// ↓ https://github.com/dakaraphi/vscode-extension-common
import { Lines } from "./ext-common";

function setToParentLevelSelection(textEditor, targetLevel, originLineNum) {
const parentLine = Lines.findNextLineUpSpacedLeft(
textEditor.document,
textEditor.selection.active.line,
+textEditor.options.tabSize
);

if (!parentLine) {
// find upward to guess if there is a higher level line
// equal means: origin line's level is higher than target level
if (originLineNum === textEditor.selection.active.line) {
let upperLineNum = textEditor.selection.active.line - 1;
if (upperLineNum >= 0) {
let line = textEditor.document.lineAt(upperLineNum);
if (!line.text) {
textEditor.selection = new vscode.Selection(
upperLineNum,
0,
upperLineNum,
0
);
}
}
return;
}

let wantLineNum = textEditor.selection.active.line - 1;

if (wantLineNum === 0) {
// no more lines before
return;
}

textEditor.selection = new vscode.Selection(wantLineNum, 0, wantLineNum, 0);
return;
}

const parentLevel = Lines.calculateLineLevel(
textEditor,
parentLine.lineNumber
);
if (parentLevel < targetLevel) {
return;
}

textEditor.selection = new vscode.Selection(
parentLine.lineNumber,
0,
parentLine.lineNumber,
0
);
setToParentLevelSelection(textEditor, targetLevel, originLineNum);
}

export function level(targetLevel) {
const textEditor = vscode.window.activeTextEditor;

setToParentLevelSelection(
textEditor,
targetLevel,
textEditor.selection.active.line
);

vscode.commands
.executeCommand("editor.unfoldAll")
.then(() =>
vscode.commands.executeCommand("editor.foldLevel" + targetLevel)
);
}
Loading

0 comments on commit 6992301

Please sign in to comment.