Always auto indent at least one hard tab

Previously when the delta between the suggested and current indent level
was greater than zero but less than one, no text would be inserted since
Editor::buildIndentString returns an empty string for levels less than one
when using hard tabs.

Closes #3575
This commit is contained in:
Kevin Sawicki 2014-09-18 15:36:31 -07:00
parent 7f3279e789
commit 021278e902
2 changed files with 11 additions and 0 deletions

View File

@ -2330,6 +2330,16 @@ describe "Editor", ->
expect(buffer.lineForRow(5)).toMatch /^\t\t\t$/
expect(editor.getCursorBufferPosition()).toEqual [5, 3]
describe "when the difference between the suggested level of indentation and the current level of indentation is greater than 0 but less than 1", ->
it "inserts one tab", ->
editor.setSoftTabs(false)
buffer.setText(" \ntest")
editor.setCursorBufferPosition [1, 0]
editor.indent(autoIndent: true)
expect(buffer.lineForRow(1)).toBe '\ttest'
expect(editor.getCursorBufferPosition()).toEqual [1, 1]
describe "when the line's indent level is greater than the suggested level of indentation", ->
describe "when 'softTabs' is true (the default)", ->
it "moves the cursor to the end of the leading whitespace and inserts 'tabLength' spaces into the buffer", ->

View File

@ -596,6 +596,7 @@ class Selection extends Model
delta = desiredIndent - @cursor.getIndentLevel()
if autoIndent and delta > 0
delta = Math.max(delta, 1) unless @editor.getSoftTabs()
@insertText(@editor.buildIndentString(delta))
else
@insertText(@editor.buildIndentString(1, @cursor.getBufferColumn()))