mirror of
https://github.com/atom/atom.git
synced 2026-02-05 20:25:04 -05:00
Don't set un-parseable numbers to 0 in the config
Previously if an integer or float field was empty it would default to zero instead of undefined which made it inconsistent with string value fields. Now the config value is only set as a Number when it can be parsed as one.
This commit is contained in:
@@ -22,17 +22,20 @@ class ConfigPanel extends View
|
||||
input.attr('checked', value)
|
||||
else
|
||||
input.val(value) if value
|
||||
input.on 'change', ->
|
||||
input.on 'change', =>
|
||||
value = input.val()
|
||||
config.set name, switch type
|
||||
when 'int'
|
||||
parseInt(value)
|
||||
when 'float'
|
||||
parseFloat(value)
|
||||
when 'checkbox'
|
||||
!!input.attr('checked')
|
||||
else
|
||||
value
|
||||
if type == 'checkbox'
|
||||
value = !!input.attr('checked')
|
||||
else
|
||||
value = @parseValue(type, value)
|
||||
config.set(name, value)
|
||||
|
||||
parseValue: (type, value) ->
|
||||
switch type
|
||||
when 'int' then value = parseInt(value) or value
|
||||
when 'float' then value = parseFloat(value) or value
|
||||
value = undefined if value == ''
|
||||
value
|
||||
|
||||
bindEditors: ->
|
||||
for editor in @find('.editor[id]').views()
|
||||
@@ -45,9 +48,5 @@ class ConfigPanel extends View
|
||||
value ?= ""
|
||||
editor.setText(value.toString())
|
||||
|
||||
editor.getBuffer().on 'contents-modified', ->
|
||||
value = editor.getText()
|
||||
if type == 'int' then value = parseInt(value) or 0
|
||||
if type == 'float' then value = parseFloat(value) or 0
|
||||
if value == "" then value = undefined
|
||||
config.set name, value
|
||||
editor.getBuffer().on 'contents-modified', =>
|
||||
config.set(name, @parseValue(type, editor.getText()))
|
||||
|
||||
Reference in New Issue
Block a user