From 0f269c921698e4954faca6990c2357b3524dac9b Mon Sep 17 00:00:00 2001 From: Jonathan Hoyt Date: Sat, 9 May 2015 14:27:21 -0700 Subject: [PATCH] Debounce the save so the editor doesn't slow down --- lib/notational-velocity-view.coffee | 12 ++++++++---- package.json | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/notational-velocity-view.coffee b/lib/notational-velocity-view.coffee index 3301d14..799fa71 100644 --- a/lib/notational-velocity-view.coffee +++ b/lib/notational-velocity-view.coffee @@ -1,5 +1,6 @@ path = require 'path' fs = require 'fs-plus' +_ = require 'underscore-plus' {$, $$, SelectListView} = require 'atom-space-pen-views' NoteDirectory = require './note-directory' Note = require './note' @@ -98,11 +99,14 @@ class NotationalVelocityView extends SelectListView if filePath atom.workspace.open(filePath).then (editor) -> + save = -> + atom.packages.deactivatePackage 'whitespace' + console.log 'save' + editor.save() + atom.packages.activatePackage 'whitespace' + debouncedSave = _.debounce save, 1000 editor.onDidStopChanging () -> - if editor.isModified() - atom.packages.deactivatePackage("whitespace"); - editor.save() - atom.packages.activatePackage("whitespace"); + debouncedSave() if editor.isModified() @cancel() diff --git a/package.json b/package.json index 571ddda..a972a09 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dependencies": { "fs-plus": "2.x", "atom-space-pen-views": "^2.0.3", - "pathwatcher": "^4.2" + "pathwatcher": "^4.2", + "underscore-plus": "^1.6.6" }, "devDependencies": { "fs-plus": "2.x",