mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Measure indent prefix on each line being commented
Previously a single indent string was used to replace all lines which could corrupt lines using hard tabs since the indent string used for replacement was two spaces causing the first character of the line to be deleted. Closes atom/language-c#1
This commit is contained in:
@@ -32,6 +32,10 @@ describe "LanguageMode", ->
|
||||
expect(buffer.lineForRow(6)).toBe " // current < pivot ? left.push(current) : right.push(current);"
|
||||
expect(buffer.lineForRow(7)).toBe " // }"
|
||||
|
||||
buffer.setText('\tvar i;')
|
||||
languageMode.toggleLineCommentsForBufferRows(0, 0)
|
||||
expect(buffer.lineForRow(0)).toBe "\t// var i;"
|
||||
|
||||
describe "fold suggestion", ->
|
||||
describe ".doesBufferRowStartFold(bufferRow)", ->
|
||||
it "returns true only when the buffer row starts a foldable region", ->
|
||||
|
||||
@@ -84,8 +84,14 @@ class LanguageMode
|
||||
else
|
||||
indent = @minIndentLevelForRowRange(start, end)
|
||||
indentString = @editSession.buildIndentString(indent)
|
||||
tabLength = @editSession.getTabLength()
|
||||
indentRegex = new RegExp("(\t|[ ]{#{tabLength}}){#{Math.floor(indent)}}")
|
||||
for row in [start..end]
|
||||
buffer.change([[row, 0], [row, indentString.length]], indentString + commentStartString)
|
||||
line = buffer.lineForRow(row)
|
||||
if indentLength = line.match(indentRegex)?[0].length
|
||||
buffer.insert([row, indentLength], commentStartString)
|
||||
else
|
||||
buffer.change([[row, 0], [row, indentString.length]], indentString + commentStartString)
|
||||
|
||||
# Folds all the foldable lines in the buffer.
|
||||
foldAll: ->
|
||||
|
||||
Reference in New Issue
Block a user