Hitting tab on a line (containing only whitespace) will auto indent the line and set the cursor to the end

This commit is contained in:
Corey Johnson
2012-07-16 10:25:28 -07:00
parent e089b74867
commit 5184b90365
3 changed files with 33 additions and 7 deletions

View File

@@ -131,7 +131,12 @@ class EditSession
insertTab: ->
if @getSelection().isEmpty()
if @softTabs
whitespaceMatch = @lineForBufferRow(@getCursorBufferPosition().row).match /^\s*$/
if @autoIndent and whitespaceMatch
indentation = @indentationForRow(@getCursorBufferPosition().row)
@getSelection().selectLine()
@insertText(indentation)
else if @softTabs
@insertText(@tabText)
else
@insertText('\t')
@@ -225,6 +230,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

@@ -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)