meta-] indents selected lines

This commit is contained in:
Corey Johnson
2012-04-10 09:55:13 -07:00
parent 95a2be5fa5
commit ec221bfee0
5 changed files with 41 additions and 0 deletions

View File

@@ -214,3 +214,31 @@ describe "Selection", ->
selection.selectToScreenPosition([0, 25])
expect(selection.isReversed()).toBeFalsy()
describe ".indentSelectedRows()", ->
tabLength = null
beforeEach ->
tabLength = editor.tabText.length
describe "when nothing is selected", ->
it "indents line cursor is and retains selection", ->
selection.setBufferRange new Range([0,3], [0,3])
selection.indentSelectedRows()
expect(editor.buffer.lineForRow(0)).toBe "#{editor.tabText}var quicksort = function () {"
expect(selection.getBufferRange()).toEqual [[0, 3 + tabLength], [0, 3 + tabLength]]
describe "when one line is selected", ->
it "indents line selection and retains selection", ->
selection.setBufferRange new Range([0,4], [0,14])
selection.indentSelectedRows()
expect(editor.buffer.lineForRow(0)).toBe "#{editor.tabText}var quicksort = function () {"
expect(selection.getBufferRange()).toEqual [[0, 4 + tabLength], [0, 14 + tabLength]]
describe "when multiple lines are selected", ->
it "indents selected lines with text and retains selection", ->
selection.setBufferRange new Range([9,1], [11,15])
selection.indentSelectedRows()
expect(editor.buffer.lineForRow(9)).toBe " };"
expect(editor.buffer.lineForRow(10)).toBe ""
expect(editor.buffer.lineForRow(11)).toBe " return sort(Array.apply(this, arguments));"

View File

@@ -91,6 +91,9 @@ class CompositeSeleciton
insertText: (text) ->
@mutateSelectedText (selection) -> selection.insertText(text)
indentSelectedRows: ->
@mutateSelectedText (selection) -> selection.indentSelectedRows()
backspace: ->
@mutateSelectedText (selection) -> selection.backspace()

View File

@@ -66,6 +66,7 @@ class Editor extends View
@on 'select-down', => @selectDown()
@on 'newline', => @insertText("\n")
@on 'tab', => @insertTab()
@on 'indent-selected-rows', => @indentSelectedRows()
@on 'backspace', => @backspace()
@on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord()
@on 'delete', => @delete()
@@ -424,6 +425,9 @@ class Editor extends View
else
@compositeSelection.insertText('\t')
indentSelectedRows: ->
@compositeSelection.indentSelectedRows()
cutSelection: -> @compositeSelection.cut()
copySelection: -> @compositeSelection.copy()
paste: -> @insertText($native.readFromPasteboard())

View File

@@ -29,3 +29,4 @@ window.keymap.bindKeys '.editor',
'alt-meta-right': 'split-right'
'alt-meta-up': 'split-up'
'alt-meta-down': 'split-down'
'meta-]': 'indent-selected-rows'

View File

@@ -105,6 +105,11 @@ class Selection extends View
@autoOutdentText() if shouldOutdent
@clearSelection()
indentSelectedRows: ->
range = @getBufferRange()
for row in [range.start.row..range.end.row]
@editor.buffer.insert([row, 0], @editor.tabText) unless @editor.buffer.lineLengthForRow(row) == 0
autoIndentText: (text) ->
if @editor.autoIndent
mode = @editor.getCurrentMode()