mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
meta-[ outdents selected lines
This commit is contained in:
@@ -222,23 +222,54 @@ describe "Selection", ->
|
||||
tabLength = editor.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "indents line cursor is and retains selection", ->
|
||||
it "indents line 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", ->
|
||||
it "indents line 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", ->
|
||||
it "indents selected lines (that are not empty) 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));"
|
||||
expect(selection.getBufferRange()).toEqual [[9, 1 + tabLength], [11, 15 + tabLength]]
|
||||
|
||||
describe ".outdentSelectedRows()", ->
|
||||
tabLength = null
|
||||
|
||||
beforeEach ->
|
||||
editor.tabText = " "
|
||||
tabLength = editor.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "outdents line and retains selection", ->
|
||||
selection.setBufferRange new Range([1,3], [1,3])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(selection.getBufferRange()).toEqual [[1, 3 - tabLength], [1, 3 - tabLength]]
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "outdents line and retains selection", ->
|
||||
selection.setBufferRange new Range([1,4], [1,14])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(selection.getBufferRange()).toEqual [[1, 4 - tabLength], [1, 14 - tabLength]]
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "outdents selected lines and retains selection", ->
|
||||
selection.setBufferRange new Range([0,1], [3,15])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var quicksort = function () {"
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(editor.buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(selection.getBufferRange()).toEqual [[0, 1], [3, 15 - tabLength]]
|
||||
|
||||
@@ -91,6 +91,9 @@ class CompositeSeleciton
|
||||
insertText: (text) ->
|
||||
@mutateSelectedText (selection) -> selection.insertText(text)
|
||||
|
||||
outdentSelectedRows: ->
|
||||
@mutateSelectedText (selection) -> selection.outdentSelectedRows()
|
||||
|
||||
indentSelectedRows: ->
|
||||
@mutateSelectedText (selection) -> selection.indentSelectedRows()
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ class Editor extends View
|
||||
@on 'newline', => @insertText("\n")
|
||||
@on 'tab', => @insertTab()
|
||||
@on 'indent-selected-rows', => @indentSelectedRows()
|
||||
@on 'outdent-selected-rows', => @outdentSelectedRows()
|
||||
@on 'backspace', => @backspace()
|
||||
@on 'backspace-to-beginning-of-word', => @backspaceToBeginningOfWord()
|
||||
@on 'delete', => @delete()
|
||||
@@ -425,8 +426,8 @@ class Editor extends View
|
||||
else
|
||||
@compositeSelection.insertText('\t')
|
||||
|
||||
indentSelectedRows: ->
|
||||
@compositeSelection.indentSelectedRows()
|
||||
indentSelectedRows: -> @compositeSelection.indentSelectedRows()
|
||||
outdentSelectedRows: -> @compositeSelection.outdentSelectedRows()
|
||||
|
||||
cutSelection: -> @compositeSelection.cut()
|
||||
copySelection: -> @compositeSelection.copy()
|
||||
|
||||
@@ -29,4 +29,5 @@ window.keymap.bindKeys '.editor',
|
||||
'alt-meta-right': 'split-right'
|
||||
'alt-meta-up': 'split-up'
|
||||
'alt-meta-down': 'split-down'
|
||||
'meta-[': 'outdent-selected-rows'
|
||||
'meta-]': 'indent-selected-rows'
|
||||
@@ -110,6 +110,14 @@ class Selection extends View
|
||||
for row in [range.start.row..range.end.row]
|
||||
@editor.buffer.insert([row, 0], @editor.tabText) unless @editor.buffer.lineLengthForRow(row) == 0
|
||||
|
||||
outdentSelectedRows: ->
|
||||
range = @getBufferRange()
|
||||
buffer = @editor.buffer
|
||||
leadingTabRegex = new RegExp("^#{@editor.tabText}")
|
||||
for row in [range.start.row..range.end.row]
|
||||
if leadingTabRegex.test buffer.lineForRow(row)
|
||||
buffer.delete [[row, 0], [row, @editor.tabText.length]]
|
||||
|
||||
autoIndentText: (text) ->
|
||||
if @editor.autoIndent
|
||||
mode = @editor.getCurrentMode()
|
||||
|
||||
Reference in New Issue
Block a user