Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an enable/disable commands, and a config option for specifying on… #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,38 @@
"workspace"
],
"activationEvents": [
"onLanguage:markdown"
"onStartupFinished"
],
"main": "./out/extension.js",
"contributes": {
"configuration": {
"title": "Mathpad",
"properties": {
"Mathpad.filePatterns": {
"type": "array",
"default": [
".*\\.md"
],
"description": "File name patterns (regular expressions) for which to run Mathpad"
},
"Mathpad.enabled": {
"type": "boolean",
"default": false,
"description": "Enable Mathpad"
}
}
},
"commands": [
{
"command": "Mathpad.enable",
"title": "Mathpad: Enable"
},
{
"command": "Mathpad.disable",
"title": "Mathpad: Disable"
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
Expand Down
8 changes: 7 additions & 1 deletion src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import MathDocument from "./document";
import { MathJsStatic } from 'mathjs';
import { create } from "./math";
import * as path from 'path';

const decorationType = window.createTextEditorDecorationType({
after: {
Expand Down Expand Up @@ -123,7 +124,12 @@ export default class EditorDecorator implements Disposable {
}

private isMathEnabled(document: TextDocument): boolean {
return languages.match(this.documentSelector, document) > 0;
let config = workspace.getConfiguration('Mathpad');
let filePatterns = config.get('filePatterns') as [string];
let currentFileName = path.basename(document.uri.toString());
let fileMatches = filePatterns.map((pat) => new RegExp(pat).test(currentFileName));
let enabled = config.get('enabled') as boolean;
return fileMatches.some((val) => val) && enabled;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ import EditorDecorator from './decorator';
export function activate(context: vscode.ExtensionContext) {
let decorator = new EditorDecorator(context);
context.subscriptions.push(decorator);
context.subscriptions.push(vscode.commands.registerCommand('Mathpad.enable', () => {
let config = vscode.workspace.getConfiguration('Mathpad', );
config.update('enabled', true, vscode.ConfigurationTarget.Global);
setTimeout(() => {decorator.renderAll();}, 1000);
}));
context.subscriptions.push(vscode.commands.registerCommand('Mathpad.disable', () => {
let config = vscode.workspace.getConfiguration('Mathpad');
config.update('enabled', false, vscode.ConfigurationTarget.Global);
setTimeout(() => {decorator.renderAll();}, 1000);
}));
}