Use cursor indent level if commenting single line

Previously commenting a line of all whitespace would insert
the comment at column 0 on the line since blank lines are
ignored when calculating the minimum indent level.
This commit is contained in:
Kevin Sawicki 2014-04-03 18:26:50 -07:00
parent 2ea09aa6b6
commit 1aa64a9d80
2 changed files with 14 additions and 1 deletions

View File

@ -46,6 +46,16 @@ describe "LanguageMode", ->
languageMode.toggleLineCommentsForBufferRows(0, 0) languageMode.toggleLineCommentsForBufferRows(0, 0)
expect(buffer.lineForRow(0)).toBe " // var i;" expect(buffer.lineForRow(0)).toBe " // var i;"
buffer.setText(' ')
languageMode.toggleLineCommentsForBufferRows(0, 0)
expect(buffer.lineForRow(0)).toBe " // "
buffer.setText (' a\n \n b')
languageMode.toggleLineCommentsForBufferRows(0, 2)
expect(buffer.lineForRow(0)).toBe " // a"
expect(buffer.lineForRow(1)).toBe " // "
expect(buffer.lineForRow(2)).toBe " // b"
describe ".rowRangeForCodeFoldAtBufferRow(bufferRow)", -> describe ".rowRangeForCodeFoldAtBufferRow(bufferRow)", ->
it "returns the start/end rows of the foldable region starting at the given row", -> it "returns the start/end rows of the foldable region starting at the given row", ->
expect(languageMode.rowRangeForCodeFoldAtBufferRow(0)).toEqual [0, 12] expect(languageMode.rowRangeForCodeFoldAtBufferRow(0)).toEqual [0, 12]

View File

@ -74,7 +74,10 @@ class LanguageMode
columnEnd = columnStart + match[2].length columnEnd = columnStart + match[2].length
buffer.change([[row, columnStart], [row, columnEnd]], "") buffer.change([[row, columnStart], [row, columnEnd]], "")
else else
indent = @minIndentLevelForRowRange(start, end) if start is end
indent = @editor.indentationForBufferRow(start)
else
indent = @minIndentLevelForRowRange(start, end)
indentString = @editor.buildIndentString(indent) indentString = @editor.buildIndentString(indent)
tabLength = @editor.getTabLength() tabLength = @editor.getTabLength()
indentRegex = new RegExp("(\t|[ ]{#{tabLength}}){#{Math.floor(indent)}}") indentRegex = new RegExp("(\t|[ ]{#{tabLength}}){#{Math.floor(indent)}}")