Skip to content

Commit 703d288

Browse files
committed
Handle editor saving
1 parent 053e11c commit 703d288

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

keymaps/tree-view.cson

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
'body.learn-ide.platform-darwin':
2+
'cmd-s': 'learn-ide:save'
3+
'cmd-S': 'learn-ide:save-as'
4+
'cmd-n': 'tree-view:add-file'
5+
'cmd-o': 'learn-ide:file-open'
6+
'cmd-O': 'learn-ide:add-project'
7+
'cmd-alt-s': 'learn-ide:save-all'
8+
9+
'body.learn-ide.platform-win32':
10+
'ctrl-s': 'learn-ide:save'
11+
'ctrl-S': 'learn-ide:save-as'
12+
'ctrl-n': 'tree-view:add-file'
13+
'ctrl-o': 'learn-ide:file-open'
14+
'ctrl-alt-o': 'learn-ide:add-project'
15+
16+
'body.learn-ide.platform-linux':
17+
'ctrl-s': 'learn-ide:save'
18+
'ctrl-S': 'learn-ide:save-as'
19+
'ctrl-n': 'tree-view:add-file'
20+
'ctrl-o': 'learn-ide:file-open'
21+
'ctrl-alt-o': 'learn-ide:add-project'
22+
123
'.platform-darwin':
224
'cmd-\\': 'tree-view:toggle'
325
'cmd-k cmd-b': 'tree-view:toggle'

lib/nsync/atom-helper.coffee

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ module.exports = helper =
105105
selectedPath: ->
106106
@treeView()?.selectedPath
107107

108+
observeTextEditors: (callback) ->
109+
atom.workspace.observeTextEditors(callback)
110+
108111
findTextEditorByElement: (element) ->
109112
atom.workspace.getTextEditors().find (editor) ->
110113
editor.element is element
@@ -113,6 +116,9 @@ module.exports = helper =
113116
atom.workspace.getTextEditors().find (editor) ->
114117
editor.getPath() is path
115118

119+
findOrCreateBuffer: (path) ->
120+
atom.project.bufferForPath(path)
121+
116122
saveEditor: (path) ->
117123
textEditor = @findTextEditorByPath(path)
118124

lib/nsync/nsync-helper.coffee

+14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ importLocalPaths = (localPaths) ->
7878

7979
nsync.save(newPath, data)
8080

81+
onEditorSave = ({path}) ->
82+
node = nsync.getNode(path)
83+
84+
node.determineSync().then (shouldSync) ->
85+
if shouldSync
86+
atomHelper.findOrCreateBuffer(path).then (textBuffer) ->
87+
text = convertEOL(textBuffer.getText())
88+
content = new Buffer(text).toString('base64')
89+
nsync.save(node.path, content)
90+
8191
module.exports = helper = (activationState) ->
8292
disposables = new CompositeDisposable
8393

@@ -129,6 +139,10 @@ module.exports = helper = (activationState) ->
129139
disposables.add nsync.onDidUpdate (path) ->
130140
atomHelper.saveEditor(path)
131141

142+
disposables.add atomHelper.observeTextEditors (editor) ->
143+
disposables.add editor.onDidSave (e) ->
144+
onEditorSave(e)
145+
132146
atomHelper.getToken().then (token) ->
133147
nsync.configure
134148
expansionState: activationState.directoryExpansionStates

0 commit comments

Comments
 (0)