From f7614c210acbb8e9ff7fc115557af527161ff9d6 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Mon, 30 Jul 2012 12:11:54 -0700 Subject: [PATCH] Add unfold-all and bind it to ctrl-} --- spec/app/display-buffer-spec.coffee | 8 ++++++++ src/app/display-buffer.coffee | 5 +++++ src/app/edit-session.coffee | 9 ++++++--- src/app/editor.coffee | 2 ++ src/app/keymaps/editor.coffee | 3 ++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/app/display-buffer-spec.coffee b/spec/app/display-buffer-spec.coffee index 0ecf550fe..87de8cbaf 100644 --- a/spec/app/display-buffer-spec.coffee +++ b/spec/app/display-buffer-spec.coffee @@ -160,6 +160,14 @@ describe "DisplayBuffer", -> expect(displayBuffer.lineForRow(2).foldable).toBeTruthy() expect(displayBuffer.lineForRow(3).foldable).toBeFalsy() + describe ".unfoldAll()", -> + it "unfolds every folded line", -> + displayBuffer.foldBufferRow(0) + displayBuffer.foldBufferRow(1) + + displayBuffer.unfoldAll() + expect(Object.keys(displayBuffer.activeFolds).length).toBe 0 + describe ".foldAll()", -> it "folds every foldable line", -> displayBuffer.foldAll() diff --git a/src/app/display-buffer.coffee b/src/app/display-buffer.coffee index a4b5e4392..a0e0049f1 100644 --- a/src/app/display-buffer.coffee +++ b/src/app/display-buffer.coffee @@ -56,6 +56,10 @@ class DisplayBuffer @createFold(startRow, endRow) + unfoldAll: -> + for row in [@buffer.getLastRow()..0] + @activeFolds[row]?.forEach (fold) => @destroyFold(fold) + foldBufferRow: (bufferRow) -> for currentRow in [bufferRow..0] [startRow, endRow] = @tokenizedBuffer.rowRangeForFoldAtBufferRow(currentRow) ? [] @@ -123,6 +127,7 @@ class DisplayBuffer folds = @activeFolds[bufferRow] _.remove(folds, fold) delete @foldsById[fold.id] + delete @activeFolds[bufferRow] if folds.length == 0 largestFoldStartingAtBufferRow: (bufferRow) -> return unless folds = @activeFolds[bufferRow] diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 164cf2525..8ad03b8e8 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -198,6 +198,12 @@ class EditSession redo: -> @buffer.redo(this) + foldAll: -> + @displayBuffer.foldAll() + + unfoldAll: -> + @displayBuffer.unfoldAll() + foldCurrentRow: -> bufferRow = @bufferPositionForScreenPosition(@getCursorScreenPosition()).row @foldBufferRow(bufferRow) @@ -215,9 +221,6 @@ class EditSession foldSelection: -> selection.fold() for selection in @getSelections() - foldAll: -> - @displayBuffer.foldAll() - createFold: (startRow, endRow) -> @displayBuffer.createFold(startRow, endRow) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 3ac7bbd0a..ee0c8cea8 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -139,6 +139,7 @@ class Editor extends View 'newline-below': @insertNewlineBelow 'toggle-soft-wrap': @toggleSoftWrap 'fold-all': @foldAll + 'unfold-all': @unfoldAll 'fold-current-row': @foldCurrentRow 'unfold-current-row': @unfoldCurrentRow 'fold-selection': @foldSelection @@ -223,6 +224,7 @@ class Editor extends View foldCurrentRow: -> @activeEditSession.foldCurrentRow() unfoldCurrentRow: -> @activeEditSession.unfoldCurrentRow() foldAll: -> @activeEditSession.foldAll() + unfoldAll: -> @activeEditSession.unfoldAll() foldSelection: -> @activeEditSession.foldSelection() destroyFold: (foldId) -> @activeEditSession.destroyFold(foldId) destroyFoldsContainingBufferRow: (bufferRow) -> @activeEditSession.destroyFoldsContainingBufferRow(bufferRow) diff --git a/src/app/keymaps/editor.coffee b/src/app/keymaps/editor.coffee index d0c5e9e85..5b2a819ff 100644 --- a/src/app/keymaps/editor.coffee +++ b/src/app/keymaps/editor.coffee @@ -19,7 +19,8 @@ window.keymap.bindKeys '.editor', 'alt-meta-w': 'toggle-soft-wrap' 'ctrl-[': 'fold-current-row' 'ctrl-]': 'unfold-current-row' - 'ctrl-(': 'fold-all' + 'ctrl-{': 'fold-all' + 'ctrl-}': 'unfold-all' 'alt-meta-ctrl-f': 'fold-selection' 'alt-meta-left': 'split-left' 'alt-meta-right': 'split-right'