Add soft-wrap hanging indentation spaces

This commit is contained in:
Antonio Scandurra
2015-03-17 22:05:43 +01:00
parent 7a4ad18f6a
commit 67b1d7890b
2 changed files with 21 additions and 8 deletions

View File

@@ -69,12 +69,17 @@ class DisplayBuffer extends Model
scrollPastEnd: atom.config.get('editor.scrollPastEnd', scope: scopeDescriptor)
softWrap: atom.config.get('editor.softWrap', scope: scopeDescriptor)
softWrapAtPreferredLineLength: atom.config.get('editor.softWrapAtPreferredLineLength', scope: scopeDescriptor)
softWrapHangingIndentationSpaces: atom.config.get('editor.softWrapHangingIndentationSpaces', scope: scopeDescriptor)
preferredLineLength: atom.config.get('editor.preferredLineLength', scope: scopeDescriptor)
subscriptions.add atom.config.onDidChange 'editor.softWrap', scope: scopeDescriptor, ({newValue}) =>
@configSettings.softWrap = newValue
@updateWrappedScreenLines()
subscriptions.add atom.config.onDidChange 'editor.softWrapHangingIndentationSpaces', scope: scopeDescriptor, ({newValue}) =>
@configSettings.softWrapHangingIndentationSpaces = newValue
@updateWrappedScreenLines()
subscriptions.add atom.config.onDidChange 'editor.softWrapAtPreferredLineLength', scope: scopeDescriptor, ({newValue}) =>
@configSettings.softWrapAtPreferredLineLength = newValue
@updateWrappedScreenLines() if @isSoftWrapped()
@@ -1157,7 +1162,10 @@ class DisplayBuffer extends Model
softWraps = 0
if @isSoftWrapped()
while wrapScreenColumn = tokenizedLine.findWrapColumn(@getSoftWrapColumn())
[wrappedLine, tokenizedLine] = tokenizedLine.softWrapAt(wrapScreenColumn)
[wrappedLine, tokenizedLine] = tokenizedLine.softWrapAt(
wrapScreenColumn,
hangingIndentationSpaces: @configSettings.softWrapHangingIndentationSpaces
)
break if wrappedLine.hasOnlySoftWrapIndentation()
screenLines.push(wrappedLine)
softWraps++

View File

@@ -118,18 +118,23 @@ class TokenizedLine
oddIndentLevel = @indentLevel - Math.floor(@indentLevel)
Math.round(@tabLength * oddIndentLevel)
buildSoftWrapIndentationTokens: (token) ->
buildSoftWrapIndentationTokens: (token, hangingIndentationSpaces) ->
indentTokens = [0...Math.floor(@indentLevel)].map =>
token.buildSoftWrapIndentationToken(@tabLength)
if @getOddIndentationSpaces()
indentTokens.concat(
token.buildSoftWrapIndentationToken @getOddIndentationSpaces()
indentTokens.push(
token.buildSoftWrapIndentationToken(@getOddIndentationSpaces())
)
else
indentTokens
softWrapAt: (column) ->
if hangingIndentationSpaces
indentTokens.push(
token.buildSoftWrapIndentationToken(hangingIndentationSpaces)
)
indentTokens
softWrapAt: (column, {hangingIndentationSpaces}) ->
return [new TokenizedLine([], '', [0, 0], [0, 0]), this] if column == 0
rightTokens = new Array(@tokens...)
@@ -142,7 +147,7 @@ class TokenizedLine
leftTextLength += nextToken.value.length
leftTokens.push nextToken
indentationTokens = @buildSoftWrapIndentationTokens(leftTokens[0])
indentationTokens = @buildSoftWrapIndentationTokens(leftTokens[0], hangingIndentationSpaces)
leftFragment = new TokenizedLine(
tokens: leftTokens