From ac04a8ed66ab09b57c3041fefa9fcf9dd359520d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Mon, 16 Jul 2012 10:45:38 -0700 Subject: [PATCH] Allow additional indentation after line has been auto-indented --- spec/app/edit-session-spec.coffee | 10 ++++++++++ src/app/edit-session.coffee | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index e529b1c56..a3ecf9f2b 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1075,6 +1075,16 @@ describe "EditSession", -> expect(buffer.lineForRow(7).length).toBe 6 expect(editSession.getCursorBufferPosition()).toEqual [7, 6] + it "allows for additional indentation if the cursor is beyond the proper indentation point", -> + buffer.insert([7, 0], " \n") + editSession.tabText = " " + editSession.setCursorBufferPosition [7, 6] + editSession.setAutoIndent(true) + editSession.indent() + expect(buffer.lineForRow(7)).toMatch /^\s+$/ + expect(buffer.lineForRow(7).length).toBe 8 + expect(editSession.getCursorBufferPosition()).toEqual [7, 8] + describe "if editSession.softTabs is false", -> it "inserts a tab character into the buffer", -> editSession.setSoftTabs(false) diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 2a9718ae4..2632abc31 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -134,8 +134,11 @@ class EditSession whitespaceMatch = @lineForBufferRow(@getCursorBufferPosition().row).match /^\s*$/ if @autoIndent and whitespaceMatch indentation = @indentationForRow(@getCursorBufferPosition().row) - @getSelection().selectLine() - @insertText(indentation) + if indentation.length > whitespaceMatch[0].length + @getSelection().selectLine() + @insertText(indentation) + else + @insertText(@tabText) else if @softTabs @insertText(@tabText) else