Alt-meta-f folds the current selection

This commit is contained in:
Nathan Sobo 2012-02-24 11:30:32 -07:00
parent 0bdc45037f
commit dfcf4a1629
3 changed files with 15 additions and 0 deletions

View File

@ -733,3 +733,10 @@ describe "Editor", ->
editor.trigger "paste" editor.trigger "paste"
expect(editor.buffer.getLine(1)).toBe " var first = function(items) {" 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) {...}'

View File

@ -58,6 +58,7 @@ class Editor extends View
'meta-z': 'undo' 'meta-z': 'undo'
'meta-Z': 'redo' 'meta-Z': 'redo'
'alt-meta-w': 'toggle-soft-wrap' 'alt-meta-w': 'toggle-soft-wrap'
'alt-meta-f': 'fold-selection'
@on 'move-right', => @moveCursorRight() @on 'move-right', => @moveCursorRight()
@on 'move-left', => @moveCursorLeft() @on 'move-left', => @moveCursorLeft()
@ -76,6 +77,7 @@ class Editor extends View
@on 'undo', => @undo() @on 'undo', => @undo()
@on 'redo', => @redo() @on 'redo', => @redo()
@on 'toggle-soft-wrap', => @toggleSoftWrap() @on 'toggle-soft-wrap', => @toggleSoftWrap()
@on 'fold-selection', => @foldSelection()
buildCursorAndSelection: -> buildCursorAndSelection: ->
@cursor = new Cursor(this) @cursor = new Cursor(this)
@ -273,6 +275,8 @@ class Editor extends View
copySelection: -> @selection.copy() copySelection: -> @selection.copy()
paste: -> @selection.insertText(atom.native.readFromPasteboard()) paste: -> @selection.insertText(atom.native.readFromPasteboard())
foldSelection: -> @selection.fold()
backspace: -> backspace: ->
@selectLeft() if @selection.isEmpty() @selectLeft() if @selection.isEmpty()
@selection.delete() @selection.delete()

View File

@ -1,4 +1,5 @@
Cursor = require 'cursor' Cursor = require 'cursor'
Range = require 'range' Range = require 'range'
{View, $$} = require 'space-pen' {View, $$} = require 'space-pen'
@ -157,3 +158,6 @@ class Selection extends View
return if @isEmpty() return if @isEmpty()
text = @editor.buffer.getTextInRange @getRange() text = @editor.buffer.getTextInRange @getRange()
atom.native.writeToPasteboard text atom.native.writeToPasteboard text
fold: ->
@editor.lineFolder.createFold(@getRange())