diff --git a/spec/editor-view-spec.coffee b/spec/editor-view-spec.coffee index c00623206..ca5d19e32 100644 --- a/spec/editor-view-spec.coffee +++ b/spec/editor-view-spec.coffee @@ -715,6 +715,14 @@ describe "EditorView", -> expect(selection1.getScreenRange()).toEqual [[4, 10], [5, 27]] expect(selection2.getScreenRange()).toEqual [[6, 10], [8, 27]] + describe "mousedown on the fold icon of a foldable line number", -> + it "toggles folding on the clicked buffer row", -> + expect(editor.isFoldedAtScreenRow(1)).toBe false + editorView.gutter.find('.line-number:eq(1) .fold-icon').mousedown() + expect(editor.isFoldedAtScreenRow(1)).toBe true + editorView.gutter.find('.line-number:eq(1) .fold-icon').mousedown() + expect(editor.isFoldedAtScreenRow(1)).toBe false + describe "when text input events are triggered on the hidden input element", -> it "inserts the typed character at the cursor position, both in the buffer and the pre element", -> editorView.attachToDom() diff --git a/src/editor-view.coffee b/src/editor-view.coffee index 5f9fc7c4a..685cbc60a 100644 --- a/src/editor-view.coffee +++ b/src/editor-view.coffee @@ -348,6 +348,11 @@ class EditorView extends View @editor.destroyFoldWithId(id) false + @gutter.on 'mousedown', '.foldable .fold-icon', (e) => + bufferRow = $(e.target).parent().data('bufferRow') + @editor.toggleFoldAtBufferRow(bufferRow) + return false + @renderedLines.on 'mousedown', (e) => clickCount = e.originalEvent.detail diff --git a/src/editor.coffee b/src/editor.coffee index 9a2cf3fe6..13b99e09e 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -598,6 +598,14 @@ class Editor extends Model for row in [bufferRange.start.row..bufferRange.end.row] @destroyFoldsContainingBufferRow(row) + # Public: Folds the given buffer row if it's not currently folded, and unfolds + # it otherwise. + toggleFoldAtBufferRow: (bufferRow) -> + if @isFoldedAtBufferRow(bufferRow) + @unfoldBufferRow(bufferRow) + else + @foldBufferRow(bufferRow) + # Public: Returns whether the current row is folded. isFoldedAtCursorRow: -> @isFoldedAtScreenRow(@getCursorScreenRow())