Merge branch 'master' into global-find

This commit is contained in:
Nathan Sobo
2012-07-16 14:56:24 -06:00
6 changed files with 53 additions and 15 deletions

View File

@@ -1096,24 +1096,46 @@ describe "EditSession", ->
editSession.deleteToEndOfWord()
expect(buffer.lineForRow(1)).toBe ' var sort = function(it) {'
describe ".insertTab()", ->
describe "if 'softTabs' is true (the default)", ->
it "inserts the value of 'tabText' into the buffer", ->
tabRegex = new RegExp("^#{editSession.tabText}")
expect(buffer.lineForRow(0)).not.toMatch(tabRegex)
editSession.insertTab()
expect(buffer.lineForRow(0)).toMatch(tabRegex)
describe ".indent()", ->
describe "when nothing is selected", ->
describe "if 'softTabs' is true (the default)", ->
it "inserts the value of 'tabText' into the buffer", ->
tabRegex = new RegExp("^#{editSession.tabText}")
expect(buffer.lineForRow(0)).not.toMatch(tabRegex)
editSession.indent()
expect(buffer.lineForRow(0)).toMatch(tabRegex)
describe "when auto-indent is on and there is no text after the cursor", ->
it "properly indents the line", ->
buffer.insert([7, 0], " \n")
editSession.tabText = " "
editSession.setCursorBufferPosition [7, 2]
editSession.setAutoIndent(true)
editSession.indent()
expect(buffer.lineForRow(7)).toMatch /^\s+$/
expect(buffer.lineForRow(7).length).toBe 6
expect(editSession.getCursorBufferPosition()).toEqual [7, 6]
it "allows for additional indentation if the cursor is beyond the proper indentation point", ->
buffer.insert([7, 0], " \n")
editSession.tabText = " "
editSession.setCursorBufferPosition [7, 6]
editSession.setAutoIndent(true)
editSession.indent()
expect(buffer.lineForRow(7)).toMatch /^\s+$/
expect(buffer.lineForRow(7).length).toBe 8
expect(editSession.getCursorBufferPosition()).toEqual [7, 8]
describe "if editSession.softTabs is false", ->
it "inserts a tab character into the buffer", ->
editSession.setSoftTabs(false)
expect(buffer.lineForRow(0)).not.toMatch(/^\t/)
editSession.insertTab()
editSession.indent()
expect(buffer.lineForRow(0)).toMatch(/^\t/)
expect(editSession.getCursorBufferPosition()).toEqual [0, 1]
expect(editSession.getCursorScreenPosition()).toEqual [0, editSession.tabText.length]
editSession.insertTab()
editSession.indent()
expect(buffer.lineForRow(0)).toMatch(/^\t\t/)
expect(editSession.getCursorBufferPosition()).toEqual [0, 2]
expect(editSession.getCursorScreenPosition()).toEqual [0, editSession.tabText.length * 2]

View File

@@ -145,7 +145,7 @@ describe "Snippets extension", ->
editor.insertText("xte")
expect(editor.getCursorScreenPosition()).toEqual [0, 3]
editor.trigger 'tab'
editor.trigger keydownEvent('tab', target: editor[0])
expect(buffer.lineForRow(0)).toBe "xte var quicksort = function () {"
expect(editor.getCursorScreenPosition()).toEqual [0, 5]

View File

@@ -124,9 +124,17 @@ class EditSession
@moveCursorToEndOfLine()
@insertNewline()
insertTab: ->
indent: ->
if @getSelection().isEmpty()
if @softTabs
whitespaceMatch = @lineForBufferRow(@getCursorBufferPosition().row).match /^\s*$/
if @autoIndent and whitespaceMatch
indentation = @indentationForRow(@getCursorBufferPosition().row)
if indentation.length > whitespaceMatch[0].length
@getSelection().selectLine()
@insertText(indentation)
else
@insertText(@tabText)
else if @softTabs
@insertText(@tabText)
else
@insertText('\t')
@@ -220,6 +228,9 @@ class EditSession
largestFoldStartingAtScreenRow: (screenRow) ->
@displayBuffer.largestFoldStartingAtScreenRow(screenRow)
indentationForRow: (row) ->
@tokenizedBuffer.indentationForRow(row)
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
return { text } unless @autoIndent
@tokenizedBuffer.autoIndentTextAfterBufferPosition(text, bufferPosition)

View File

@@ -105,7 +105,7 @@ class Editor extends View
'select-down': @selectDown
'select-word': @selectWord
'newline': @insertNewline
'tab': @insertTab
'indent': @indent
'indent-selected-rows': @indentSelectedRows
'outdent-selected-rows': @outdentSelectedRows
'backspace': @backspace
@@ -211,7 +211,7 @@ class Editor extends View
insertText: (text) -> @activeEditSession.insertText(text)
insertNewline: -> @activeEditSession.insertNewline()
insertNewlineBelow: -> @activeEditSession.insertNewlineBelow()
insertTab: -> @activeEditSession.insertTab()
indent: -> @activeEditSession.indent()
indentSelectedRows: -> @activeEditSession.indentSelectedRows()
outdentSelectedRows: -> @activeEditSession.outdentSelectedRows()
cutSelection: -> @activeEditSession.cutSelectedText()

View File

@@ -7,7 +7,7 @@ window.keymap.bindKeys '.editor',
'meta-a': 'select-all'
'enter': 'newline'
'meta-enter': 'newline-below'
'tab': 'tab'
'tab': 'indent'
'backspace': 'backspace'
'delete': 'delete'
'meta-x': 'cut'

View File

@@ -48,6 +48,11 @@ class TokenizedBuffer
else
null
indentationForRow: (row) ->
state = @stateForRow(row)
previousRowText = @buffer.lineForRow(row - 1)
@aceMode.getNextLineIndent(state, previousRowText, @tabText)
autoIndentTextAfterBufferPosition: (text, bufferPosition) ->
{ row, column} = bufferPosition
state = @stateForRow(row)