mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
Paste indent normalization works with on lines w/ mixed indentation
Normalizing the indent no longer explodes when pasting on a line that has mixed tabs and spaces when the edit session is using hard tabs.
This commit is contained in:
@@ -124,10 +124,13 @@ class EditSession
|
||||
@buffer.change([[bufferRow, 0], [bufferRow, currentIndentString.length]], newIndentString)
|
||||
|
||||
indentLevelForLine: (line) ->
|
||||
if line.match(/^\t/)
|
||||
line.match(/^\t*/)?[0].length
|
||||
if match = line.match(/^[\t ]+/)
|
||||
leadingWhitespace = match[0]
|
||||
tabCount = leadingWhitespace.match(/\t/g)?.length ? 0
|
||||
spaceCount = leadingWhitespace.match(/[ ]/g)?.length ? 0
|
||||
tabCount + (spaceCount / @getTabLength())
|
||||
else
|
||||
line.match(/^\s*/)?[0].length / @getTabLength()
|
||||
0
|
||||
|
||||
buildIndentString: (number) ->
|
||||
if @softTabs
|
||||
|
||||
@@ -238,11 +238,9 @@ class Selection
|
||||
|
||||
adjustIndentationForLine: (line, delta) ->
|
||||
currentIndentLevel = @editSession.indentLevelForLine(line)
|
||||
currentIndentString = @editSession.buildIndentString(currentIndentLevel)
|
||||
desiredIndentLevel = Math.max(0, currentIndentLevel + delta)
|
||||
desiredIndentString = @editSession.buildIndentString(desiredIndentLevel)
|
||||
|
||||
line.replace(new RegExp("^#{currentIndentString}"), desiredIndentString)
|
||||
line.replace(/^[\t ]*/, desiredIndentString)
|
||||
|
||||
backspace: ->
|
||||
if @isEmpty() and not @editSession.isFoldedAtScreenRow(@cursor.getScreenRow())
|
||||
|
||||
Reference in New Issue
Block a user