Handle non-integer indentation level values

This was already occurring when using hard tabs but soft tabs still
had issues.

Refs atom/language-c#7
This commit is contained in:
Kevin Sawicki
2014-03-10 18:45:01 -07:00
parent a79090c65a
commit 86cd7f7a01
2 changed files with 12 additions and 4 deletions

View File

@@ -2552,7 +2552,7 @@ describe "Editor", ->
expect(editor.lineForBufferRow(13)).toBe "}; # too many closing brackets!"
describe "when inserted text does not match a decrease indent pattern", ->
it "does not the indentation", ->
it "does not decrease the indentation", ->
editor.setCursorBufferPosition([12, 0])
editor.insertText(' ')
expect(editor.lineForBufferRow(12)).toBe ' };'
@@ -2786,10 +2786,18 @@ describe "Editor", ->
describe "when the editor uses soft tabs but the row has hard tabs", ->
it "only replaces whitespace charachters", ->
editor.setSoftWrap(true)
editor.setText(" 1\n 2")
editor.setText("\t1\n\t2")
editor.setCursorBufferPosition([0, 0])
editor.setIndentationForBufferRow(0, 2)
expect(editor.getText()).toBe(" 1\n 2")
expect(editor.getText()).toBe(" 1\n\t2")
describe "when the indentation level is a non-integer", ->
it "does not throw an exception", ->
editor.setSoftWrap(true)
editor.setText("\t1\n\t2")
editor.setCursorBufferPosition([0, 0])
editor.setIndentationForBufferRow(0, 2.1)
expect(editor.getText()).toBe(" 1\n\t2")
describe ".reloadGrammar()", ->
beforeEach ->

View File

@@ -400,7 +400,7 @@ class Editor extends Model
# Constructs the string used for tabs.
buildIndentString: (number) ->
if @getSoftTabs()
_.multiplyString(" ", number * @getTabLength())
_.multiplyString(" ", Math.floor(number * @getTabLength()))
else
_.multiplyString("\t", Math.floor(number))