Comparar commits

...

5 Commits

Autor SHA1 Mensagem Data
Max Brunsfeld cffe733641 Fix config event subscription methods
Signed-off-by: Nathan Sobo <nathan@github.com>
2014-12-19 17:28:33 -08:00
Nathan Sobo 3127171b2b Fix Config::isDefault 2014-12-19 16:47:24 -08:00
Nathan Sobo 1d48cb641c Fix Config::save 2014-12-19 16:47:24 -08:00
Nathan Sobo b7b5852863 Store all settings in the scoped property store
There are a few failing specs, but I think they can all be addressed by
having a `source` for all properties and using it to target only the
user settings in various cases.
2014-12-19 16:47:18 -08:00
Max Brunsfeld d104e68342 Revert "Revert "Merge pull request #4631""
This reverts commit dc2a453986.

Conflicts:
	spec/config-spec.coffee
	src/config.coffee
2014-12-19 14:20:27 -08:00
12 arquivos alterados com 573 adições e 374 exclusões
+307 -146
Ver Arquivo
@@ -2,6 +2,7 @@ path = require 'path'
temp = require 'temp' temp = require 'temp'
CSON = require 'season' CSON = require 'season'
fs = require 'fs-plus' fs = require 'fs-plus'
Grim = require 'grim'
describe "Config", -> describe "Config", ->
dotAtomPath = null dotAtomPath = null
@@ -34,6 +35,36 @@ describe "Config", ->
atom.config.setDefaults("bar", baz: 7) atom.config.setDefaults("bar", baz: 7)
expect(atom.config.get("bar.baz")).toEqual {a: 3} expect(atom.config.get("bar.baz")).toEqual {a: 3}
describe "when a 'sources' option is specified", ->
it "only retrieves values from the specified sources", ->
atom.config.set("x.y", 1, scopeSelector: ".foo", source: "a")
atom.config.set("x.y", 2, scopeSelector: ".foo", source: "b")
atom.config.set("x.y", 3, scopeSelector: ".foo", source: "c")
atom.config.setSchema("x.y", type: "integer", default: 4)
expect(atom.config.get("x.y", sources: ["a"], scope: [".foo"])).toBe 1
expect(atom.config.get("x.y", sources: ["b"], scope: [".foo"])).toBe 2
expect(atom.config.get("x.y", sources: ["c"], scope: [".foo"])).toBe 3
# Schema defaults never match a specific source. We could potentially add a special "schema" source.
expect(atom.config.get("x.y", sources: ["x"], scope: [".foo"])).toBeUndefined()
expect(atom.config.get(null, sources: ['a'], scope: [".foo"]).x.y).toBe 1
describe "when an 'excludeSources' option is specified", ->
it "only retrieves values from the specified sources", ->
atom.config.set("x.y", 0)
atom.config.set("x.y", 1, scopeSelector: ".foo", source: "a")
atom.config.set("x.y", 2, scopeSelector: ".foo", source: "b")
atom.config.set("x.y", 3, scopeSelector: ".foo", source: "c")
atom.config.setSchema("x.y", type: "integer", default: 4)
expect(atom.config.get("x.y", excludeSources: ["a"], scope: [".foo"])).toBe 3
expect(atom.config.get("x.y", excludeSources: ["c"], scope: [".foo"])).toBe 2
expect(atom.config.get("x.y", excludeSources: ["b", "c"], scope: [".foo"])).toBe 1
expect(atom.config.get("x.y", excludeSources: ["b", "c", "a"], scope: [".foo"])).toBe 0
expect(atom.config.get("x.y", excludeSources: ["b", "c", "a", atom.config.getUserConfigPath()], scope: [".foo"])).toBe 4
expect(atom.config.get("x.y", excludeSources: [atom.config.getUserConfigPath()])).toBe 4
describe ".set(keyPath, value)", -> describe ".set(keyPath, value)", ->
it "allows a key path's value to be written", -> it "allows a key path's value to be written", ->
expect(atom.config.set("foo.bar.baz", 42)).toBe true expect(atom.config.set("foo.bar.baz", 42)).toBe true
@@ -50,7 +81,7 @@ describe "Config", ->
expect(observeHandler).toHaveBeenCalledWith 42 expect(observeHandler).toHaveBeenCalledWith 42
describe "when the value equals the default value", -> describe "when the value equals the default value", ->
it "does not store the value", -> it "does not store the value in the user's config", ->
atom.config.setDefaults "foo", atom.config.setDefaults "foo",
same: 1 same: 1
changes: 1 changes: 1
@@ -66,60 +97,84 @@ describe "Config", ->
atom.config.set('foo.null', undefined) atom.config.set('foo.null', undefined)
atom.config.set('foo.undefined', null) atom.config.set('foo.undefined', null)
atom.config.set('foo.sameObject', {b: 2, a: 1}) atom.config.set('foo.sameObject', {b: 2, a: 1})
expect(atom.config.settings.foo).toEqual {changes: 2}
expect(atom.config.get("foo.same", sources: [atom.config.getUserConfigPath()])).toBeUndefined()
expect(atom.config.get("foo.changes", sources: [atom.config.getUserConfigPath()])).toBe 2
atom.config.set('foo.changes', 1) atom.config.set('foo.changes', 1)
expect(atom.config.settings.foo).toEqual {} expect(atom.config.get("foo.changes", sources: [atom.config.getUserConfigPath()])).toBeUndefined()
describe ".getDefault(keyPath)", -> describe ".getDefault(keyPath)", ->
it "returns a clone of the default value", -> it "returns a clone of the default value", ->
atom.config.setDefaults("foo", same: 1, changes: 1) atom.config.setDefaults("foo", same: 1, changes: 1)
spyOn(Grim, 'deprecate')
expect(atom.config.getDefault('foo.same')).toBe 1 expect(atom.config.getDefault('foo.same')).toBe 1
expect(atom.config.getDefault('foo.changes')).toBe 1 expect(atom.config.getDefault('foo.changes')).toBe 1
expect(Grim.deprecate.callCount).toBe 2
atom.config.set('foo.same', 2) atom.config.set('foo.same', 2)
atom.config.set('foo.changes', 3) atom.config.set('foo.changes', 3)
expect(atom.config.getDefault('foo.same')).toBe 1 expect(atom.config.getDefault('foo.same')).toBe 1
expect(atom.config.getDefault('foo.changes')).toBe 1 expect(atom.config.getDefault('foo.changes')).toBe 1
expect(Grim.deprecate.callCount).toBe 4
initialDefaultValue = [1, 2, 3] initialDefaultValue = [1, 2, 3]
atom.config.setDefaults("foo", bar: initialDefaultValue) atom.config.setDefaults("foo", bar: initialDefaultValue)
expect(atom.config.getDefault('foo.bar')).toEqual initialDefaultValue expect(atom.config.getDefault('foo.bar')).toEqual initialDefaultValue
expect(atom.config.getDefault('foo.bar')).not.toBe initialDefaultValue expect(atom.config.getDefault('foo.bar')).not.toBe initialDefaultValue
expect(Grim.deprecate.callCount).toBe 6
describe "when scoped settings are used", -> describe "when scoped settings are used", ->
it "returns the global default when no scoped default set", -> it "returns the global default when no scoped default set", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 10
it "returns the scoped default when a scoped default is set", -> spyOn(Grim, 'deprecate')
expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 10
expect(Grim.deprecate).toHaveBeenCalled()
it "returns the scoped settings not including the user's config file", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42) atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42)
expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42
atom.config.set('.source.coffee', 'foo.bar.baz', 55) spyOn(Grim, 'deprecate')
expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42 expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42
expect(Grim.deprecate.callCount).toBe 1
atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
expect(atom.config.getDefault('.source.coffee', 'foo.bar.baz')).toBe 42
expect(Grim.deprecate.callCount).toBe 2
describe ".isDefault(keyPath)", -> describe ".isDefault(keyPath)", ->
it "returns true when the value of the key path is its default value", -> it "returns true when the value of the key path is its default value", ->
atom.config.setDefaults("foo", same: 1, changes: 1) atom.config.setDefaults("foo", same: 1, changes: 1)
spyOn(Grim, 'deprecate')
expect(atom.config.isDefault('foo.same')).toBe true expect(atom.config.isDefault('foo.same')).toBe true
expect(atom.config.isDefault('foo.changes')).toBe true expect(atom.config.isDefault('foo.changes')).toBe true
expect(Grim.deprecate.callCount).toBe 2
atom.config.set('foo.same', 2) atom.config.set('foo.same', 1)
atom.config.set('foo.changes', 3) atom.config.set('foo.changes', 3)
expect(atom.config.isDefault('foo.same')).toBe false
expect(atom.config.isDefault('foo.same')).toBe true
expect(atom.config.isDefault('foo.changes')).toBe false expect(atom.config.isDefault('foo.changes')).toBe false
expect(Grim.deprecate.callCount).toBe 4
describe "when scoped settings are used", -> describe "when scoped settings are used", ->
it "returns false when a scoped setting was set by the user", -> it "returns false when a scoped setting was set by the user", ->
spyOn(Grim, 'deprecate')
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true
expect(Grim.deprecate.callCount).toBe 1
atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42) atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42)
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe true
expect(Grim.deprecate.callCount).toBe 2
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe false expect(atom.config.isDefault('.source.coffee', 'foo.bar.baz')).toBe false
expect(Grim.deprecate.callCount).toBe 3
describe ".setDefaults(keyPath)", -> describe ".setDefaults(keyPath)", ->
it "sets a default when the setting's key contains an escaped dot", -> it "sets a default when the setting's key contains an escaped dot", ->
@@ -150,17 +205,17 @@ describe "Config", ->
atom.config.toggle('foo.a') atom.config.toggle('foo.a')
expect(atom.config.get('foo.a')).toBe false expect(atom.config.get('foo.a')).toBe false
describe ".restoreDefault(keyPath)", -> describe ".unset(keyPath, {scope})", ->
it "sets the value of the key path to its default", -> it "sets the value of the key path to its default", ->
atom.config.setDefaults('a', b: 3) atom.config.setDefaults('a', b: 3)
atom.config.set('a.b', 4) atom.config.set('a.b', 4)
expect(atom.config.get('a.b')).toBe 4 expect(atom.config.get('a.b')).toBe 4
atom.config.restoreDefault('a.b') atom.config.unset('a.b')
expect(atom.config.get('a.b')).toBe 3 expect(atom.config.get('a.b')).toBe 3
atom.config.set('a.c', 5) atom.config.set('a.c', 5)
expect(atom.config.get('a.c')).toBe 5 expect(atom.config.get('a.c')).toBe 5
atom.config.restoreDefault('a.c') atom.config.unset('a.c')
expect(atom.config.get('a.c')).toBeUndefined() expect(atom.config.get('a.c')).toBeUndefined()
it "calls ::save()", -> it "calls ::save()", ->
@@ -168,43 +223,61 @@ describe "Config", ->
atom.config.set('a.b', 4) atom.config.set('a.b', 4)
atom.config.save.reset() atom.config.save.reset()
atom.config.restoreDefault('a.c') atom.config.unset('a.c')
expect(atom.config.save.callCount).toBe 1 expect(atom.config.save.callCount).toBe 1
describe "when scoped settings are used", -> describe "when scoped settings are used", ->
it "restores the global default when no scoped default set", -> it "restores the global default when no scoped default set", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 55
atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') atom.config.unset('foo.bar.baz', scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 10 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 10
it "restores the scoped default when a scoped default is set", -> it "restores the scoped default when a scoped default is set", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42) atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42)
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
atom.config.set('.source.coffee', 'foo.bar.ok', 100) atom.config.set('foo.bar.ok', 100, scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 55
atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') atom.config.unset('foo.bar.baz', scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 42 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 42
expect(atom.config.get(['.source.coffee'], 'foo.bar.ok')).toBe 100 expect(atom.config.get('foo.bar.ok', scope: ['.source.coffee'])).toBe 100
it "calls ::save()", -> it "calls ::save()", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42) atom.config.addScopedSettings("default", ".source.coffee", foo: bar: baz: 42)
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
atom.config.save.reset() atom.config.save.reset()
atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') atom.config.unset('foo.bar.baz', scopeSelector: '.source.coffee')
expect(atom.config.save.callCount).toBe 1 expect(atom.config.save.callCount).toBe 1
it "allows removing settings for a specific source and scope selector", ->
atom.config.set('foo.bar', 55, scopeSelector: '.source.coffee', source: "source-a")
atom.config.set('foo.bar', 65, scopeSelector: '.source.coffee', source: "source-b")
expect(atom.config.get('foo.bar', scope: ['.source.coffee'])).toBe 65
atom.config.unset('foo.bar', source: "source-b", scopeSelector: ".source.coffee")
expect(atom.config.get('foo.bar', scope: ['.source.coffee', '.string'])).toBe 55
it "allows removing all settings for a specific source", ->
atom.config.set('foo.bar', 55, scopeSelector: '.source.coffee', source: "source-a")
atom.config.set('foo.bar', 65, scopeSelector: '.source.coffee', source: "source-b")
atom.config.set('foo.baz', 65, scopeSelector: '.source.coffee', source: "source-b")
expect(atom.config.get('foo.bar', scope: ['.source.coffee'])).toBe 65
atom.config.unset(null, source: "source-b", scopeSelector: ".source.coffee")
expect(atom.config.get('foo.bar', scope: ['.source.coffee', '.string'])).toBe 55
expect(atom.config.get('foo.baz', scope: ['.source.coffee', '.string'])).toBe undefined
it "does not call ::save or add a scoped property when no value has been set", -> it "does not call ::save or add a scoped property when no value has been set", ->
# see https://github.com/atom/atom/issues/4175 # see https://github.com/atom/atom/issues/4175
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') atom.config.unset('foo.bar.baz', scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 10 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 10
expect(atom.config.save).not.toHaveBeenCalled() expect(atom.config.save).not.toHaveBeenCalled()
@@ -216,14 +289,14 @@ describe "Config", ->
jasmine.unspy atom.config, 'save' jasmine.unspy atom.config, 'save'
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
atom.config.set('.source.coffee', 'foo.bar.zfoo', 20) atom.config.set('foo.bar.zfoo', 20, scopeSelector: '.source.coffee')
CSON.writeFileSync.reset() CSON.writeFileSync.reset()
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 55
atom.config.restoreDefault('.source.coffee', 'foo.bar.baz') atom.config.unset('foo.bar.baz', scopeSelector: '.source.coffee')
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 10 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 10
expect(atom.config.get(['.source.coffee'], 'foo.bar.zfoo')).toBe 20 expect(atom.config.get('foo.bar.zfoo', scope: ['.source.coffee'])).toBe 20
expect(CSON.writeFileSync).toHaveBeenCalled() expect(CSON.writeFileSync).toHaveBeenCalled()
properties = CSON.writeFileSync.mostRecentCall.args[1] properties = CSON.writeFileSync.mostRecentCall.args[1]
expect(properties['.coffee.source']).toEqual expect(properties['.coffee.source']).toEqual
@@ -232,19 +305,29 @@ describe "Config", ->
zfoo: 20 zfoo: 20
CSON.writeFileSync.reset() CSON.writeFileSync.reset()
atom.config.restoreDefault('.source.coffee', 'foo.bar.zfoo') atom.config.unset('foo.bar.zfoo', scopeSelector: '.source.coffee')
expect(CSON.writeFileSync).toHaveBeenCalled() expect(CSON.writeFileSync).toHaveBeenCalled()
properties = CSON.writeFileSync.mostRecentCall.args[1] properties = CSON.writeFileSync.mostRecentCall.args[1]
expect(properties['.coffee.source']).toBeUndefined() expect(properties['.coffee.source']).toBeUndefined()
it "does not call ::save when the value is already at the default", -> it "does not call ::save when the value is already at the default", ->
atom.config.setDefaults("foo", bar: baz: 10) atom.config.setDefaults("foo", bar: baz: 10)
atom.config.set('.source.coffee', 'foo.bar.baz', 55) atom.config.set('foo.bar.baz', 55)
atom.config.save.reset() atom.config.save.reset()
atom.config.restoreDefault('.source.coffee', 'foo.bar.ok') atom.config.unset('foo.bar.ok', scopeSelector: '.source.coffee')
expect(atom.config.save).not.toHaveBeenCalled() expect(atom.config.save).not.toHaveBeenCalled()
expect(atom.config.get(['.source.coffee'], 'foo.bar.baz')).toBe 55 expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 55
it "deprecates passing a scope selector as the first argument", ->
atom.config.setDefaults("foo", bar: baz: 10)
atom.config.set('foo.bar.baz', 55, scopeSelector: '.source.coffee')
spyOn(Grim, 'deprecate')
atom.config.unset('.source.coffee', 'foo.bar.baz')
expect(Grim.deprecate).toHaveBeenCalled()
expect(atom.config.get('foo.bar.baz', scope: ['.source.coffee'])).toBe 10
describe ".getSettings()", -> describe ".getSettings()", ->
it "returns all settings including defaults", -> it "returns all settings including defaults", ->
@@ -321,56 +404,37 @@ describe "Config", ->
spyOn(CSON, 'writeFileSync') spyOn(CSON, 'writeFileSync')
jasmine.unspy atom.config, 'save' jasmine.unspy atom.config, 'save'
describe "when ~/.atom/config.json exists", -> it "writes properties from the user config path source to the user config path", ->
it "writes any non-default properties to ~/.atom/config.json", -> atom.config.configFilePath = "/fake/config/path"
atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.json") atom.config.set("a.b.c", 1)
atom.config.set("a.b.c", 1) atom.config.set("a.b.d", 2)
atom.config.set("a.b.d", 2) atom.config.set("x.y.z", 3)
atom.config.set("x.y.z", 3) atom.config.set("x.y.q", 3, source: "/not/user/config")
atom.config.setDefaults("a.b", e: 4, f: 5) atom.config.set('foo.bar', 'ruby', scopeSelector: '.source.ruby')
atom.config.set('foo.omg', 'wow', scopeSelector: '.source.ruby')
atom.config.set('foo.bar', 'coffee', scopeSelector: '.source.coffee')
CSON.writeFileSync.reset() atom.config.setDefaults("a.b", e: 4, f: 5)
atom.config.save()
expect(CSON.writeFileSync.argsForCall[0][0]).toBe(path.join(atom.config.configDirPath, "atom.config.json")) CSON.writeFileSync.reset()
writtenConfig = CSON.writeFileSync.argsForCall[0][1] atom.config.save()
expect(writtenConfig).toEqual global: atom.config.settings
describe "when ~/.atom/config.json doesn't exist", -> expect(CSON.writeFileSync.argsForCall[0][0]).toBe atom.config.getUserConfigPath()
it "writes any non-default properties to ~/.atom/config.cson", -> writtenConfig = CSON.writeFileSync.argsForCall[0][1]
atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson") global.debug = true
atom.config.set("a.b.c", 1) expect(writtenConfig).toEqual
atom.config.set("a.b.d", 2) 'global':
atom.config.set("x.y.z", 3) a: b:
atom.config.setDefaults("a.b", e: 4, f: 5) c: 1
d: 2
CSON.writeFileSync.reset() x: y: z: 3
atom.config.save() '.ruby.source':
foo:
expect(CSON.writeFileSync.argsForCall[0][0]).toBe(path.join(atom.config.configDirPath, "atom.config.cson")) bar: 'ruby'
writtenConfig = CSON.writeFileSync.argsForCall[0][1] omg: 'wow'
expect(writtenConfig).toEqual global: atom.config.settings '.coffee.source':
foo:
describe "when scoped settings are defined", -> bar: 'coffee'
it 'writes out explicitly set config settings', ->
atom.config.set('.source.ruby', 'foo.bar', 'ruby')
atom.config.set('.source.ruby', 'foo.omg', 'wow')
atom.config.set('.source.coffee', 'foo.bar', 'coffee')
CSON.writeFileSync.reset()
atom.config.save()
writtenConfig = CSON.writeFileSync.argsForCall[0][1]
expect(writtenConfig).toEqualJson
global:
atom.config.settings
'.ruby.source':
foo:
bar: 'ruby'
omg: 'wow'
'.coffee.source':
foo:
bar: 'coffee'
describe ".setDefaults(keyPath, defaults)", -> describe ".setDefaults(keyPath, defaults)", ->
it "assigns any previously-unassigned keys to the object at the key path", -> it "assigns any previously-unassigned keys to the object at the key path", ->
@@ -411,12 +475,21 @@ describe "Config", ->
atom.config.set('foo.bar.baz', "value 1") atom.config.set('foo.bar.baz', "value 1")
expect(observeHandler).toHaveBeenCalledWith({newValue: 'value 1', oldValue: 'value 2'}) expect(observeHandler).toHaveBeenCalledWith({newValue: 'value 1', oldValue: 'value 2'})
observeHandler.reset()
atom.config.set('foo.bar', {baz: "value 3"})
expect(observeHandler).toHaveBeenCalledWith({newValue: 'value 3', oldValue: 'value 1'})
observeHandler.reset()
atom.config.set('foo.bar', null)
expect(observeHandler).toHaveBeenCalledWith({newValue: undefined, oldValue: 'value 3'})
observeHandler.reset()
describe 'when a keyPath is not specified', -> describe 'when a keyPath is not specified', ->
beforeEach -> beforeEach ->
observeHandler = jasmine.createSpy("observeHandler") observeHandler = jasmine.createSpy("observeHandler")
atom.config.set("foo.bar.baz", "value 1") atom.config.set("foo", bar: baz: "value 1")
observeSubscription = atom.config.onDidChange observeHandler observeSubscription = atom.config.onDidChange(observeHandler)
it "does not fire the given callback initially", -> it "does not fire the given callback initially", ->
expect(observeHandler).not.toHaveBeenCalled() expect(observeHandler).not.toHaveBeenCalled()
@@ -424,6 +497,7 @@ describe "Config", ->
it "fires the callback every time any value changes", -> it "fires the callback every time any value changes", ->
observeHandler.reset() # clear the initial call observeHandler.reset() # clear the initial call
atom.config.set('foo.bar.baz', "value 2") atom.config.set('foo.bar.baz', "value 2")
expect(observeHandler).toHaveBeenCalled() expect(observeHandler).toHaveBeenCalled()
expect(observeHandler.mostRecentCall.args[0].newValue.foo.bar.baz).toBe("value 2") expect(observeHandler.mostRecentCall.args[0].newValue.foo.bar.baz).toBe("value 2")
expect(observeHandler.mostRecentCall.args[0].oldValue.foo.bar.baz).toBe("value 1") expect(observeHandler.mostRecentCall.args[0].oldValue.foo.bar.baz).toBe("value 1")
@@ -446,7 +520,7 @@ describe "Config", ->
beforeEach -> beforeEach ->
observeHandler = jasmine.createSpy("observeHandler") observeHandler = jasmine.createSpy("observeHandler")
atom.config.set("foo.bar.baz", "value 1") atom.config.set("foo.bar.baz", "value 1")
observeSubscription = atom.config.observe "foo.bar.baz", observeHandler observeSubscription = atom.config.observe("foo.bar.baz", observeHandler)
it "fires the given callback with the current value at the keypath", -> it "fires the given callback with the current value at the keypath", ->
expect(observeHandler).toHaveBeenCalledWith("value 1") expect(observeHandler).toHaveBeenCalledWith("value 1")
@@ -459,6 +533,21 @@ describe "Config", ->
atom.config.set('foo.bar.baz', "value 1") atom.config.set('foo.bar.baz', "value 1")
expect(observeHandler).toHaveBeenCalledWith("value 1") expect(observeHandler).toHaveBeenCalledWith("value 1")
observeHandler.reset()
atom.config.set('foo.bar', {baz: "value 3"})
expect(observeHandler).toHaveBeenCalledWith("value 3")
observeHandler.reset()
atom.config.set('foo.bar', null)
expect(observeHandler).toHaveBeenCalledWith(undefined)
observeHandler.reset()
atom.config.set('foo.bar.baz.quux', "value 4")
expect(observeHandler).toHaveBeenCalledWith({quux: "value 4"})
atom.config.set('foo.bar.baz.buzz', "value 5")
expect(observeHandler).toHaveBeenCalledWith({quux: "value 4", buzz: "value 5"})
observeHandler.reset() observeHandler.reset()
atom.config.loadUserConfig() atom.config.loadUserConfig()
@@ -492,6 +581,31 @@ describe "Config", ->
atom.config.set('foo.bar.baz', "value 10") atom.config.set('foo.bar.baz', "value 10")
expect(bazCatHandler).not.toHaveBeenCalled() expect(bazCatHandler).not.toHaveBeenCalled()
describe "observing scoped settings", ->
otherHandler = null
beforeEach ->
observeSubscription.dispose()
otherHandler = jasmine.createSpy('otherHandler')
it "allows settings to be observed in a specific scope", ->
atom.config.observe("foo.bar.baz", scope: [".some.scope"], observeHandler)
atom.config.observe("foo.bar.baz", scope: [".another.scope"], otherHandler)
atom.config.set('foo.bar.baz', "value 2", scopeSelector: ".some")
expect(observeHandler).toHaveBeenCalledWith("value 2")
expect(otherHandler).not.toHaveBeenCalledWith("value 2")
it "deprecates using a scope descriptor as the first argument", ->
spyOn(Grim, 'deprecate')
atom.config.observe([".some.scope"], "foo.bar.baz", observeHandler)
atom.config.observe([".another.scope"], "foo.bar.baz", otherHandler)
expect(Grim.deprecate).toHaveBeenCalled()
atom.config.set('foo.bar.baz', "value 2", scopeSelector: ".some")
expect(observeHandler).toHaveBeenCalledWith("value 2")
expect(otherHandler).not.toHaveBeenCalledWith("value 2")
describe ".transact(callback)", -> describe ".transact(callback)", ->
changeSpy = null changeSpy = null
@@ -544,6 +658,15 @@ describe "Config", ->
atom.config.configDirPath = dotAtomPath atom.config.configDirPath = dotAtomPath
atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson") atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson")
expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy() expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy()
atom.config.setSchema 'foo',
type: 'object'
properties:
bar:
type: 'string'
default: 'def'
int:
type: 'integer'
default: 12
afterEach -> afterEach ->
fs.removeSync(dotAtomPath) fs.removeSync(dotAtomPath)
@@ -563,7 +686,7 @@ describe "Config", ->
it "updates the config data based on the file contents", -> it "updates the config data based on the file contents", ->
expect(atom.config.get("foo.bar")).toBe 'baz' expect(atom.config.get("foo.bar")).toBe 'baz'
expect(atom.config.get(['.source.ruby'], "foo.bar")).toBe 'more-specific' expect(atom.config.get("foo.bar", scope: ['.source.ruby'])).toBe 'more-specific'
describe "when the config file contains valid cson", -> describe "when the config file contains valid cson", ->
beforeEach -> beforeEach ->
@@ -601,43 +724,42 @@ describe "Config", ->
expect(fs.existsSync(atom.config.configFilePath)).toBe true expect(fs.existsSync(atom.config.configFilePath)).toBe true
expect(CSON.readFileSync(atom.config.configFilePath)).toEqual {} expect(CSON.readFileSync(atom.config.configFilePath)).toEqual {}
describe "when a schema is specified", -> describe "when the config file contains values that do not adhere to the schema", ->
warnSpy = null
beforeEach -> beforeEach ->
schema = warnSpy = spyOn console, 'warn'
type: 'object' fs.writeFileSync atom.config.configFilePath, """
properties: foo:
bar: bar: 'baz'
type: 'string' int: 'bad value'
default: 'def' """
int: atom.config.loadUserConfig()
type: 'integer'
default: 12
atom.config.setSchema('foo', schema) it "updates the only the settings that have values matching the schema", ->
expect(atom.config.get("foo.bar")).toBe 'baz'
expect(atom.config.get("foo.int")).toBe 12
describe "when the config file contains values that do not adhere to the schema", -> expect(warnSpy).toHaveBeenCalled()
warnSpy = null expect(warnSpy.mostRecentCall.args[0]).toContain "foo.int"
beforeEach ->
warnSpy = spyOn console, 'warn'
fs.writeFileSync atom.config.configFilePath, """
foo:
bar: 'baz'
int: 'bad value'
"""
atom.config.loadUserConfig()
it "updates the only the settings that have values matching the schema", ->
expect(atom.config.get("foo.bar")).toBe 'baz'
expect(atom.config.get("foo.int")).toBe 12
expect(warnSpy).toHaveBeenCalled()
expect(warnSpy.mostRecentCall.args[0]).toContain "'foo.int' could not be set"
describe ".observeUserConfig()", -> describe ".observeUserConfig()", ->
updatedHandler = null updatedHandler = null
beforeEach -> beforeEach ->
atom.config.setDefaults('foo', bar: 'def') atom.config.setSchema 'foo',
type: 'object'
properties:
bar:
type: 'string'
default: 'def'
baz:
type: 'string'
scoped:
type: 'boolean'
int:
type: 'integer'
default: 12
atom.config.configDirPath = dotAtomPath atom.config.configDirPath = dotAtomPath
atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson") atom.config.configFilePath = path.join(atom.config.configDirPath, "atom.config.cson")
expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy() expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy()
@@ -670,32 +792,38 @@ describe "Config", ->
it "does not fire a change event for paths that did not change", -> it "does not fire a change event for paths that did not change", ->
atom.config.onDidChange 'foo.bar', noChangeSpy = jasmine.createSpy() atom.config.onDidChange 'foo.bar', noChangeSpy = jasmine.createSpy()
fs.writeFileSync(atom.config.configFilePath, "foo: { bar: 'baz', omg: 'ok'}") fs.writeFileSync(atom.config.configFilePath, "foo: { bar: 'baz', baz: 'ok'}")
waitsFor 'update event', -> updatedHandler.callCount > 0 waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> runs ->
expect(noChangeSpy).not.toHaveBeenCalled() expect(noChangeSpy).not.toHaveBeenCalled()
expect(atom.config.get('foo.bar')).toBe 'baz' expect(atom.config.get('foo.bar')).toBe 'baz'
expect(atom.config.get('foo.omg')).toBe 'ok' expect(atom.config.get('foo.baz')).toBe 'ok'
describe 'when the default value is a complex value', -> describe 'when the default value is a complex value', ->
beforeEach -> beforeEach ->
atom.config.setSchema 'foo.bar',
type: 'array'
items:
type: 'string'
fs.writeFileSync(atom.config.configFilePath, "foo: { bar: ['baz', 'ok']}") fs.writeFileSync(atom.config.configFilePath, "foo: { bar: ['baz', 'ok']}")
waitsFor 'update event', -> updatedHandler.callCount > 0 waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> updatedHandler.reset() runs -> updatedHandler.reset()
it "does not fire a change event for paths that did not change", -> it "does not fire a change event for paths that did not change", ->
atom.config.onDidChange 'foo.bar', noChangeSpy = jasmine.createSpy() noChangeSpy = jasmine.createSpy()
atom.config.onDidChange('foo.bar', noChangeSpy)
fs.writeFileSync(atom.config.configFilePath, "foo: { bar: ['baz', 'ok'], omg: 'another'}") fs.writeFileSync(atom.config.configFilePath, "foo: { bar: ['baz', 'ok'], baz: 'another'}")
waitsFor 'update event', -> updatedHandler.callCount > 0 waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> runs ->
expect(noChangeSpy).not.toHaveBeenCalled() expect(noChangeSpy).not.toHaveBeenCalled()
expect(atom.config.get('foo.bar')).toEqual ['baz', 'ok'] expect(atom.config.get('foo.bar')).toEqual ['baz', 'ok']
expect(atom.config.get('foo.omg')).toBe 'another' expect(atom.config.get('foo.baz')).toBe 'another'
describe 'when scoped settings are used', -> describe 'when scoped settings are used', ->
it "fires a change event for scoped settings that are removed", -> it "fires a change event for scoped settings that are removed", ->
atom.config.onDidChange ['.source.ruby'], 'foo.scoped', scopedSpy = jasmine.createSpy() scopedSpy = jasmine.createSpy()
atom.config.onDidChange('foo.scoped', scope: ['.source.ruby'], scopedSpy)
fs.writeFileSync atom.config.configFilePath, """ fs.writeFileSync atom.config.configFilePath, """
global: global:
@@ -705,10 +833,11 @@ describe "Config", ->
waitsFor 'update event', -> updatedHandler.callCount > 0 waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> runs ->
expect(scopedSpy).toHaveBeenCalled() expect(scopedSpy).toHaveBeenCalled()
expect(atom.config.get(['.source.ruby'], 'foo.scoped')).toBe false expect(atom.config.get('foo.scoped', scope: ['.source.ruby'])).toBe false
it "does not fire a change event for paths that did not change", -> it "does not fire a change event for paths that did not change", ->
atom.config.onDidChange ['.source.ruby'], 'foo.scoped', noChangeSpy = jasmine.createSpy() noChangeSpy = jasmine.createSpy()
atom.config.onDidChange('foo.scoped', scope: ['.source.ruby'], noChangeSpy)
fs.writeFileSync atom.config.configFilePath, """ fs.writeFileSync atom.config.configFilePath, """
global: global:
@@ -721,8 +850,8 @@ describe "Config", ->
waitsFor 'update event', -> updatedHandler.callCount > 0 waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> runs ->
expect(noChangeSpy).not.toHaveBeenCalled() expect(noChangeSpy).not.toHaveBeenCalled()
expect(atom.config.get(['.source.ruby'], 'foo.bar')).toBe 'baz' expect(atom.config.get('foo.bar', scope: ['.source.ruby'])).toBe 'baz'
expect(atom.config.get(['.source.ruby'], 'foo.scoped')).toBe true expect(atom.config.get('foo.scoped', scope: ['.source.ruby'])).toBe true
describe "when the config file changes to omit a setting with a default", -> describe "when the config file changes to omit a setting with a default", ->
it "resets the setting back to the default", -> it "resets the setting back to the default", ->
@@ -1125,8 +1254,8 @@ describe "Config", ->
it 'it respects the scoped defaults', -> it 'it respects the scoped defaults', ->
expect(atom.config.get('foo.bar.str')).toBe 'ok' expect(atom.config.get('foo.bar.str')).toBe 'ok'
expect(atom.config.get(['.source.js'], 'foo.bar.str')).toBe 'omg' expect(atom.config.get('foo.bar.str', scope: ['.source.js'])).toBe 'omg'
expect(atom.config.get(['.source.coffee'], 'foo.bar.str')).toBe 'ok' expect(atom.config.get('foo.bar.str', scope: ['.source.coffee'])).toBe 'ok'
describe "scoped settings", -> describe "scoped settings", ->
describe ".get(scopeDescriptor, keyPath)", -> describe ".get(scopeDescriptor, keyPath)", ->
@@ -1135,29 +1264,29 @@ describe "Config", ->
atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22) atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11) atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11)
expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.double.coffee"])).toBe 42
expect(atom.config.get([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22 expect(atom.config.get("foo.bar.baz", scope: [".source.js", ".string.quoted.double.js"])).toBe 22
expect(atom.config.get([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11 expect(atom.config.get("foo.bar.baz", scope: [".source.js", ".variable.assignment.js"])).toBe 11
expect(atom.config.get([".text"], "foo.bar.baz")).toBeUndefined() expect(atom.config.get("foo.bar.baz", scope: [".text"])).toBeUndefined()
it "favors the most recently added properties in the event of a specificity tie", -> it "favors the most recently added properties in the event of a specificity tie", ->
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.single", foo: bar: baz: 42) atom.config.addScopedSettings("config", ".source.coffee .string.quoted.single", foo: bar: baz: 42)
atom.config.addScopedSettings("config", ".source.coffee .string.quoted.double", foo: bar: baz: 22) atom.config.addScopedSettings("config", ".source.coffee .string.quoted.double", foo: bar: baz: 22)
expect(atom.config.get([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.single"])).toBe 42
expect(atom.config.get([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.single.double"])).toBe 22
describe 'when there are global defaults', -> describe 'when there are global defaults', ->
it 'falls back to the global when there is no scoped property specified', -> it 'falls back to the global when there is no scoped property specified', ->
atom.config.setDefaults("foo", hasDefault: 'ok') atom.config.setDefaults("foo", hasDefault: 'ok')
expect(atom.config.get([".source.coffee", ".string.quoted.single"], "foo.hasDefault")).toBe 'ok' expect(atom.config.get("foo.hasDefault", scope: [".source.coffee", ".string.quoted.single"])).toBe 'ok'
describe 'setting priority', -> describe 'setting priority', ->
describe 'when package settings are added after user settings', -> describe 'when package settings are added after user settings', ->
it "returns the user's setting because the user's setting has higher priority", -> it "returns the user's setting because the user's setting has higher priority", ->
atom.config.set(".source.coffee", "foo.bar.baz", 100) atom.config.set("foo.bar.baz", 100, scopeSelector: ".source.coffee")
atom.config.addScopedSettings("some-package", ".source.coffee", foo: bar: baz: 1) atom.config.addScopedSettings("some-package", ".source.coffee", foo: bar: baz: 1)
expect(atom.config.get([".source.coffee"], "foo.bar.baz")).toBe 100 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee"])).toBe 100
describe ".set(scope, keyPath, value)", -> describe ".set(scope, keyPath, value)", ->
it "sets the value and overrides the others", -> it "sets the value and overrides the others", ->
@@ -1165,10 +1294,10 @@ describe "Config", ->
atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22) atom.config.addScopedSettings("config", ".source .string.quoted.double", foo: bar: baz: 22)
atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11) atom.config.addScopedSettings("config", ".source", foo: bar: baz: 11)
expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.double.coffee"])).toBe 42
expect(atom.config.set(".source.coffee .string.quoted.double.coffee", "foo.bar.baz", 100)).toBe true expect(atom.config.set("foo.bar.baz", 100, scopeSelector: ".source.coffee .string.quoted.double.coffee")).toBe true
expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 100 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.double.coffee"])).toBe 100
describe ".removeScopedSettingsForName(name)", -> describe ".removeScopedSettingsForName(name)", ->
it "allows properties to be removed by name", -> it "allows properties to be removed by name", ->
@@ -1176,12 +1305,13 @@ describe "Config", ->
disposable2 = atom.config.addScopedSettings("b", ".source .string.quoted.double", foo: bar: baz: 22) disposable2 = atom.config.addScopedSettings("b", ".source .string.quoted.double", foo: bar: baz: 22)
disposable2.dispose() disposable2.dispose()
expect(atom.config.get([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBeUndefined() expect(atom.config.get("foo.bar.baz", scope: [".source.js", ".string.quoted.double.js"])).toBeUndefined()
expect(atom.config.get([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 expect(atom.config.get("foo.bar.baz", scope: [".source.coffee", ".string.quoted.double.coffee"])).toBe 42
describe ".observe(scopeDescriptor, keyPath)", -> describe ".observe(scopeDescriptor, keyPath)", ->
it 'calls the supplied callback when the value at the descriptor/keypath changes', -> it 'calls the supplied callback when the value at the descriptor/keypath changes', ->
atom.config.observe [".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz", changeSpy = jasmine.createSpy() changeSpy = jasmine.createSpy()
atom.config.observe("foo.bar.baz", scope: [".source.coffee", ".string.quoted.double.coffee"], changeSpy)
expect(changeSpy).toHaveBeenCalledWith(undefined) expect(changeSpy).toHaveBeenCalledWith(undefined)
changeSpy.reset() changeSpy.reset()
@@ -1212,7 +1342,38 @@ describe "Config", ->
describe ".onDidChange(scopeDescriptor, keyPath)", -> describe ".onDidChange(scopeDescriptor, keyPath)", ->
it 'calls the supplied callback when the value at the descriptor/keypath changes', -> it 'calls the supplied callback when the value at the descriptor/keypath changes', ->
keyPath = "foo.bar.baz" keyPath = "foo.bar.baz"
atom.config.onDidChange [".source.coffee", ".string.quoted.double.coffee"], keyPath, changeSpy = jasmine.createSpy() changeSpy = jasmine.createSpy('onDidChange callback')
atom.config.onDidChange keyPath, scope: [".source.coffee", ".string.quoted.double.coffee"], changeSpy
atom.config.set("foo.bar.baz", 12)
expect(changeSpy).toHaveBeenCalledWith({oldValue: undefined, newValue: 12})
changeSpy.reset()
disposable1 = atom.config.addScopedSettings("a", ".source .string.quoted.double", foo: bar: baz: 22)
expect(changeSpy).toHaveBeenCalledWith({oldValue: 12, newValue: 22})
changeSpy.reset()
disposable2 = atom.config.addScopedSettings("b", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42)
expect(changeSpy).toHaveBeenCalledWith({oldValue: 22, newValue: 42})
changeSpy.reset()
disposable2.dispose()
expect(changeSpy).toHaveBeenCalledWith({oldValue: 42, newValue: 22})
changeSpy.reset()
disposable1.dispose()
expect(changeSpy).toHaveBeenCalledWith({oldValue: 22, newValue: 12})
changeSpy.reset()
atom.config.set("foo.bar.baz", undefined)
expect(changeSpy).toHaveBeenCalledWith({oldValue: 12, newValue: undefined})
changeSpy.reset()
it 'deprecates using a scope descriptor as an optional first argument', ->
keyPath = "foo.bar.baz"
spyOn(Grim, 'deprecate')
atom.config.onDidChange [".source.coffee", ".string.quoted.double.coffee"], keyPath, changeSpy = jasmine.createSpy()
expect(Grim.deprecate).toHaveBeenCalled()
atom.config.set("foo.bar.baz", 12) atom.config.set("foo.bar.baz", 12)
expect(changeSpy).toHaveBeenCalledWith({oldValue: undefined, newValue: 12}) expect(changeSpy).toHaveBeenCalledWith({oldValue: undefined, newValue: 12})
+6 -6
Ver Arquivo
@@ -367,7 +367,7 @@ describe "PackageManager", ->
atom.packages.activatePackage("package-with-scoped-properties") atom.packages.activatePackage("package-with-scoped-properties")
runs -> runs ->
expect(atom.config.get ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' expect(atom.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBe '^a'
describe "converted textmate packages", -> describe "converted textmate packages", ->
it "loads the package's grammars", -> it "loads the package's grammars", ->
@@ -380,13 +380,13 @@ describe "PackageManager", ->
expect(atom.grammars.selectGrammar("file.rb").name).toBe "Ruby" expect(atom.grammars.selectGrammar("file.rb").name).toBe "Ruby"
it "loads the translated scoped properties", -> it "loads the translated scoped properties", ->
expect(atom.config.get(['.source.ruby'], 'editor.commentStart')).toBeUndefined() expect(atom.config.get('editor.commentStart', scope: ['.source.ruby'])).toBeUndefined()
waitsForPromise -> waitsForPromise ->
atom.packages.activatePackage('language-ruby') atom.packages.activatePackage('language-ruby')
runs -> runs ->
expect(atom.config.get(['.source.ruby'], 'editor.commentStart')).toBe '# ' expect(atom.config.get('editor.commentStart', scope: ['.source.ruby'])).toBe '# '
describe "::deactivatePackage(id)", -> describe "::deactivatePackage(id)", ->
afterEach -> afterEach ->
@@ -493,9 +493,9 @@ describe "PackageManager", ->
atom.packages.activatePackage("package-with-scoped-properties") atom.packages.activatePackage("package-with-scoped-properties")
runs -> runs ->
expect(atom.config.get ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' expect(atom.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBe '^a'
atom.packages.deactivatePackage("package-with-scoped-properties") atom.packages.deactivatePackage("package-with-scoped-properties")
expect(atom.config.get ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined() expect(atom.config.get 'editor.increaseIndentPattern', scope: ['.source.omg']).toBeUndefined()
describe "textmate packages", -> describe "textmate packages", ->
it "removes the package's grammars", -> it "removes the package's grammars", ->
@@ -515,7 +515,7 @@ describe "PackageManager", ->
runs -> runs ->
atom.packages.deactivatePackage('language-ruby') atom.packages.deactivatePackage('language-ruby')
expect(atom.config.get(['.source.ruby'], 'editor.commentStart')).toBeUndefined() expect(atom.config.get('editor.commentStart', scope: ['.source.ruby'])).toBeUndefined()
describe "::activate()", -> describe "::activate()", ->
packageActivator = null packageActivator = null
+16 -16
Ver Arquivo
@@ -2593,9 +2593,9 @@ describe "TextEditorComponent", ->
describe 'soft wrap settings', -> describe 'soft wrap settings', ->
beforeEach -> beforeEach ->
atom.config.set '.source.coffee', 'editor.softWrap', true atom.config.set 'editor.softWrap', true, scopeSelector: '.source.coffee'
atom.config.set '.source.coffee', 'editor.preferredLineLength', 17 atom.config.set 'editor.preferredLineLength', 17, scopeSelector: '.source.coffee'
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', true atom.config.set 'editor.softWrapAtPreferredLineLength', true, scopeSelector: '.source.coffee'
editor.setEditorWidthInChars(20) editor.setEditorWidthInChars(20)
coffeeEditor.setEditorWidthInChars(20) coffeeEditor.setEditorWidthInChars(20)
@@ -2605,18 +2605,18 @@ describe "TextEditorComponent", ->
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items ' expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '
it 'updates the wrapped lines when editor.preferredLineLength changes', -> it 'updates the wrapped lines when editor.preferredLineLength changes', ->
atom.config.set '.source.coffee', 'editor.preferredLineLength', 20 atom.config.set 'editor.preferredLineLength', 20, scopeSelector: '.source.coffee'
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if ' expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '
it 'updates the wrapped lines when editor.softWrapAtPreferredLineLength changes', -> it 'updates the wrapped lines when editor.softWrapAtPreferredLineLength changes', ->
atom.config.set '.source.coffee', 'editor.softWrapAtPreferredLineLength', false atom.config.set 'editor.softWrapAtPreferredLineLength', false, scopeSelector: '.source.coffee'
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if ' expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if '
it 'updates the wrapped lines when editor.softWrap changes', -> it 'updates the wrapped lines when editor.softWrap changes', ->
atom.config.set '.source.coffee', 'editor.softWrap', false atom.config.set 'editor.softWrap', false, scopeSelector: '.source.coffee'
expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if items.length <= 1' expect(coffeeEditor.lineTextForScreenRow(2)).toEqual ' return items if items.length <= 1'
atom.config.set '.source.coffee', 'editor.softWrap', true atom.config.set 'editor.softWrap', true, scopeSelector: '.source.coffee'
expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items ' expect(coffeeEditor.lineTextForScreenRow(3)).toEqual ' return items '
it 'updates the wrapped lines when the grammar changes', -> it 'updates the wrapped lines when the grammar changes', ->
@@ -2644,11 +2644,11 @@ describe "TextEditorComponent", ->
tab: 'F' tab: 'F'
cr: 'E' cr: 'E'
atom.config.set '.source.js', 'editor.showInvisibles', true atom.config.set 'editor.showInvisibles', true, scopeSelector: '.source.js'
atom.config.set '.source.js', 'editor.invisibles', jsInvisibles atom.config.set 'editor.invisibles', jsInvisibles, scopeSelector: '.source.js'
atom.config.set '.source.coffee', 'editor.showInvisibles', false atom.config.set 'editor.showInvisibles', false, scopeSelector: '.source.coffee'
atom.config.set '.source.coffee', 'editor.invisibles', coffeeInvisibles atom.config.set 'editor.invisibles', coffeeInvisibles, scopeSelector: '.source.coffee'
editor.setText " a line with tabs\tand spaces \n" editor.setText " a line with tabs\tand spaces \n"
nextAnimationFrame() nextAnimationFrame()
@@ -2664,7 +2664,7 @@ describe "TextEditorComponent", ->
it "re-renders the invisibles when the invisible settings change", -> it "re-renders the invisibles when the invisible settings change", ->
jsGrammar = editor.getGrammar() jsGrammar = editor.getGrammar()
editor.setGrammar(coffeeEditor.getGrammar()) editor.setGrammar(coffeeEditor.getGrammar())
atom.config.set '.source.coffee', 'editor.showInvisibles', true atom.config.set 'editor.showInvisibles', true, scopeSelector: '.source.coffee'
nextAnimationFrame() nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{coffeeInvisibles.space}a line with tabs#{coffeeInvisibles.tab}and spaces#{coffeeInvisibles.space}#{coffeeInvisibles.eol}" expect(component.lineNodeForScreenRow(0).textContent).toBe "#{coffeeInvisibles.space}a line with tabs#{coffeeInvisibles.tab}and spaces#{coffeeInvisibles.space}#{coffeeInvisibles.eol}"
@@ -2673,7 +2673,7 @@ describe "TextEditorComponent", ->
space: 'E' space: 'E'
tab: 'W' tab: 'W'
cr: 'I' cr: 'I'
atom.config.set '.source.coffee', 'editor.invisibles', newInvisibles atom.config.set 'editor.invisibles', newInvisibles, scopeSelector: '.source.coffee'
nextAnimationFrame() nextAnimationFrame()
expect(component.lineNodeForScreenRow(0).textContent).toBe "#{newInvisibles.space}a line with tabs#{newInvisibles.tab}and spaces#{newInvisibles.space}#{newInvisibles.eol}" expect(component.lineNodeForScreenRow(0).textContent).toBe "#{newInvisibles.space}a line with tabs#{newInvisibles.tab}and spaces#{newInvisibles.space}#{newInvisibles.eol}"
@@ -2683,8 +2683,8 @@ describe "TextEditorComponent", ->
describe 'editor.showIndentGuide', -> describe 'editor.showIndentGuide', ->
beforeEach -> beforeEach ->
atom.config.set '.source.js', 'editor.showIndentGuide', true atom.config.set 'editor.showIndentGuide', true, scopeSelector: '.source.js'
atom.config.set '.source.coffee', 'editor.showIndentGuide', false atom.config.set 'editor.showIndentGuide', false, scopeSelector: '.source.coffee'
it "has an 'indent-guide' class when scoped editor.showIndentGuide is true, but not when scoped editor.showIndentGuide is false", -> it "has an 'indent-guide' class when scoped editor.showIndentGuide is true, but not when scoped editor.showIndentGuide is false", ->
line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
@@ -2705,7 +2705,7 @@ describe "TextEditorComponent", ->
expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe true expect(line1LeafNodes[0].classList.contains('indent-guide')).toBe true
expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false expect(line1LeafNodes[1].classList.contains('indent-guide')).toBe false
atom.config.set '.source.js', 'editor.showIndentGuide', false atom.config.set 'editor.showIndentGuide', false, scopeSelector: '.source.js'
line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1)) line1LeafNodes = getLeafNodes(component.lineNodeForScreenRow(1))
expect(line1LeafNodes[0].textContent).toBe ' ' expect(line1LeafNodes[0].textContent).toBe ' '
+6 -6
Ver Arquivo
@@ -1327,7 +1327,7 @@ describe "TextEditor", ->
coffeeEditor.selectWordsContainingCursors() coffeeEditor.selectWordsContainingCursors()
expect(coffeeEditor.getSelectedBufferRange()).toEqual [[0, 6], [0, 15]] expect(coffeeEditor.getSelectedBufferRange()).toEqual [[0, 6], [0, 15]]
atom.config.set '.source.coffee', 'editor.nonWordCharacters', 'qusort' atom.config.set 'editor.nonWordCharacters', 'qusort', scopeSelector: '.source.coffee'
coffeeEditor.setCursorBufferPosition [0, 9] coffeeEditor.setCursorBufferPosition [0, 9]
coffeeEditor.selectWordsContainingCursors() coffeeEditor.selectWordsContainingCursors()
@@ -3276,7 +3276,7 @@ describe "TextEditor", ->
atom.packages.unloadPackages() atom.packages.unloadPackages()
it 'returns correct values based on the scope of the set grammars', -> it 'returns correct values based on the scope of the set grammars', ->
atom.config.set '.source.coffee', 'editor.tabLength', 6 atom.config.set 'editor.tabLength', 6, scopeSelector: '.source.coffee'
expect(editor.getTabLength()).toBe 2 expect(editor.getTabLength()).toBe 2
expect(coffeeEditor.getTabLength()).toBe 6 expect(coffeeEditor.getTabLength()).toBe 6
@@ -3298,12 +3298,12 @@ describe "TextEditor", ->
expect(editor.getTabLength()).toBe 2 expect(editor.getTabLength()).toBe 2
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2 expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2
atom.config.set '.source.js', 'editor.tabLength', 6 atom.config.set 'editor.tabLength', 6, scopeSelector: '.source.js'
expect(editor.getTabLength()).toBe 6 expect(editor.getTabLength()).toBe 6
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 6 expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 6
it 'updates the tab length when the grammar changes', -> it 'updates the tab length when the grammar changes', ->
atom.config.set '.source.coffee', 'editor.tabLength', 6 atom.config.set 'editor.tabLength', 6, scopeSelector: '.source.coffee'
expect(editor.getTabLength()).toBe 2 expect(editor.getTabLength()).toBe 2
expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2 expect(editor.tokenizedLineForScreenRow(5).tokens[0].firstNonWhitespaceIndex).toBe 2
@@ -3473,8 +3473,8 @@ describe "TextEditor", ->
atom.project.open('coffee.coffee', autoIndent: false).then (o) -> coffeeEditor = o atom.project.open('coffee.coffee', autoIndent: false).then (o) -> coffeeEditor = o
runs -> runs ->
atom.config.set('.source.js', 'editor.autoIndent', true) atom.config.set('editor.autoIndent', true, scopeSelector: '.source.js')
atom.config.set('.source.coffee', 'editor.autoIndent', false) atom.config.set('editor.autoIndent', false, scopeSelector: '.source.coffee')
afterEach: -> afterEach: ->
atom.packages.deactivatePackages() atom.packages.deactivatePackages()
+214 -176
Ver Arquivo
@@ -314,11 +314,12 @@ class Config
@settings = {} @settings = {}
@scopedSettingsStore = new ScopedPropertyStore @scopedSettingsStore = new ScopedPropertyStore
@usersScopedSettings = new CompositeDisposable @usersScopedSettings = new CompositeDisposable
@usersScopedSettingPriority = {priority: 1000}
@configFileHasErrors = false @configFileHasErrors = false
@configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson']) @configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= path.join(@configDirPath, 'config.cson') @configFilePath ?= path.join(@configDirPath, 'config.cson')
@transactDepth = 0 @transactDepth = 0
@prioritiesBySource = {}
@prioritiesBySource[@getUserConfigPath()] = 1000
### ###
Section: Config Subscription Section: Config Subscription
@@ -338,32 +339,36 @@ class Config
# # do stuff with value # # do stuff with value
# ``` # ```
# #
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}. See {::get} for examples.
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `keyPath` {String} name of the key to observe # * `keyPath` {String} name of the key to observe
# * `options` {Object}
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}. See {::get} for examples.
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `callback` {Function} to call when the value of the key changes. # * `callback` {Function} to call when the value of the key changes.
# * `value` the new value of the key # * `value` the new value of the key
# #
# Returns a {Disposable} with the following keys on which you can call # Returns a {Disposable} with the following keys on which you can call
# `.dispose()` to unsubscribe. # `.dispose()` to unsubscribe.
observe: (scopeDescriptor, keyPath, options, callback) -> observe: ->
args = Array::slice.call(arguments) if arguments.length is 2
if args.length is 2 [keyPath, callback] = arguments
# observe(keyPath, callback) else if arguments.length is 3 and (_.isArray(arguments[0]) or arguments[0] instanceof ScopeDescriptor)
[keyPath, callback, scopeDescriptor, options] = args Grim.deprecate """
else if args.length is 3 and (Array.isArray(scopeDescriptor) or scopeDescriptor instanceof ScopeDescriptor) Passing a scope descriptor as the first argument to Config::observe is deprecated.
# observe(scopeDescriptor, keyPath, callback) Pass a `scope` in an options hash as the third argument instead.
[scopeDescriptor, keyPath, callback, options] = args """
else if args.length is 3 and _.isString(scopeDescriptor) and _.isObject(keyPath) [scopeDescriptor, keyPath, callback] = arguments
# observe(keyPath, options, callback) # Deprecated! else if arguments.length is 3 and (_.isString(arguments[0]) and _.isObject(arguments[1]))
[keyPath, options, callback, scopeDescriptor] = args [keyPath, options, callback] = arguments
scopeDescriptor = options.scope
message = "" if options.callNow?
message = "`callNow` was set to false. Use ::onDidChange instead. Note that ::onDidChange calls back with different arguments." if options.callNow == false Grim.deprecate """
Grim.deprecate "Config::observe no longer supports options; see https://atom.io/docs/api/latest/Config. #{message}" Config::observe no longer takes a `callNow` option. Use ::onDidChange instead.
Note that ::onDidChange passes its callback different arguments.
See https://atom.io/docs/api/latest/Config
"""
else else
console.error 'An unsupported form of Config::observe is being used. See https://atom.io/docs/api/latest/Config for details' console.error 'An unsupported form of Config::observe is being used. See https://atom.io/docs/api/latest/Config for details'
return return
@@ -376,13 +381,14 @@ class Config
# Essential: Add a listener for changes to a given key path. If `keyPath` is # Essential: Add a listener for changes to a given key path. If `keyPath` is
# not specified, your callback will be called on changes to any key. # not specified, your callback will be called on changes to any key.
# #
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}. See {::get} for examples.
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `keyPath` (optional) {String} name of the key to observe. Must be # * `keyPath` (optional) {String} name of the key to observe. Must be
# specified if `scopeDescriptor` is specified. # specified if `scopeDescriptor` is specified.
# * `optional` (optional) {Object}
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}. See {::get} for examples.
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `callback` {Function} to call when the value of the key changes. # * `callback` {Function} to call when the value of the key changes.
# * `event` {Object} # * `event` {Object}
# * `newValue` the new value of the key # * `newValue` the new value of the key
@@ -391,12 +397,20 @@ class Config
# #
# Returns a {Disposable} with the following keys on which you can call # Returns a {Disposable} with the following keys on which you can call
# `.dispose()` to unsubscribe. # `.dispose()` to unsubscribe.
onDidChange: (scopeDescriptor, keyPath, callback) -> onDidChange: ->
args = Array::slice.call(arguments)
if arguments.length is 1 if arguments.length is 1
[callback, scopeDescriptor, keyPath] = args [callback] = arguments
else if arguments.length is 2 else if arguments.length is 2
[keyPath, callback, scopeDescriptor] = args [keyPath, callback] = arguments
else if _.isArray(arguments[0]) or arguments[0] instanceof ScopeDescriptor
Grim.deprecate """
Passing a scope descriptor as the first argument to Config::onDidChange is deprecated.
Pass a `scope` in an options hash as the third argument instead.
"""
[scopeDescriptor, keyPath, callback] = arguments
else
[keyPath, options, callback] = arguments
scopeDescriptor = options.scope
if scopeDescriptor? if scopeDescriptor?
@onDidChangeScopedKeyPath(scopeDescriptor, keyPath, callback) @onDidChangeScopedKeyPath(scopeDescriptor, keyPath, callback)
@@ -447,24 +461,40 @@ class Config
# atom.config.get(scopeDescriptor, 'editor.tabLength') # => 2 # atom.config.get(scopeDescriptor, 'editor.tabLength') # => 2
# ``` # ```
# #
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `keyPath` The {String} name of the key to retrieve. # * `keyPath` The {String} name of the key to retrieve.
# * `options` (optional) {Object}
# * `sources` (optional) {Array} of {String} source names. If provided, only
# values that were associated with these sources during {::set} will be used.
# * `excludeSources` (optional) {Array} of {String} source names. If provided,
# values that were associated with these sources during {::set} will not
# be used.
# * `scopeDescriptor` (optional) {ScopeDescriptor} describing a path from
# the root of the syntax tree to a token. Get one by calling
# {editor.getLastCursor().getScopeDescriptor()}
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# #
# Returns the value from Atom's default settings, the user's configuration # Returns the value from Atom's default settings, the user's configuration
# file in the type specified by the configuration schema. # file in the type specified by the configuration schema.
get: (scopeDescriptor, keyPath) -> get: ->
if arguments.length == 1 if arguments.length > 1
# cannot assign to keyPath for the sake of v8 optimization if typeof arguments[0] is 'string' or not arguments[0]?
globalKeyPath = scopeDescriptor [keyPath, options] = arguments
@getRawValue(globalKeyPath) {scope} = options
else
Grim.deprecate """
Passing a scope descriptor as the first argument to Config::get is deprecated.
Pass a `scope` in an options hash as the final argument instead.
"""
[scope, keyPath] = arguments
else else
value = @getRawScopedValue(scopeDescriptor, keyPath) [keyPath] = arguments
value ?= @getRawValue(keyPath)
value if scope?
value = @getRawScopedValue(scope, keyPath, options)
value ? @getRawValue(keyPath, options)
else
@getRawValue(keyPath, options)
# Essential: Sets the value for a configuration setting. # Essential: Sets the value for a configuration setting.
# #
@@ -495,63 +525,90 @@ class Config
# atom.config.get(['source.js'], 'editor.tabLength') # => 4 # atom.config.get(['source.js'], 'editor.tabLength') # => 4
# ``` # ```
# #
# * `scopeSelector` (optional) {String}. eg. '.source.ruby'
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `keyPath` The {String} name of the key. # * `keyPath` The {String} name of the key.
# * `value` The value of the setting. Passing `undefined` will revert the # * `value` The value of the setting. Passing `undefined` will revert the
# setting to the default value. # setting to the default value.
# * `options` (optional) {Object}
# * `scopeSelector` (optional) {String}. eg. '.source.ruby'
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `source` (optional) {String} The name of a file with which the setting
# is associated. Defaults to the user's config file.
# #
# Returns a {Boolean} # Returns a {Boolean}
# * `true` if the value was set. # * `true` if the value was set.
# * `false` if the value was not able to be coerced to the type specified in the setting's schema. # * `false` if the value was not able to be coerced to the type specified in the setting's schema.
set: (scopeSelector, keyPath, value) -> set: ->
if arguments.length < 3 if arguments[0]?[0] is '.'
value = keyPath Grim.deprecate """
keyPath = scopeSelector Passing a scope selector as the first argument to Config::set is deprecated.
scopeSelector = undefined Pass a `scopeSelector` in an options hash as the final argument instead.
"""
[scopeSelector, keyPath, value] = arguments
else
[keyPath, value, options] = arguments
scopeSelector = options?.scopeSelector
source = options?.source
unless value == undefined source ?= @getUserConfigPath()
unless value is undefined
try try
value = @makeValueConformToSchema(keyPath, value) value = @makeValueConformToSchema(keyPath, value)
catch e catch e
return false return false
if scopeSelector? if scopeSelector?
@setRawScopedValue(scopeSelector, keyPath, value) @setRawScopedValue(source, scopeSelector, keyPath, value)
else else
@setRawValue(keyPath, value) @setRawValue(source, keyPath, value)
@emitChangeEvent()
@save() unless @configFileHasErrors @save() unless @configFileHasErrors
true true
# Extended: Restore the global setting at `keyPath` to its default value. # Essential: Restore the setting at `keyPath` to its default value.
# #
# * `scopeSelector` (optional) {String}. eg. '.source.ruby'
# See [the scopes docs](https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors)
# for more information.
# * `keyPath` The {String} name of the key. # * `keyPath` The {String} name of the key.
# * `options` (optional) {Object}
# * `scopeSelector` (optional) {String}. See {::set}
# * `source` (optional) {String}. See {::set}
unset: (keyPath, options) ->
if typeof options is 'string'
Grim.deprecate """
Passing a scope selector as the first argument to Config::unset is deprecated.
Pass a `scopeSelector` in an options hash as the second argument instead.
"""
scopeSelector = keyPath
keyPath = options
else
{scopeSelector, source} = options ? {}
source ?= @getUserConfigPath()
if scopeSelector?
if keyPath?
settings = @scopedSettingsStore.propertiesForSourceAndSelector(source, scopeSelector)
if _.valueForKeyPath(settings, keyPath)?
@scopedSettingsStore.removePropertiesForSourceAndSelector(source, scopeSelector)
_.setValueForKeyPath(settings, keyPath, undefined)
settings = withoutEmptyObjects(settings)
@addScopedSettings(source, scopeSelector, settings, priority: @usersScopedSettingPriority) if settings?
@save() unless @configFileHasErrors
else
@scopedSettingsStore.removePropertiesForSource(source)
else
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
# Deprecated: Restore the global setting at `keyPath` to its default value.
# #
# Returns the new value. # Returns the new value.
restoreDefault: (scopeSelector, keyPath) -> restoreDefault: (scopeSelector, keyPath) ->
if arguments.length == 1 Grim.deprecate("Use ::unset instead.")
keyPath = scopeSelector @unset(scopeSelector, keyPath)
scopeSelector = null @get(keyPath)
if scopeSelector? # Deprecated: Get the global default value of the key path. _Please note_ that in most
settings = @scopedSettingsStore.propertiesForSourceAndSelector('user-config', scopeSelector)
if _.valueForKeyPath(settings, keyPath)?
@scopedSettingsStore.removePropertiesForSourceAndSelector('user-config', scopeSelector)
_.setValueForKeyPath(settings, keyPath, undefined)
settings = withoutEmptyObjects(settings)
@addScopedSettings('user-config', scopeSelector, settings, @usersScopedSettingPriority) if settings?
@save() unless @configFileHasErrors
@getDefault(scopeSelector, keyPath)
else
@set(keyPath, _.valueForKeyPath(@defaultSettings, keyPath))
@get(keyPath)
# Extended: Get the global default value of the key path. _Please note_ that in most
# cases calling this is not necessary! {::get} returns the default value when # cases calling this is not necessary! {::get} returns the default value when
# a custom value is not specified. # a custom value is not specified.
# #
@@ -559,35 +616,31 @@ class Config
# * `keyPath` The {String} name of the key. # * `keyPath` The {String} name of the key.
# #
# Returns the default value. # Returns the default value.
getDefault: (scopeSelector, keyPath) -> getDefault: ->
if arguments.length == 1 Grim.deprecate("Use `::get(keyPath, {scope, excludeSources: [atom.config.getUserConfigPath()]})` instead")
keyPath = scopeSelector if arguments.length is 1
scopeSelector = null [keyPath] = arguments
if scopeSelector?
defaultValue = @scopedSettingsStore.getPropertyValue(scopeSelector, keyPath, excludeSources: ['user-config'])
defaultValue ?= _.valueForKeyPath(@defaultSettings, keyPath)
else else
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath) [scopeSelector, keyPath] = arguments
_.deepClone(defaultValue) scope = [scopeSelector]
@get(keyPath, {scope, excludeSources: [@getUserConfigPath()]})
# Extended: Is the value at `keyPath` its default value? # Deprecated: Is the value at `keyPath` its default value?
# #
# * `scopeSelector` (optional) {String}. eg. '.source.ruby' # * `scopeSelector` (optional) {String}. eg. '.source.ruby'
# * `keyPath` The {String} name of the key. # * `keyPath` The {String} name of the key.
# #
# Returns a {Boolean}, `true` if the current value is the default, `false` # Returns a {Boolean}, `true` if the current value is the default, `false`
# otherwise. # otherwise.
isDefault: (scopeSelector, keyPath) -> isDefault: ->
if arguments.length == 1 Grim.deprecate("Use `not ::get(keyPath, {scope, sources: [atom.config.getUserConfigPath()]})?` instead")
keyPath = scopeSelector if arguments.length is 1
scopeSelector = null [keyPath] = arguments
scopeSelector = '*'
if scopeSelector?
settings = @scopedSettingsStore.propertiesForSourceAndSelector('user-config', scopeSelector)
not _.valueForKeyPath(settings, keyPath)?
else else
not _.valueForKeyPath(@settings, keyPath)? [scopeSelector, keyPath] = arguments
not @get(keyPath, {scope: [scopeSelector], sources: [@getUserConfigPath()]})?
# Extended: Retrieve the schema for a specific key path. The schema will tell # Extended: Retrieve the schema for a specific key path. The schema will tell
# you what type the keyPath expects, and other metadata about the config # you what type the keyPath expects, and other metadata about the config
@@ -609,7 +662,7 @@ class Config
# defaults. Returns the scoped settings when a `scopeSelector` is specified. # defaults. Returns the scoped settings when a `scopeSelector` is specified.
getSettings: -> getSettings: ->
Grim.deprecate "Use ::get(keyPath) instead" Grim.deprecate "Use ::get(keyPath) instead"
_.deepExtend({}, @settings, @defaultSettings) _.deepExtend({}, @defaultSettings, @scopedSettingsStore.getProperties('.xxx')...)
# Extended: Get the {String} path to the config file being used. # Extended: Get the {String} path to the config file being used.
getUserConfigPath: -> getUserConfigPath: ->
@@ -752,55 +805,43 @@ class Config
console.error detail console.error detail
save: -> save: ->
allSettings = global: @settings settings = @scopedSettingsStore.propertiesForSource(@getUserConfigPath())
allSettings = _.extend allSettings, @scopedSettingsStore.propertiesForSource('user-config') settings.global = settings['*']
CSON.writeFileSync(@configFilePath, allSettings) delete settings['*']
CSON.writeFileSync(@configFilePath, settings)
### ###
Section: Private methods managing global settings Section: Private methods managing global settings
### ###
resetUserSettings: (newSettings) -> resetUserSettings: (newSettings) ->
@scopedSettingsStore.removePropertiesForSource(@getUserConfigPath())
unless isPlainObject(newSettings) unless isPlainObject(newSettings)
@settings = {}
@emitChangeEvent() @emitChangeEvent()
return return
if newSettings.global? unless newSettings.global?
scopedSettings = newSettings newSettings = {global: newSettings}
newSettings = newSettings.global
delete scopedSettings.global
@resetUserScopedSettings(scopedSettings)
unsetUnspecifiedValues = (keyPath, value) => for selector, settings of newSettings
if isPlainObject(value) unless settings is undefined
keys = splitKeyPath(keyPath) try
for key, childValue of value settings = @makeValueConformToSchema(null, settings)
continue unless value.hasOwnProperty(key) catch e
unsetUnspecifiedValues(keys.concat([key]).join('.'), childValue) continue
if selector is 'global'
@setRawValue(@getUserConfigPath(), null, settings)
else else
@setRawValue(keyPath, undefined) unless _.valueForKeyPath(newSettings, keyPath)? @setRawScopedValue(@getUserConfigPath(), selector, null, settings)
return
@setRecursive(null, newSettings) @emitChangeEvent()
unsetUnspecifiedValues(null, @settings)
setRecursive: (keyPath, value) -> getRawValue: (keyPath, options) ->
if isPlainObject(value) value = @getRawScopedValue(['xxx'], keyPath, options)
keys = splitKeyPath(keyPath) unless options?.sources?.length > 0
for key, childValue of value defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
continue unless value.hasOwnProperty(key)
@setRecursive(keys.concat([key]).join('.'), childValue)
else
try
value = @makeValueConformToSchema(keyPath, value)
@setRawValue(keyPath, value)
catch e
console.warn("'#{keyPath}' could not be set. Attempted value: #{JSON.stringify(value)}; Schema: #{JSON.stringify(@getSchema(keyPath))}")
getRawValue: (keyPath) ->
value = _.valueForKeyPath(@settings, keyPath)
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
if value? if value?
value = _.deepClone(value) value = _.deepClone(value)
@@ -810,26 +851,17 @@ class Config
value value
setRawValue: (keyPath, value) -> setRawValue: (source, keyPath, value) ->
defaultValue = _.valueForKeyPath(@defaultSettings, keyPath) defaultValue = _.valueForKeyPath(@defaultSettings, keyPath)
value = undefined if _.isEqual(defaultValue, value) value = undefined if _.isEqual(defaultValue, value)
@setRawScopedValue(source, '*', keyPath, value)
_.setValueForKeyPath(@settings, keyPath, value)
@emitChangeEvent() @emitChangeEvent()
observeKeyPath: (keyPath, options, callback) -> observeKeyPath: (keyPath, options, callback) ->
callback(@get(keyPath)) @observeScopedKeyPath(["xxx"], keyPath, callback)
@onDidChangeKeyPath keyPath, (event) -> callback(event.newValue)
onDidChangeKeyPath: (keyPath, callback) -> onDidChangeKeyPath: (keyPath, callback) ->
oldValue = @get(keyPath) @onDidChangeScopedKeyPath(["xxx"], keyPath, callback)
didChange = =>
newValue = @get(keyPath)
callback({oldValue, newValue}) unless _.isEqual(oldValue, newValue)
oldValue = newValue
@emitter.on 'did-change', didChange
isSubKeyPath: (keyPath, subKeyPath) -> isSubKeyPath: (keyPath, subKeyPath) ->
return false unless keyPath? and subKeyPath? return false unless keyPath? and subKeyPath?
@@ -851,6 +883,7 @@ class Config
try try
defaults = @makeValueConformToSchema(keyPath, defaults) defaults = @makeValueConformToSchema(keyPath, defaults)
@setRawDefault(keyPath, defaults) @setRawDefault(keyPath, defaults)
@emitChangeEvent()
catch e catch e
console.warn("'#{keyPath}' could not set the default. Attempted default: #{JSON.stringify(defaults)}; Schema: #{JSON.stringify(@getSchema(keyPath))}") console.warn("'#{keyPath}' could not set the default. Attempted default: #{JSON.stringify(defaults)}; Schema: #{JSON.stringify(@getSchema(keyPath))}")
@@ -900,12 +933,6 @@ class Config
emitChangeEvent: -> emitChangeEvent: ->
@emitter.emit 'did-change' unless @transactDepth > 0 @emitter.emit 'did-change' unless @transactDepth > 0
resetUserScopedSettings: (newScopedSettings) ->
@usersScopedSettings?.dispose()
@usersScopedSettings = new CompositeDisposable
@usersScopedSettings.add @scopedSettingsStore.addProperties('user-config', newScopedSettings, @usersScopedSettingPriority)
@emitChangeEvent()
addScopedSettings: (source, selector, value, options) -> addScopedSettings: (source, selector, value, options) ->
settingsBySelector = {} settingsBySelector = {}
settingsBySelector[selector] = value settingsBySelector[selector] = value
@@ -915,41 +942,33 @@ class Config
disposable.dispose() disposable.dispose()
@emitChangeEvent() @emitChangeEvent()
setRawScopedValue: (selector, keyPath, value) -> setRawScopedValue: (source, selector, keyPath, value) ->
if keyPath? if keyPath?
newValue = {} newValue = {}
_.setValueForKeyPath(newValue, keyPath, value) setValueAtKeyPath(newValue, keyPath, value)
value = newValue value = newValue
settingsBySelector = {} settingsBySelector = {}
settingsBySelector[selector] = value settingsBySelector[selector] = value
@usersScopedSettings.add @scopedSettingsStore.addProperties('user-config', settingsBySelector, @usersScopedSettingPriority) @usersScopedSettings.add @scopedSettingsStore.addProperties(source, settingsBySelector, priority: @prioritiesBySource[source])
@emitChangeEvent()
getRawScopedValue: (scopeDescriptor, keyPath) -> getRawScopedValue: (scopeDescriptor, keyPath, options) ->
scopeDescriptor = ScopeDescriptor.fromObject(scopeDescriptor) scopeDescriptor = ScopeDescriptor.fromObject(scopeDescriptor)
@scopedSettingsStore.getPropertyValue(scopeDescriptor.getScopeChain(), keyPath) value = @scopedSettingsStore.getPropertyValue(scopeDescriptor.getScopeChain(), keyPath, options)
value
observeScopedKeyPath: (scopeDescriptor, keyPath, callback) -> observeScopedKeyPath: (scope, keyPath, callback) ->
oldValue = @get(scopeDescriptor, keyPath) callback(@get(keyPath, {scope}))
@onDidChangeScopedKeyPath scope, keyPath, ({newValue}) ->
callback(newValue)
callback(oldValue) onDidChangeScopedKeyPath: (scope, keyPath, callback) ->
oldValue = _.deepClone(@get(keyPath, {scope}))
didChange = => @emitter.on 'did-change', (event) =>
newValue = @get(scopeDescriptor, keyPath) newValue = @get(keyPath, {scope})
callback(newValue) unless _.isEqual(oldValue, newValue) unless _.isEqual(newValue, oldValue)
oldValue = newValue callback({newValue, oldValue})
oldValue = _.deepClone(newValue)
@emitter.on 'did-change', didChange
onDidChangeScopedKeyPath: (scopeDescriptor, keyPath, callback) ->
oldValue = @get(scopeDescriptor, keyPath)
didChange = =>
newValue = @get(scopeDescriptor, keyPath)
callback({oldValue, newValue}) unless _.isEqual(oldValue, newValue)
oldValue = newValue
@emitter.on 'did-change', didChange
# TODO: figure out how to change / remove this. The return value is awkward. # TODO: figure out how to change / remove this. The return value is awkward.
# * language mode uses it for one thing. # * language mode uses it for one thing.
@@ -1015,7 +1034,11 @@ Config.addSchemaEnforcers
for prop, childSchema of schema.properties for prop, childSchema of schema.properties
continue unless value.hasOwnProperty(prop) continue unless value.hasOwnProperty(prop)
try try
newValue[prop] = @executeSchemaEnforcers("#{keyPath}.#{prop}", value[prop], childSchema) newKeyPath = if keyPath?
"#{keyPath}.#{prop}"
else
prop
newValue[prop] = @executeSchemaEnforcers(newKeyPath, value[prop], childSchema)
catch error catch error
console.warn "Error setting item in object: #{error.message}" console.warn "Error setting item in object: #{error.message}"
newValue newValue
@@ -1068,6 +1091,21 @@ splitKeyPath = (keyPath) ->
keyPathArray.push keyPath.substr(startIndex, keyPath.length) keyPathArray.push keyPath.substr(startIndex, keyPath.length)
keyPathArray keyPathArray
getValueAtKeyPath = (object, keyPath) ->
keys = splitKeyPath(keyPath)
for key in keys
object = object[key]
return unless object?
object
setValueAtKeyPath = (object, keyPath, value) ->
keys = splitKeyPath(keyPath)
while keys.length > 1
key = keys.shift()
object[key] ?= {}
object = object[key]
object[keys.shift()] = value
withoutEmptyObjects = (object) -> withoutEmptyObjects = (object) ->
resultObject = undefined resultObject = undefined
if isPlainObject(object) if isPlainObject(object)
+2 -2
Ver Arquivo
@@ -202,7 +202,7 @@ class Cursor extends Model
[before, after] = @editor.getTextInBufferRange(range) [before, after] = @editor.getTextInBufferRange(range)
return false if /\s/.test(before) or /\s/.test(after) return false if /\s/.test(before) or /\s/.test(after)
nonWordCharacters = atom.config.get(@getScopeDescriptor(), 'editor.nonWordCharacters').split('') nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: @getScopeDescriptor()).split('')
_.contains(nonWordCharacters, before) isnt _.contains(nonWordCharacters, after) _.contains(nonWordCharacters, before) isnt _.contains(nonWordCharacters, after)
# Public: Returns whether this cursor is between a word's start and end. # Public: Returns whether this cursor is between a word's start and end.
@@ -636,7 +636,7 @@ class Cursor extends Model
# Returns a {RegExp}. # Returns a {RegExp}.
wordRegExp: ({includeNonWordCharacters}={}) -> wordRegExp: ({includeNonWordCharacters}={}) ->
includeNonWordCharacters ?= true includeNonWordCharacters ?= true
nonWordCharacters = atom.config.get(@getScopeDescriptor(), 'editor.nonWordCharacters') nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: @getScopeDescriptor())
segments = ["^[\t ]*$"] segments = ["^[\t ]*$"]
segments.push("[^\\s#{_.escapeRegExp(nonWordCharacters)}]+") segments.push("[^\\s#{_.escapeRegExp(nonWordCharacters)}]+")
if includeNonWordCharacters if includeNonWordCharacters
+9 -9
Ver Arquivo
@@ -67,24 +67,24 @@ class DisplayBuffer extends Model
oldConfigSettings = @configSettings oldConfigSettings = @configSettings
@configSettings = @configSettings =
scrollPastEnd: atom.config.get(scopeDescriptor, 'editor.scrollPastEnd') scrollPastEnd: atom.config.get('editor.scrollPastEnd', scope: scopeDescriptor)
softWrap: atom.config.get(scopeDescriptor, 'editor.softWrap') softWrap: atom.config.get('editor.softWrap', scope: scopeDescriptor)
softWrapAtPreferredLineLength: atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength') softWrapAtPreferredLineLength: atom.config.get('editor.softWrapAtPreferredLineLength', scope: scopeDescriptor)
preferredLineLength: atom.config.get(scopeDescriptor, 'editor.preferredLineLength') preferredLineLength: atom.config.get('editor.preferredLineLength', scope: scopeDescriptor)
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrap', ({newValue}) => subscriptions.add atom.config.onDidChange 'editor.softWrap', scope: scopeDescriptor, ({newValue}) =>
@configSettings.softWrap = newValue @configSettings.softWrap = newValue
@updateWrappedScreenLines() @updateWrappedScreenLines()
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrapAtPreferredLineLength', ({newValue}) => subscriptions.add atom.config.onDidChange 'editor.softWrapAtPreferredLineLength', scope: scopeDescriptor, ({newValue}) =>
@configSettings.softWrapAtPreferredLineLength = newValue @configSettings.softWrapAtPreferredLineLength = newValue
@updateWrappedScreenLines() if @isSoftWrapped() @updateWrappedScreenLines() if @isSoftWrapped()
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.preferredLineLength', ({newValue}) => subscriptions.add atom.config.onDidChange 'editor.preferredLineLength', scope: scopeDescriptor, ({newValue}) =>
@configSettings.preferredLineLength = newValue @configSettings.preferredLineLength = newValue
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength') @updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get('editor.softWrapAtPreferredLineLength', scope: scopeDescriptor)
subscriptions.add atom.config.observe scopeDescriptor, 'editor.scrollPastEnd', (value) => subscriptions.add atom.config.observe 'editor.scrollPastEnd', scope: scopeDescriptor, (value) =>
@configSettings.scrollPastEnd = value @configSettings.scrollPastEnd = value
@updateWrappedScreenLines() if oldConfigSettings? and not _.isEqual(oldConfigSettings, @configSettings) @updateWrappedScreenLines() if oldConfigSettings? and not _.isEqual(oldConfigSettings, @configSettings)
+1 -1
Ver Arquivo
@@ -316,7 +316,7 @@ class LanguageMode
@editor.setIndentationForBufferRow(bufferRow, desiredIndentLevel) @editor.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
getRegexForProperty: (scopeDescriptor, property) -> getRegexForProperty: (scopeDescriptor, property) ->
if pattern = atom.config.get(scopeDescriptor, property) if pattern = atom.config.get(property, scope: scopeDescriptor)
new OnigRegExp(pattern) new OnigRegExp(pattern)
increaseIndentRegexForScopeDescriptor: (scopeDescriptor) -> increaseIndentRegexForScopeDescriptor: (scopeDescriptor) ->
+3 -3
Ver Arquivo
@@ -462,9 +462,9 @@ TextEditorComponent = React.createClass
scopeDescriptor = editor.getRootScopeDescriptor() scopeDescriptor = editor.getRootScopeDescriptor()
subscriptions.add atom.config.observe scopeDescriptor, 'editor.showIndentGuide', @setShowIndentGuide subscriptions.add atom.config.observe 'editor.showIndentGuide', scope: scopeDescriptor, @setShowIndentGuide
subscriptions.add atom.config.observe scopeDescriptor, 'editor.showLineNumbers', @setShowLineNumbers subscriptions.add atom.config.observe 'editor.showLineNumbers', scope: scopeDescriptor, @setShowLineNumbers
subscriptions.add atom.config.observe scopeDescriptor, 'editor.scrollSensitivity', @setScrollSensitivity subscriptions.add atom.config.observe 'editor.scrollSensitivity', scope: scopeDescriptor, @setScrollSensitivity
focused: -> focused: ->
if @isMounted() if @isMounted()
+6 -6
Ver Arquivo
@@ -168,8 +168,8 @@ class TextEditor extends Model
scopeDescriptor = @getRootScopeDescriptor() scopeDescriptor = @getRootScopeDescriptor()
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.showInvisibles', => @updateInvisibles() subscriptions.add atom.config.onDidChange 'editor.showInvisibles', scope: scopeDescriptor, => @updateInvisibles()
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.invisibles', => @updateInvisibles() subscriptions.add atom.config.onDidChange 'editor.invisibles', scope: scopeDescriptor, => @updateInvisibles()
getViewClass: -> getViewClass: ->
require './text-editor-view' require './text-editor-view'
@@ -2812,17 +2812,17 @@ class TextEditor extends Model
### ###
shouldAutoIndent: -> shouldAutoIndent: ->
atom.config.get(@getRootScopeDescriptor(), "editor.autoIndent") atom.config.get("editor.autoIndent", scope: @getRootScopeDescriptor())
shouldAutoIndentOnPaste: -> shouldAutoIndentOnPaste: ->
atom.config.get(@getRootScopeDescriptor(), "editor.autoIndentOnPaste") atom.config.get("editor.autoIndentOnPaste", scope: @getRootScopeDescriptor())
shouldShowInvisibles: -> shouldShowInvisibles: ->
not @mini and atom.config.get(@getRootScopeDescriptor(), 'editor.showInvisibles') not @mini and atom.config.get('editor.showInvisibles', scope: @getRootScopeDescriptor())
updateInvisibles: -> updateInvisibles: ->
if @shouldShowInvisibles() if @shouldShowInvisibles()
@displayBuffer.setInvisibles(atom.config.get(@getRootScopeDescriptor(), 'editor.invisibles')) @displayBuffer.setInvisibles(atom.config.get('editor.invisibles', scope: @getRootScopeDescriptor()))
else else
@displayBuffer.setInvisibles(null) @displayBuffer.setInvisibles(null)
+2 -2
Ver Arquivo
@@ -84,10 +84,10 @@ class TokenizedBuffer extends Model
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText()) @currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
@subscribe @grammar.onDidUpdate => @retokenizeLines() @subscribe @grammar.onDidUpdate => @retokenizeLines()
@configSettings = tabLength: atom.config.get(@rootScopeDescriptor, 'editor.tabLength') @configSettings = tabLength: atom.config.get('editor.tabLength', scope: @rootScopeDescriptor)
@grammarTabLengthSubscription?.dispose() @grammarTabLengthSubscription?.dispose()
@grammarTabLengthSubscription = atom.config.onDidChange @rootScopeDescriptor, 'editor.tabLength', ({newValue}) => @grammarTabLengthSubscription = atom.config.onDidChange 'editor.tabLength', scope: @rootScopeDescriptor, ({newValue}) =>
@configSettings.tabLength = newValue @configSettings.tabLength = newValue
@retokenizeLines() @retokenizeLines()
@subscribe @grammarTabLengthSubscription @subscribe @grammarTabLengthSubscription
+1 -1
Ver Arquivo
@@ -645,7 +645,7 @@ class Workspace extends Model
# Restore to a default editor font size. # Restore to a default editor font size.
resetFontSize: -> resetFontSize: ->
atom.config.restoreDefault("editor.fontSize") atom.config.unset("editor.fontSize")
# Removes the item's uri from the list of potential items to reopen. # Removes the item's uri from the list of potential items to reopen.
itemOpened: (item) -> itemOpened: (item) ->