From ecad6bc2a88aec1ba5d773eba91bb3d57310ec9d Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 24 Apr 2013 16:14:35 -0700 Subject: [PATCH] Don't allow float or int Editor's to have NaN as a value --- spec/app/config-panel-spec.coffee | 6 ++++++ src/app/config-panel.coffee | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/app/config-panel-spec.coffee b/spec/app/config-panel-spec.coffee index 3fbf322d5..dd231eb2f 100644 --- a/spec/app/config-panel-spec.coffee +++ b/spec/app/config-panel-spec.coffee @@ -72,3 +72,9 @@ describe "ConfigPanel", -> expect(config.get('foo.int')).toBe 3 expect(config.get('foo.float')).toBe 3.3 expect(config.get('foo.string')).toBe 'All limitations are self imposed.' + + panel.intEditor.setText('') + panel.floatEditor.setText('ha ha') + window.advanceClock(10000) # wait for contents-modified to be triggered + expect(config.get('foo.int')).toBe 0 + expect(config.get('foo.float')).toBe 0 diff --git a/src/app/config-panel.coffee b/src/app/config-panel.coffee index 2482718a1..aa3cc1164 100644 --- a/src/app/config-panel.coffee +++ b/src/app/config-panel.coffee @@ -32,6 +32,7 @@ class ConfigPanel extends View bindEditors: -> for editor in @find('.editor[id]').views() + console.log editor do (editor) => name = editor.attr('id') type = editor.attr('type') @@ -41,6 +42,6 @@ class ConfigPanel extends View editor.getBuffer().on 'contents-modified', -> value = editor.getText() - if type == 'int' then value = parseInt(value) - if type == 'float' then value = parseFloat(value) + if type == 'int' then value = parseInt(value) or 0 + if type == 'float' then value = parseFloat(value) or 0 config.set name, value