From 27f2a5bb8dc75ebe097adc8bd9a43cb095e6ff6d Mon Sep 17 00:00:00 2001 From: Seongjae Lee Date: Sat, 12 Sep 2015 10:47:29 -0700 Subject: [PATCH] Delete an empty note when closing a pane Close #18. This is against nvALT, but I think this is more intuitive way. --- lib/notational-velocity.coffee | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/notational-velocity.coffee b/lib/notational-velocity.coffee index 995b33d..e7877d1 100644 --- a/lib/notational-velocity.coffee +++ b/lib/notational-velocity.coffee @@ -47,7 +47,7 @@ module.exports = window.addEventListener('blur', handleBlur, true) @subscriptions.add new Disposable -> window.removeEventListener('blur', handleBlur, true) - @subscriptions.add atom.workspace.onWillDestroyPaneItem ({item}) => @autosave(item) + @subscriptions.add atom.workspace.onWillDestroyPaneItem ({item}) => @autosave(item) unless @autodelete(item) deactivate: -> @subscriptions.dispose() @@ -70,6 +70,17 @@ module.exports = return unless path.extname(uri) in atom.config.get('nvatom.extensions') paneItem?.save?() + autodelete: (paneItem) -> + return false unless paneItem?.getURI?()? + uri = paneItem.getURI() + return false unless uri.indexOf(@rootDirectory) == 0 + return false unless path.extname(uri) in atom.config.get('nvatom.extensions') + return false unless paneItem?.isEmpty() + fs.unlinkSync(uri) + noteName = uri.substring(@rootDirectory.length + 1) + atom.notifications.addInfo("Empty note #{noteName} is deleted.") + return true + autosaveAll: -> @autosave(paneItem) for paneItem in atom.workspace.getPaneItems()