mirror of
https://github.com/wassname/nvatom.git
synced 2026-08-06 13:10:26 +08:00
Merge pull request #10 from jonmagic/auto-save-on-did-stop-changing
Auto save document 1 second after finishing typing
This commit is contained in:
@@ -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'
|
||||
@@ -87,16 +88,26 @@ class NotationalVelocityView extends SelectListView
|
||||
|
||||
confirmSelection: ->
|
||||
item = @getSelectedItem()
|
||||
filePath = null
|
||||
if item?
|
||||
atom.workspace.open(item.getFilePath())
|
||||
@cancel()
|
||||
filePath = item.getFilePath()
|
||||
else
|
||||
sanitizedQuery = @getFilterQuery().replace(/\s+$/, '')
|
||||
if sanitizedQuery.length > 0
|
||||
filePath = path.join(@rootDirectory, sanitizedQuery + '.md')
|
||||
fs.writeFileSync(filePath, '')
|
||||
atom.workspace.open(filePath)
|
||||
@cancel()
|
||||
|
||||
if filePath
|
||||
atom.workspace.open(filePath).then (editor) ->
|
||||
save = ->
|
||||
atom.packages.deactivatePackage 'whitespace'
|
||||
editor.save()
|
||||
atom.packages.activatePackage 'whitespace'
|
||||
debouncedSave = _.debounce save, 1000
|
||||
editor.onDidStopChanging () ->
|
||||
debouncedSave() if editor.isModified()
|
||||
|
||||
@cancel()
|
||||
|
||||
destroy: ->
|
||||
@cancel()
|
||||
|
||||
+2
-1
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user