diff --git a/spec/atom/editor-spec.coffee b/spec/atom/editor-spec.coffee index cb2d9bbde..95d92acd4 100644 --- a/spec/atom/editor-spec.coffee +++ b/spec/atom/editor-spec.coffee @@ -733,3 +733,10 @@ describe "Editor", -> editor.trigger "paste" expect(editor.buffer.getLine(1)).toBe " var first = function(items) {" + describe "folding", -> + describe "when a fold-selection event is triggered", -> + it "folds the selected text and renders a placeholder for it", -> + editor.selection.setRange(new Range([4, 29], [7, 4])) + editor.trigger 'fold-selection' + expect(editor.lines.find('.line:eq(4)').text()).toBe ' while(items.length > 0) {...}' + diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 6b8d78b63..dd667197b 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -58,6 +58,7 @@ class Editor extends View 'meta-z': 'undo' 'meta-Z': 'redo' 'alt-meta-w': 'toggle-soft-wrap' + 'alt-meta-f': 'fold-selection' @on 'move-right', => @moveCursorRight() @on 'move-left', => @moveCursorLeft() @@ -76,6 +77,7 @@ class Editor extends View @on 'undo', => @undo() @on 'redo', => @redo() @on 'toggle-soft-wrap', => @toggleSoftWrap() + @on 'fold-selection', => @foldSelection() buildCursorAndSelection: -> @cursor = new Cursor(this) @@ -273,6 +275,8 @@ class Editor extends View copySelection: -> @selection.copy() paste: -> @selection.insertText(atom.native.readFromPasteboard()) + foldSelection: -> @selection.fold() + backspace: -> @selectLeft() if @selection.isEmpty() @selection.delete() diff --git a/src/atom/selection.coffee b/src/atom/selection.coffee index 0efa856be..f1fb7dfad 100644 --- a/src/atom/selection.coffee +++ b/src/atom/selection.coffee @@ -1,4 +1,5 @@ Cursor = require 'cursor' + Range = require 'range' {View, $$} = require 'space-pen' @@ -157,3 +158,6 @@ class Selection extends View return if @isEmpty() text = @editor.buffer.getTextInRange @getRange() atom.native.writeToPasteboard text + + fold: -> + @editor.lineFolder.createFold(@getRange())