From 1b56f32785c910a53861980142c8bcebf87e48c8 Mon Sep 17 00:00:00 2001 From: Inaki Ibarra <16115640+ibarrain@users.noreply.github.com> Date: Fri, 13 Sep 2019 10:35:54 +0800 Subject: [PATCH] Save note file in home directory instead of workspace folder --- CHANGELOG.md | 6 +++++- README.md | 5 ++--- extension.js | 12 +++--------- package.json | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a215e7e..96442de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] -## [1.0.3] - 2019-09-12 +## [1.0.4] - 2019-09-13 +### Changed +- Save in home directory instead of workspace folder when filepath is not defined + +## [1.0.3] - 2019-09-13 ### Added - Error when there's no folder in workspace and missing filepath diff --git a/README.md b/README.md index 7bd856a..84c7e5c 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ If the Daily Notes file is already open: * Press ```Ctrl+W``` to close the file * Press ```Ctrl+S``` to save the file -If you don't want to save Daily Notes file in current workspace: +You may save your note file anywhere: -* Create a new file ```daily-notes.md```, copy the path and set the ```dailyNotes.filePath``` in config +* Create a new file ```daily-notes.md```, copy the path and set the ```dailyNotes.filePath``` in config. ## Extension Settings @@ -37,7 +37,6 @@ This extension contributes the following settings: ## Known Issues -* You may get an error 'extension.open failed' when there's no open folder in your workspace. You can fix this by setting ```dailyNotes.filePath``` in config or opening a folder first, then ```Alt+N```. * If you are using remote Windows Subsystem for Linux a.k.a WSL for VSCode, the file path format from Windows may not work. This can be solved easily by using the file path from WSL e.g. ```/mnt/c/projects```. diff --git a/extension.js b/extension.js index e4678ac..9090a2c 100644 --- a/extension.js +++ b/extension.js @@ -1,6 +1,7 @@ const vscode = require('vscode'); const fs = require('fs'); const firstline = require('firstline'); +const homedir = require('os').homedir(); /** * @param {vscode.ExtensionContext} context @@ -10,10 +11,6 @@ function activate(context) { let disposable = vscode.commands.registerCommand('extension.open', function () { const filePath = getFilePath(); - if (!filePath) { - return vscode.window.showErrorMessage("Open a folder in your workspace first or set DailyNotes.FilePath in Config"); - } - if (fs.existsSync(filePath)) { prependDateHeader(filePath); } else { @@ -21,20 +18,17 @@ function activate(context) { } vscode.workspace.openTextDocument(filePath).then(doc => { - vscode.window.showTextDocument(doc, { preview: true }); + vscode.window.showTextDocument(doc); }); }); function getFilePath() { const configFilePath = vscode.workspace.getConfiguration().get('dailyNotes.filePath'); - const workspaceFolders = vscode.workspace.workspaceFolders; if (configFilePath) { return configFilePath; - } else if (workspaceFolders && workspaceFolders.length > 0) { - return workspaceFolders[0].uri.fsPath + "/daily-notes.md"; } else { - return null; + return homedir + "/daily-notes.md"; } } diff --git a/package.json b/package.json index edda158..2be6620 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-daily-notes", "displayName": "VSCode Daily Notes", "description": "A simple text-based journal extension for Visual Studio Code", - "version": "1.0.3", + "version": "1.0.4", "icon": "images/icon.png", "engines": { "vscode": "^1.38.0"