diff --git a/public/js/lib/views/arrow_configuration_view.js b/public/js/lib/views/arrow_configuration_view.js index ae36bca..eb45e04 100644 --- a/public/js/lib/views/arrow_configuration_view.js +++ b/public/js/lib/views/arrow_configuration_view.js @@ -97,10 +97,13 @@ if (!('CSSArrowPlease' in window)) window.CSSArrowPlease = {}; var target = $(ev.currentTarget), val = parseInt(target.val()), increment = ev.keyCode == 38 ? 1 : -1, - multiply = ev.shiftKey ? 10 : 1 + multiply = ev.shiftKey ? 10 : 1, + newVal = val + increment * multiply; - target.val(val + increment * multiply); - this._updateModel(ev) + if (newVal < 0) newVal = 0; + + target.val(newVal); + this._updateModel(ev); } }; diff --git a/public/js/spec/views/arrow_configuration_view_spec.js b/public/js/spec/views/arrow_configuration_view_spec.js index a6388dc..70731d6 100644 --- a/public/js/spec/views/arrow_configuration_view_spec.js +++ b/public/js/spec/views/arrow_configuration_view_spec.js @@ -87,12 +87,15 @@ describe("CSSArrowPlease.ArrowConfigurationView", function () { arrowAttr = object.arrowAttr; $.each(keystrokes, function (i, keystroke) { - var keydown = $.Event('keydown') + var keydown = $.Event('keydown'), + expectedVal = defaultVal + keystroke.increment; keydown.keyCode = keystroke.key; keydown.shiftKey = keystroke.shift; elem.val(defaultVal).trigger(keydown); - expect( arrow.get(arrowAttr) ).toEqual(defaultVal + keystroke.increment); + + if (expectedVal < 0) expectedVal = 0; + expect( arrow.get(arrowAttr) ).toEqual(expectedVal); }); }); });