From 5f1e44153829986898f8d62072eb517297c0bf5f Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 16 Jul 2012 14:23:31 -0700 Subject: [PATCH 1/5] shift-backspace acts as backspace --- src/app/keymaps/editor.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/keymaps/editor.coffee b/src/app/keymaps/editor.coffee index 6bdce72c3..60aef8450 100644 --- a/src/app/keymaps/editor.coffee +++ b/src/app/keymaps/editor.coffee @@ -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' From 611eb93219e34a52ea2be9c336c9e9f78a82b8c2 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 16 Jul 2012 16:11:52 -0700 Subject: [PATCH 2/5] Buffer stores a is modified on disk flag --- spec/app/buffer-spec.coffee | 15 +++++++++++++++ src/app/buffer.coffee | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/app/buffer-spec.coffee b/spec/app/buffer-spec.coffee index 932506576..125298cf6 100644 --- a/spec/app/buffer-spec.coffee +++ b/spec/app/buffer-spec.coffee @@ -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()", -> beforeEach -> buffer.destroy() diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index 21aa60e57..867c97ec2 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -12,6 +12,7 @@ class Buffer @idCounter = 1 undoManager: null modified: null + modifiedOnDisk: null lines: null file: null @@ -41,7 +42,9 @@ class Buffer @file?.off() @file = new File(path) @file.on "contents-change", => - unless @isModified() + if @isModified() + @modifiedOnDisk = true + else @setText(fs.read(@file.getPath())) @modified = false @trigger "path-change", this @@ -167,9 +170,13 @@ class Buffer fs.write path, @getText() @file?.updateMd5() @modified = false + @modifiedOnDisk = false @setPath(path) @trigger 'after-save' + isModifiedOnDisk: -> + @modifiedOnDisk + isModified: -> @modified From 5914b6cc2a52c136aa4776b6422619cc237a80ee Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 16 Jul 2012 16:12:09 -0700 Subject: [PATCH 3/5] Add Buffer.reload() --- spec/app/buffer-spec.coffee | 11 +++++++++++ src/app/buffer.coffee | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/spec/app/buffer-spec.coffee b/spec/app/buffer-spec.coffee index 125298cf6..6478a1e7b 100644 --- a/spec/app/buffer-spec.coffee +++ b/spec/app/buffer-spec.coffee @@ -299,6 +299,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 = null diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index 867c97ec2..b8838c505 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -33,6 +33,11 @@ class Buffer destroy: -> @file?.off() + reload: -> + @setText(fs.read(@file.getPath())) + @modified = false + @modifiedOnDisk = false + getPath: -> @file?.getPath() From e8a892ee3e412c3b0558a0b253468f5ae028b86b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 20 Jul 2012 17:56:36 -0600 Subject: [PATCH 4/5] Start implementing "tool-panel" keymap scheme Tool panels will be mapped to ctrl-# bindings. If the panel is focused, the # binding closes it. Otherwise the # binding shows it (if needed) and focuses it. The esc key unfocuses the panel, but does not necessarily close it. Meta-w always closes the panel. This is the scheme. Right now we only have 2 panels: Command Panel: Ctrl-0, esc still hides it Tree View: Ctrl-1, esc just unfocuses it --- spec/extensions/tree-view-spec.coffee | 40 +++++++++++++++---- .../command-panel/command-panel.coffee | 1 + src/extensions/command-panel/keymap.coffee | 6 ++- src/extensions/fuzzy-finder/keymap.coffee | 3 +- src/extensions/tree-view/keymap.coffee | 5 ++- src/extensions/tree-view/tree-view.coffee | 5 ++- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index 12aa90cd1..54f8bac3c 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -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", -> + fit "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() diff --git a/src/extensions/command-panel/command-panel.coffee b/src/extensions/command-panel/command-panel.coffee index 242374edc..eef6f7c0d 100644 --- a/src/extensions/command-panel/command-panel.coffee +++ b/src/extensions/command-panel/command-panel.coffee @@ -51,6 +51,7 @@ class CommandPanel extends View toggle: -> if @parent().length then @detach() else @attach() + false attach: (text='') -> @rootView.append(this) diff --git a/src/extensions/command-panel/keymap.coffee b/src/extensions/command-panel/keymap.coffee index 0f7d1a7be..605ac9b2e 100644 --- a/src/extensions/command-panel/keymap.coffee +++ b/src/extensions/command-panel/keymap.coffee @@ -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' diff --git a/src/extensions/fuzzy-finder/keymap.coffee b/src/extensions/fuzzy-finder/keymap.coffee index 66bf1b34e..b06be4909 100644 --- a/src/extensions/fuzzy-finder/keymap.coffee +++ b/src/extensions/fuzzy-finder/keymap.coffee @@ -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' diff --git a/src/extensions/tree-view/keymap.coffee b/src/extensions/tree-view/keymap.coffee index 1330170e9..735a8bc41 100644 --- a/src/extensions/tree-view/keymap.coffee +++ b/src/extensions/tree-view/keymap.coffee @@ -1,8 +1,11 @@ window.keymap.bindKeys '#root-view' - 'alt-tab': 'tree-view:focus' + 'ctrl-1': 'tree-view:toggle' 'ctrl-T': 'tree-view:toggle' + 'alt-tab': 'tree-view:focus' 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' diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 260dbaaf1..5207e7a41 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -49,6 +49,7 @@ 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() @@ -71,11 +72,11 @@ class TreeView extends View @root?.unwatchEntries() toggle: -> - if @hasParent() + if @is(':focus') @detach() @rootView.focus() else - @attach() + @attach() unless @hasParent() @focus() attach: -> From 830935cdb8a121cac8ce8e72bf602783a838d742 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 20 Jul 2012 18:59:44 -0600 Subject: [PATCH 5/5] Kill old TreeView bindings. Ctrl-1 is king. --- src/extensions/tree-view/keymap.coffee | 3 --- src/extensions/tree-view/tree-view.coffee | 3 --- 2 files changed, 6 deletions(-) diff --git a/src/extensions/tree-view/keymap.coffee b/src/extensions/tree-view/keymap.coffee index 735a8bc41..9c5b1f060 100644 --- a/src/extensions/tree-view/keymap.coffee +++ b/src/extensions/tree-view/keymap.coffee @@ -1,7 +1,5 @@ window.keymap.bindKeys '#root-view' 'ctrl-1': 'tree-view:toggle' - 'ctrl-T': 'tree-view:toggle' - 'alt-tab': 'tree-view:focus' window.keymap.bindKeys '.tree-view' 'escape': 'tree-view:unfocus' @@ -13,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' diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 5207e7a41..c8cb852b2 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -54,9 +54,6 @@ class TreeView extends View @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) ->