WIP: Reworking auto-indent/outdent logic

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-09 12:57:47 -06:00
parent ad4b3db439
commit e8aaec43f7
6 changed files with 135 additions and 74 deletions

View File

@@ -329,17 +329,27 @@ class Buffer
isRowBlank: (row) ->
not /\S/.test @lineForRow(row)
nextNonBlankRow: (row) ->
lastRow = @getLastRow()
if row < lastRow
for row in [(row + 1)..lastRow]
return row unless @isRowBlank(row)
previousNonBlankRow: (startRow) ->
startRow = Math.min(startRow, @getLastRow())
for row in [(startRow - 1)..0]
return row unless @isRowBlank(row)
null
nextNonBlankRow: (startRow) ->
lastRow = @getLastRow()
if startRow < lastRow
for row in [(startRow + 1)..lastRow]
return row unless @isRowBlank(row)
null
indentationForRow: (row) ->
@lineForRow(row).match(/^\s*/)?[0].length
setIndentationForRow: (bufferRow, newLevel) ->
currentLevel = @indentationForRow(bufferRow)
indentString = [0...newLevel].map(-> ' ').join('')
@change([[bufferRow, 0], [bufferRow, currentLevel]], indentString)
logLines: (start=0, end=@getLastRow())->
for row in [start..end]
line = @lineForRow(row)