diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index f739edcc4..c7fb88148 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -2262,7 +2262,7 @@ describe "TextEditor", -> expect(editor.indentationForBufferRow(2)).toBe 0 expect(editor.indentationForBufferRow(3)).toBe 1 - describe "when a newline is appended on a line that matches the decreaseNextIndentRegex", -> + describe "when a newline is appended on a line that matches the decreaseNextIndentPattern", -> it "indents the new line to the correct level when editor.autoIndent is true", -> waitsForPromise -> atom.packages.activatePackage('language-go') @@ -3012,7 +3012,19 @@ describe "TextEditor", -> expect(editor.lineTextForBufferRow(7)).toBe("\t\t\t * indent") expect(editor.lineTextForBufferRow(8)).toBe("\t\t\t **/") - describe "when pasting a single line of text", -> + describe "when pasting line(s) above a line that matches the decreaseIndentPattern", -> + it "auto-indents based on the pasted line(s) only", -> + atom.clipboard.write("a(x);\n b(x);\n c(x);\n", indentBasis: 0) + editor.setCursorBufferPosition([7, 0]) + editor.pasteText() + + expect(editor.lineTextForBufferRow(7)).toBe " a(x);" + expect(editor.lineTextForBufferRow(8)).toBe " b(x);" + expect(editor.lineTextForBufferRow(9)).toBe " c(x);" + expect(editor.lineTextForBufferRow(10)).toBe " }" + + + describe "when pasting a line of text without line ending", -> it "does not auto-indent the text", -> atom.clipboard.write("a(x);", indentBasis: 0) editor.setCursorBufferPosition([5, 0]) diff --git a/src/language-mode.coffee b/src/language-mode.coffee index d382970c7..3c21a5f63 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -234,14 +234,15 @@ class LanguageMode # # Returns a {Number}. suggestedIndentForBufferRow: (bufferRow, options) -> + line = @buffer.lineForRow(bufferRow) tokenizedLine = @editor.displayBuffer.tokenizedBuffer.tokenizedLineForRow(bufferRow) - @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, tokenizedLine, options) + @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options) suggestedIndentForLineAtBufferRow: (bufferRow, line, options) -> tokenizedLine = @editor.displayBuffer.tokenizedBuffer.buildTokenizedLineForRowWithText(bufferRow, line) - @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, tokenizedLine, options) + @suggestedIndentForTokenizedLineAtBufferRow(bufferRow, line, tokenizedLine, options) - suggestedIndentForTokenizedLineAtBufferRow: (bufferRow, tokenizedLine, options) -> + suggestedIndentForTokenizedLineAtBufferRow: (bufferRow, line, tokenizedLine, options={}) -> iterator = tokenizedLine.getTokenIterator() iterator.next() scopeDescriptor = new ScopeDescriptor(scopes: iterator.getScopes()) @@ -253,7 +254,7 @@ class LanguageMode currentIndentLevel = @editor.indentationForBufferRow(bufferRow) return currentIndentLevel unless increaseIndentRegex - if options?.skipBlankLines ? true + if options.skipBlankLines ? true precedingRow = @buffer.previousNonBlankRow(bufferRow) return 0 unless precedingRow? else @@ -268,10 +269,7 @@ class LanguageMode desiredIndentLevel += 1 if increaseIndentRegex?.testSync(precedingLine) desiredIndentLevel -= 1 if decreaseNextIndentRegex?.testSync(precedingLine) - unless @editor.isBufferRowCommented(bufferRow) - bufferLine = @buffer.lineForRow(bufferRow) - desiredIndentLevel -= 1 if decreaseIndentRegex?.testSync(bufferLine) - + desiredIndentLevel -= 1 if decreaseIndentRegex?.testSync(line) Math.max(desiredIndentLevel, 0) # Calculate a minimum indent level for a range of lines excluding empty lines.