Skip to content

Commit

Permalink
Add Increment/Decrement Context commands (Closes hoovercj#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
alefragnani committed Oct 1, 2019
1 parent 2313490 commit 528c0cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@
],
"main": "./out/src/extension",
"contributes": {
"commands": [{
"commands": [
{
"command": "dimmer.ToggleDimmer",
"title": "Toggle Dimmer"
}],
},
{
"command": "dimmer.IncrementContext",
"title": "Dimmer: Increment Context"
},
{
"command": "dimmer.DecrementContext",
"title": "Dimmer: Decrement Context"
}
],
"configuration": {
"properties": {
"dimmer.enabled": {
Expand Down Expand Up @@ -78,4 +88,4 @@
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
}
}
}
13 changes: 12 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let context = 0;
let opacity = 50;
let delay = 200;
let commandScope = true;
const updateContextBy = 1;

let dimDecoration: vscode.TextEditorDecorationType;
let normalDecoration = vscode.window.createTextEditorDecorationType(<vscode.DecorationRenderOptions> {
Expand All @@ -24,10 +25,13 @@ export function activate(context: vscode.ExtensionContext) {
let commandRegistration = vscode.commands.registerCommand('dimmer.ToggleDimmer', () => {
vscode.workspace.getConfiguration('dimmer').update("enabled", !enabled, commandScope);
});
let incrementContextCommandRegistration = vscode.commands.registerCommand('dimmer.IncrementContext', () => updateContextSize(updateContextBy));
let decrementContextCommandRegistration = vscode.commands.registerCommand('dimmer.DecrementContext', () => updateContextSize(updateContextBy * -1));

initialize();

context.subscriptions.push(selectionRegistration, configRegistration, commandRegistration, textEditorChangeRegistration);
context.subscriptions.push(selectionRegistration, configRegistration, commandRegistration, incrementContextCommandRegistration,
decrementContextCommandRegistration, textEditorChangeRegistration);
}

function updateIfEnabled(textEditor: vscode.TextEditor) {
Expand Down Expand Up @@ -126,6 +130,13 @@ function dimEditor(editor: vscode.TextEditor) {
editor.setDecorations(dimDecoration, [new vscode.Range(startPosition, endPosition)]);
}

function updateContextSize(updateBy: number) {
let config = vscode.workspace.getConfiguration('dimmer');
context = config.get('context', 0);
context += updateBy;
config.update('context', context);
}

export function deactivate() {
resetAllDecorations();
}

0 comments on commit 528c0cf

Please sign in to comment.