Skip to content

Commit

Permalink
Add support to #2 - Secondary section
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani committed Mar 1, 2019
1 parent 1fa746d commit 5e85980
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
27 changes: 21 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,46 @@
"Snippets"
],
"activationEvents": [
"onCommand:divider.addFromCursor"
"onCommand:divider.addDividerLevel1",
"onCommand:divider.addDividerLevel2"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "divider.addFromCursor",
"title": "Divider: Add From Cursor"
"command": "divider.addDividerLevel1",
"title": "Divider: Add Divider - Level 1"
},
{
"command": "divider.addDividerLevel2",
"title": "Divider: Add Divider - Level 2"
}
],
"keybindings": [
{
"command": "divider.addFromCursor",
"command": "divider.addDividerLevel1",
"key": "alt+d",
"when": "editorTextFocus"
},
{
"command": "divider.addDividerLevel2",
"key": "alt+ctrl+d",
"when": "editorTextFocus"
}
],
"configuration": {
"type": "object",
"title": "Section Divider extension",
"properties": {
"divider.text": {
"divider.text.level1": {
"type": "string",
"default": "=",
"description": "Text that will be used to fill the section divider lines."
"description": "Text that will be used to fill the Level 1 section divider lines."
},
"divider.text.level2": {
"type": "string",
"default": "-",
"description": "Text that will be used to fill the Level 2 section divider lines."
},
"divider.endColumn": {
"type": "number",
Expand Down
20 changes: 12 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import { IndentationRenderer } from "./renderers/indentationRenderer";
// ============================================================================
export function activate(context: vscode.ExtensionContext): void {

// FROM CURSOR
const fromCursor = vscode.commands.registerCommand("divider.addFromCursor", () => {
// prepare selection
// ADD DIVIDER - LEVEL 1
const addDividerLevel1 = vscode.commands.registerCommand("divider.addDividerLevel1", () => {
const currentSelection = vscode.window.activeTextEditor.selection;
insertDivider(currentSelection, 1);
});
context.subscriptions.push(addDividerLevel1);

// insert
insertDivider(currentSelection);
// ADD DIVIDER - LEVEL 2
const addDividerLevel2 = vscode.commands.registerCommand("divider.addDividerLevel2", () => {
const currentSelection = vscode.window.activeTextEditor.selection;
insertDivider(currentSelection, 2);
});
context.subscriptions.push(fromCursor);
context.subscriptions.push(addDividerLevel2);
}

export function deactivate(): void {
Expand All @@ -27,11 +31,11 @@ export function deactivate(): void {
// =============================================================================
// INSERT DIVIDER ENTRY POINT
// =============================================================================
function insertDivider(selection: vscode.Selection, numberOfLines?: number): void {
function insertDivider(selection: vscode.Selection, level: number, numberOfLines?: number): void {
// read config
const config = vscode.workspace.getConfiguration("divider");
const configEndColumn = config.get("endColumn", 80);
const configText = config.get("text", "=");
const configText = config.get(`text.level${level}`, "=");
let configNumberOfLines = config.get("lines", 3);
if (numberOfLines) {
configNumberOfLines = numberOfLines;
Expand Down

0 comments on commit 5e85980

Please sign in to comment.