Auto-indent skips cursor over leading whitespace before inserting more

This preserves the user's intent to bring the line's total amount of leading whitespace to the desired indent level.
This commit is contained in:
Nathan Sobo
2012-11-05 15:15:00 -07:00
parent 8cd79dae49
commit b87d7cd0df
3 changed files with 19 additions and 9 deletions

View File

@@ -111,6 +111,15 @@ class Cursor
newPosition = [position.row, 0] if newPosition.isEqual(position)
@setBufferPosition(newPosition)
skipLeadingWhitespace: ->
position = @getBufferPosition()
range = @editSession.bufferRangeForBufferRow(position.row)
endOfLeadingWhitespace = null
@editSession.scanInRange /^[ \t]*/, range, (match, matchRange) =>
endOfLeadingWhitespace = matchRange.end
@setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position)
moveToEndOfLine: ->
@setBufferPosition([@getBufferRow(), Infinity])

View File

@@ -187,6 +187,7 @@ class Selection
{ row, column } = @cursor.getBufferPosition()
if @isEmpty()
@cursor.skipLeadingWhitespace()
desiredIndent = @editSession.suggestedIndentForBufferRow(row)
delta = desiredIndent - @cursor.getIndentLevel()