mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
🎨 Refactor buildSoftWrapIndentationTokens
...as suggested by @nathansobo ✨
This commit is contained in:
@@ -111,26 +111,16 @@ class TokenizedLine
|
||||
|
||||
return maxColumn
|
||||
|
||||
# For a given `indentLevel`, calculates how many trailing spaces cannot fit in a single tab.
|
||||
#
|
||||
# indentLevel - {Number}
|
||||
# Returns a {Number} representing the odd indentation spaces in `indentLevel`.
|
||||
oddIndentationSpacesForIndentLevel: (indentLevel) ->
|
||||
oddIndentLevel = indentLevel - Math.floor(indentLevel)
|
||||
Math.round(@tabLength * oddIndentLevel)
|
||||
|
||||
buildSoftWrapIndentationTokens: (token, hangingIndent) ->
|
||||
hangingIndentLevel = hangingIndent / @tabLength
|
||||
indentLevel = @indentLevel + hangingIndentLevel
|
||||
indentTokens = [0...Math.floor(indentLevel)].map =>
|
||||
token.buildSoftWrapIndentationToken(@tabLength)
|
||||
totalIndentSpaces = (@indentLevel * @tabLength) + hangingIndent
|
||||
indentTokens = []
|
||||
while totalIndentSpaces > 0
|
||||
tokenLength = Math.min(@tabLength, totalIndentSpaces)
|
||||
indentToken = token.buildSoftWrapIndentationToken(tokenLength)
|
||||
indentTokens.push(indentToken)
|
||||
totalIndentSpaces -= tokenLength
|
||||
|
||||
if oddIndentationSpaces = @oddIndentationSpacesForIndentLevel(indentLevel)
|
||||
indentTokens.concat(
|
||||
token.buildSoftWrapIndentationToken(oddIndentationSpaces)
|
||||
)
|
||||
else
|
||||
indentTokens
|
||||
indentTokens
|
||||
|
||||
softWrapAt: (column, hangingIndent) ->
|
||||
return [new TokenizedLine([], '', [0, 0], [0, 0]), this] if column == 0
|
||||
|
||||
Reference in New Issue
Block a user