mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
meta-] indents selected lines
This commit is contained in:
@@ -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));"
|
||||
|
||||
@@ -91,6 +91,9 @@ class CompositeSeleciton
|
||||
insertText: (text) ->
|
||||
@mutateSelectedText (selection) -> selection.insertText(text)
|
||||
|
||||
indentSelectedRows: ->
|
||||
@mutateSelectedText (selection) -> selection.indentSelectedRows()
|
||||
|
||||
backspace: ->
|
||||
@mutateSelectedText (selection) -> selection.backspace()
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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'
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user