mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Add soft-wrap hanging indentation spaces
This commit is contained in:
@@ -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++
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user