From 437b0decab6d9b2c151b805ef5f1b4638719386f Mon Sep 17 00:00:00 2001 From: steffen Date: Sat, 31 May 2014 13:32:14 +0200 Subject: [PATCH] Fix indenting of HTML (closing) tags for instance. Fix #1294 The indentation level is not anymore reduced by adding a new line, which previously caused multiple reductions of the indentation level. This fixes the behavior of HTML closing tags, which currently "jump" backwards if you try to move them down. --- spec/editor-spec.coffee | 7 +++++++ src/selection.coffee | 3 +++ 2 files changed, 10 insertions(+) diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 4a2cce174..704d062fb 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1616,6 +1616,13 @@ describe "Editor", -> expect(editor.lineForBufferRow(1)).toBe ' ' expect(editor.lineForBufferRow(2)).toBe '}' + describe "when a new line is appended before a closing tag (e.g. by pressing enter before a selection)", -> + it "moves the line down and keeps the indentation level the same when editor.autoIndent is true", -> + atom.config.set('editor.autoIndent', true) + editor.setCursorBufferPosition([9,2]) + editor.insertNewline() + expect(editor.lineForBufferRow(10)).toBe ' };' + describe ".backspace()", -> describe "when there is a single cursor", -> changeScreenRangeHandler = null diff --git a/src/selection.coffee b/src/selection.coffee index e3eeb15a3..0c3161837 100644 --- a/src/selection.coffee +++ b/src/selection.coffee @@ -305,7 +305,10 @@ class Selection extends Model if options.autoIndent @editor.autoIndentBufferRow(row) for row in newBufferRange.getRows() else if options.autoIndentNewline and text == '\n' + currentIndentation = @editor.indentationForBufferRow(newBufferRange.start.row) @editor.autoIndentBufferRow(newBufferRange.end.row, preserveLeadingWhitespace: true) + if @editor.indentationForBufferRow(newBufferRange.end.row) < currentIndentation + @editor.setIndentationForBufferRow(newBufferRange.end.row, currentIndentation) else if options.autoDecreaseIndent and /\S/.test text @editor.autoDecreaseIndentForBufferRow(newBufferRange.start.row)