vscode-next-note/extension.js

37 lines
1.3 KiB
JavaScript
Raw Normal View History

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
var vscode = require('vscode');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
console.log('next-note: activated');
context.subscriptions.push(vscode.commands.registerCommand('extension.sayHello', function () {
vscode.window.showInformationMessage('Hello World!');
}));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteInsertDate', function () {
var editor = vscode.window.activeTextEditor;
if (!editor) {
console.error("no active editor");
return;
};
//editor.document.getWordRangeAtPosition
var cursorEnd = editor.selection.end;
if (editor.document.lineCount > cursorEnd.line+1) {
cursorEnd.line += 1;
}
var d = new Date();
editor.edit(editBuilder => {
editBuilder.insert(cursorEnd, "## "+ d.toString() +"\n");
});
}));
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
console.log("next-note: deactivated")
}
exports.deactivate = deactivate;