From 5e85980464b043ed8c349d2e5213024750369a25 Mon Sep 17 00:00:00 2001 From: Renato Dinhani Date: Fri, 1 Mar 2019 00:07:12 -0300 Subject: [PATCH] Add support to #2 - Secondary section --- package.json | 27 +++++++++++++++++++++------ src/extension.ts | 20 ++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index dae445f..a957017 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/extension.ts b/src/extension.ts index 120efa1..3c7653d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { @@ -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;