mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Comments can't increase the indent level of the next line
This commit is contained in:
@@ -2241,6 +2241,14 @@ describe "EditSession", ->
|
||||
editSession.insertText('\n')
|
||||
expect(editSession.indentationForBufferRow(6)).toBe editSession.indentationForBufferRow(5)
|
||||
|
||||
describe "when the line preceding the newline is a comment", ->
|
||||
it "maintains the indent of the commented line", ->
|
||||
editSession.setCursorBufferPosition([0, 0])
|
||||
editSession.insertText(' //')
|
||||
editSession.setCursorBufferPosition([0, Infinity])
|
||||
editSession.insertText('\n')
|
||||
expect(editSession.indentationForBufferRow(1)).toBe 2
|
||||
|
||||
it "does not indent the line preceding the newline", ->
|
||||
editSession.setCursorBufferPosition([2, 0])
|
||||
editSession.insertText(' var this-line-should-be-indented-more\n')
|
||||
|
||||
@@ -9,6 +9,7 @@ Subscriber = require 'subscriber'
|
||||
Range = require 'range'
|
||||
_ = require 'underscore'
|
||||
fsUtils = require 'fs-utils'
|
||||
TextMateScopeSelector = require 'text-mate-scope-selector'
|
||||
|
||||
# An `EditSession` manages the states between {Editor}s, {Buffer}s, and the project as a whole.
|
||||
module.exports =
|
||||
@@ -284,6 +285,14 @@ class EditSession
|
||||
# {Delegates to: Buffer.isRowBlank}
|
||||
isBufferRowBlank: (bufferRow) -> @buffer.isRowBlank(bufferRow)
|
||||
|
||||
# Test if an entire row is a comment
|
||||
#
|
||||
# Returns a {Boole}.
|
||||
isBufferRowCommented: (bufferRow) ->
|
||||
if match = @lineForBufferRow(bufferRow).match(/\S/)
|
||||
scopes = @tokenForBufferPosition([bufferRow, match.index]).scopes
|
||||
new TextMateScopeSelector('comment.*').matches(scopes)
|
||||
|
||||
# {Delegates to: Buffer.nextNonBlankRow}
|
||||
nextNonBlankBufferRow: (bufferRow) -> @buffer.nextNonBlankRow(bufferRow)
|
||||
|
||||
|
||||
@@ -162,9 +162,8 @@ class LanguageMode
|
||||
return currentIndentLevel unless precedingRow?
|
||||
|
||||
precedingLine = @buffer.lineForRow(precedingRow)
|
||||
|
||||
desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow)
|
||||
desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine)
|
||||
desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine) and not @editSession.isBufferRowCommented(precedingRow)
|
||||
|
||||
return desiredIndentLevel unless decreaseIndentRegex = @decreaseIndentRegexForScopes(scopes)
|
||||
desiredIndentLevel -= 1 if decreaseIndentRegex.test(currentLine)
|
||||
|
||||
Reference in New Issue
Block a user