mirror of
https://github.com/atom/atom.git
synced 2026-01-22 13:28:01 -05:00
Support setting number fields to 0
Previously entering 0 would end up as '0' in the config value instead of as a numeric value.
This commit is contained in:
@@ -39,6 +39,12 @@ describe "ConfigPanel", ->
|
||||
panel.floatInput.val('90.2').change()
|
||||
expect(config.get('foo.float')).toBe 90.2
|
||||
|
||||
panel.intInput.val('0').change()
|
||||
expect(config.get('foo.int')).toBe 0
|
||||
|
||||
panel.floatInput.val('0').change()
|
||||
expect(config.get('foo.float')).toBe 0
|
||||
|
||||
panel.stringInput.val('moo').change()
|
||||
expect(config.get('foo.string')).toBe 'moo'
|
||||
|
||||
@@ -102,6 +108,12 @@ describe "ConfigPanel", ->
|
||||
expect(config.get('foo.float')).toBe undefined
|
||||
expect(config.get('foo.string')).toBe undefined
|
||||
|
||||
panel.intEditor.setText('0')
|
||||
panel.floatEditor.setText('0')
|
||||
window.advanceClock(10000) # wait for contents-modified to be triggered
|
||||
expect(config.get('foo.int')).toBe 0
|
||||
expect(config.get('foo.float')).toBe 0
|
||||
|
||||
it "does not save the config value until it has been changed to a new value", ->
|
||||
class TestPanel extends ConfigPanel
|
||||
@content: ->
|
||||
|
||||
@@ -32,8 +32,12 @@ class ConfigPanel extends View
|
||||
|
||||
parseValue: (type, value) ->
|
||||
switch type
|
||||
when 'int' then value = parseInt(value) or value
|
||||
when 'float' then value = parseFloat(value) or value
|
||||
when 'int'
|
||||
intValue = parseInt(value)
|
||||
value = intValue unless isNaN(intValue)
|
||||
when 'float'
|
||||
floatValue = parseFloat(value)
|
||||
value = floatValue unless isNaN(floatValue)
|
||||
value = undefined if value == ''
|
||||
value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user