mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
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:
@@ -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])
|
||||
|
||||
|
||||
@@ -187,6 +187,7 @@ class Selection
|
||||
{ row, column } = @cursor.getBufferPosition()
|
||||
|
||||
if @isEmpty()
|
||||
@cursor.skipLeadingWhitespace()
|
||||
desiredIndent = @editSession.suggestedIndentForBufferRow(row)
|
||||
delta = desiredIndent - @cursor.getIndentLevel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user