Merge branch 'master' into global-find

Conflicts:
	src/app/buffer.coffee
This commit is contained in:
Nathan Sobo
2012-07-20 19:01:38 -06:00
9 changed files with 87 additions and 20 deletions

View File

@@ -90,6 +90,21 @@ describe 'Buffer', ->
expect(event.newText).toBe "second"
expect(buffer.isModified()).toBeFalsy()
describe "when the buffer is modified", ->
it "sets modifiedOnDisk to be true", ->
fileChangeHandler = jasmine.createSpy('fileChange')
buffer.file.on 'contents-change', fileChangeHandler
buffer.insert([0, 0], "a change")
fs.write(path, "second")
expect(fileChangeHandler.callCount).toBe 0
waitsFor "file to trigger contents-change event", ->
fileChangeHandler.callCount > 0
runs ->
expect(buffer.isModifiedOnDisk()).toBeTruthy()
describe ".isModified()", ->
it "returns true when user changes buffer", ->
expect(buffer.isModified()).toBeFalsy()
@@ -282,6 +297,17 @@ describe 'Buffer', ->
buffer = new Buffer
expect(-> buffer.save()).toThrow()
describe "reload()", ->
it "loads text from disk are sets @modified and @modifiedOnDisk to false", ->
buffer.modified = true
buffer.modifiedOnDisk = true
buffer.setText("abc")
buffer.reload()
expect(buffer.modifed).toBeFalsy()
expect(buffer.modifiedOnDisk).toBeFalsy()
expect(buffer.getText()).toBe(fileContents)
describe ".saveAs(path)", ->
[filePath, saveAsBuffer] = []

View File

@@ -103,18 +103,42 @@ describe "TreeView", ->
newRootView.remove()
describe "when tree-view:toggle is triggered on the root view", ->
it "shows/hides the tree view", ->
beforeEach ->
rootView.attachToDom()
describe "when the tree view is visible", ->
beforeEach ->
expect(treeView).toBeVisible()
describe "when the tree view is focused", ->
it "hides the tree view", ->
treeView.focus()
rootView.trigger 'tree-view:toggle'
expect(treeView).toBeHidden()
describe "when the tree view is not focused", ->
it "shifts focus to the tree view", ->
rootView.focus()
rootView.trigger 'tree-view:toggle'
expect(treeView).toBeVisible()
expect(treeView).toMatchSelector(':focus')
describe "when the tree view is hidden", ->
it "shows and focuses the tree view", ->
treeView.detach()
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeTruthy()
expect(treeView).toMatchSelector(':focus')
describe "when tree-view:unfocus is triggered on the tree view", ->
it "surrenders focus to the root view but remains open", ->
rootView.attachToDom()
treeView.focus()
expect(treeView.hasParent()).toBeTruthy()
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeFalsy()
treeView.trigger 'tree-view:unfocus'
expect(treeView).toBeVisible()
expect(treeView).not.toMatchSelector(':focus')
expect(rootView).toMatchSelector(':focus')
rootView.trigger 'tree-view:toggle'
expect(treeView.hasParent()).toBeTruthy()
expect(treeView).toMatchSelector(':focus')
describe "when a directory's disclosure arrow is clicked", ->
it "expands / collapses the associated directory", ->
subdir = treeView.root.find('.entries > li:contains(dir/)').view()

View File

@@ -14,6 +14,7 @@ class Buffer
@idCounter = 1
undoManager: null
modified: null
modifiedOnDisk: null
lines: null
file: null
anchors: null
@@ -52,11 +53,18 @@ class Buffer
this
subscribeToFile: ->
@file?.on "contents-change", =>
unless @isModified()
@file.on "contents-change", =>
if @isModified()
@modifiedOnDisk = true
else
@setText(fs.read(@file.getPath()))
@modified = false
reload: ->
@setText(fs.read(@file.getPath()))
@modified = false
@modifiedOnDisk = false
getPath: ->
@file?.getPath()
@@ -198,9 +206,13 @@ class Buffer
fs.write path, @getText()
@file?.updateMd5()
@modified = false
@modifiedOnDisk = false
@setPath(path)
@trigger 'after-save'
isModifiedOnDisk: ->
@modifiedOnDisk
isModified: ->
@modified

View File

@@ -9,6 +9,7 @@ window.keymap.bindKeys '.editor',
'meta-enter': 'newline-below'
'tab': 'indent'
'backspace': 'backspace'
'shift-backspace': 'backspace'
'delete': 'delete'
'meta-x': 'cut'
'meta-c': 'copy'

View File

@@ -58,6 +58,7 @@ class CommandPanel extends View
toggle: ->
if @parent().length then @detach() else @attach()
false
attach: (text='') ->
@rootView.append(this)

View File

@@ -1,7 +1,11 @@
window.keymap.bindKeys '*'
'ctrl-0': 'command-panel:toggle'
'ctrl-meta-0': 'command-panel:toggle-preview'
'meta-:': 'command-panel:toggle'
'meta-F': 'command-panel:find-in-project'
window.keymap.bindKeys '.command-panel .editor',
window.keymap.bindKeys '.command-panel .editor input',
'meta-w': 'command-panel:toggle'
escape: 'command-panel:toggle'
enter: 'command-panel:execute'

View File

@@ -2,6 +2,7 @@ window.keymap.bindKeys '*'
'meta-t': 'fuzzy-finder:toggle-file-finder'
'meta-b': 'fuzzy-finder:toggle-buffer-finder'
window.keymap.bindKeys ".fuzzy-finder .editor",
window.keymap.bindKeys ".fuzzy-finder .editor input",
'enter': 'fuzzy-finder:select-path',
'escape': 'fuzzy-finder:cancel'
'meta-w': 'fuzzy-finder:cancel'

View File

@@ -1,8 +1,9 @@
window.keymap.bindKeys '#root-view'
'alt-tab': 'tree-view:focus'
'ctrl-T': 'tree-view:toggle'
'ctrl-1': 'tree-view:toggle'
window.keymap.bindKeys '.tree-view'
'escape': 'tree-view:unfocus'
'meta-w': 'tree-view:toggle'
'right': 'tree-view:expand-directory'
'left': 'tree-view:collapse-directory'
'enter': 'tree-view:open-selected-entry'
@@ -10,7 +11,6 @@ window.keymap.bindKeys '.tree-view'
'a': 'tree-view:add'
'delete': 'tree-view:remove'
'backspace': 'tree-view:remove'
'alt-tab': 'tree-view:unfocus'
window.keymap.bindKeys '.tree-view-dialog .mini.editor'
'enter': 'tree-view:confirm'

View File

@@ -49,13 +49,11 @@ class TreeView extends View
@on 'tree-view:add', => @add()
@on 'tree-view:remove', => @removeSelectedEntry()
@on 'tree-view:directory-modified', => @selectActiveFile()
@on 'tree-view:unfocus', => @rootView.focus()
@rootView.on 'tree-view:toggle', => @toggle()
@rootView.on 'active-editor-path-change', => @selectActiveFile()
@rootView.project.on 'path-change', => @updateRoot()
@on 'tree-view:unfocus', => @rootView.getActiveEditor()?.focus()
@rootView.on 'tree-view:focus', => this.focus()
@selectEntry(@root) if @root
afterAttach: (onDom) ->
@@ -71,11 +69,11 @@ class TreeView extends View
@root?.unwatchEntries()
toggle: ->
if @hasParent()
if @is(':focus')
@detach()
@rootView.focus()
else
@attach()
@attach() unless @hasParent()
@focus()
attach: ->