Toggle folding upon 'mousedown' on a foldable line's fold-icon

This commit is contained in:
Nathan Sobo
2014-01-17 15:17:13 -07:00
parent 1e3dc05b3d
commit b2dff15e51
3 changed files with 21 additions and 0 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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())