Ignore first modified event in config editor

This event comes from initially setting the text for the current
config value on the editor and was causing the config to be
immediately saved multiple times when opened.
This commit is contained in:
Kevin Sawicki
2013-04-30 21:55:43 -07:00
parent ca7da8a0da
commit 047d9525e7
2 changed files with 16 additions and 2 deletions

View File

@@ -67,6 +67,7 @@ describe "ConfigPanel", ->
config.set('foo.float', 1.1)
config.set('foo.string', 'I think therefore I am.')
panel = new TestPanel
window.advanceClock(10000) # wait for contents-modified to be triggered
expect(panel.intEditor.getText()).toBe '1'
expect(panel.floatEditor.getText()).toBe '1.1'
expect(panel.stringEditor.getText()).toBe 'I think therefore I am.'
@@ -100,3 +101,15 @@ describe "ConfigPanel", ->
expect(config.get('foo.int')).toBe undefined
expect(config.get('foo.float')).toBe undefined
expect(config.get('foo.string')).toBe undefined
it "does not save the config value until it has been changed to a new value", ->
class TestPanel extends ConfigPanel
@content: ->
@div =>
@subview "foo.int", new Editor(mini: true, attributes: {id: 'foo.int', type: 'int'})
config.set('foo.int', 1)
spyOn(config, 'set')
new TestPanel
window.advanceClock(10000) # wait for contents-modified to be triggered
expect(config.set).not.toHaveBeenCalled()

View File

@@ -48,5 +48,6 @@ class ConfigPanel extends View
value ?= ""
editor.setText(value.toString())
editor.getBuffer().on 'contents-modified', =>
config.set(name, @parseValue(type, editor.getText()))
editor.getBuffer().one 'contents-modified', =>
editor.getBuffer().on 'contents-modified', =>
config.set(name, @parseValue(type, editor.getText()))