mirror of
https://github.com/atom/atom.git
synced 2026-02-08 13:45:09 -05:00
Fix indentation when pasting lines
The fix to ignore invisibles () introduces a new bug when pasting lines from the clipboard (see screencast below). As the commit takes the content of `@buffer.lineFromRow(bufferRow)` to test against the `decreaseIndentRegex`, it will actually test the content of the row the cursor is on instead of the content that is being pasted. And this (of course) could cause unexpected indentations.
This commit is contained in:
@@ -234,14 +234,15 @@ class LanguageMode
|
||||
#
|
||||
# Returns a {Number}.
|
||||
suggestedIndentForBufferRow: (bufferRow, options) ->
|
||||
line = @buffer.lineForRow(bufferRow)
|
||||
tokenizedLine = @editor.displayBuffer.tokenizedBuffer.tokenizedLineForRow(bufferRow)
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, tokenizedLine, options)
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
|
||||
|
||||
suggestedIndentForLineAtBufferRow: (bufferRow, line, options) ->
|
||||
tokenizedLine = @editor.displayBuffer.tokenizedBuffer.buildTokenizedLineForRowWithText(bufferRow, line)
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, tokenizedLine, options)
|
||||
@suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options)
|
||||
|
||||
suggestedIndentForTokenizedLineAtBufferRow: (bufferRow, tokenizedLine, options) ->
|
||||
suggestedIndentForTokenizedLineAtBufferRow: (bufferRow, line, tokenizedLine, options={}) ->
|
||||
iterator = tokenizedLine.getTokenIterator()
|
||||
iterator.next()
|
||||
scopeDescriptor = new ScopeDescriptor(scopes: iterator.getScopes())
|
||||
@@ -253,7 +254,7 @@ class LanguageMode
|
||||
currentIndentLevel = @editor.indentationForBufferRow(bufferRow)
|
||||
return currentIndentLevel unless increaseIndentRegex
|
||||
|
||||
if options?.skipBlankLines ? true
|
||||
if options.skipBlankLines ? true
|
||||
precedingRow = @buffer.previousNonBlankRow(bufferRow)
|
||||
return 0 unless precedingRow?
|
||||
else
|
||||
@@ -268,10 +269,7 @@ class LanguageMode
|
||||
desiredIndentLevel += 1 if increaseIndentRegex?.testSync(precedingLine)
|
||||
desiredIndentLevel -= 1 if decreaseNextIndentRegex?.testSync(precedingLine)
|
||||
|
||||
unless @editor.isBufferRowCommented(bufferRow)
|
||||
bufferLine = @buffer.lineForRow(bufferRow)
|
||||
desiredIndentLevel -= 1 if decreaseIndentRegex?.testSync(bufferLine)
|
||||
|
||||
desiredIndentLevel -= 1 if decreaseIndentRegex?.testSync(line)
|
||||
Math.max(desiredIndentLevel, 0)
|
||||
|
||||
# Calculate a minimum indent level for a range of lines excluding empty lines.
|
||||
|
||||
Reference in New Issue
Block a user