diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 0c7459a70..c575c835a 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -1554,17 +1554,21 @@ describe "Editor", -> buffer.insert([0, 0], "–") expect(editor.find('.line:eq(0)').outerHeight()).toBe editor.find('.line:eq(1)').outerHeight() - describe "when editor.setShowInvisibles is called", -> + describe "when config.editor.showInvisibles is set to true", -> it "displays spaces as •, tabs as ▸ and newlines as ¬ when true", -> editor.attachToDom() editor.setInvisibles(rootView.getInvisibles()) editor.setText " a line with tabs\tand spaces " - expect(editor.showInvisibles).toBeFalsy() + expect(config.editor.showInvisibles).toBeFalsy() expect(editor.renderedLines.find('.line').text()).toBe " a line with tabs and spaces " - editor.setShowInvisibles(true) + + config.editor.showInvisibles = true + config.update() expect(editor.renderedLines.find('.line').text()).toBe "•a line with tabs▸ and spaces•¬" - editor.setShowInvisibles(false) + + config.editor.showInvisibles = false + config.update() expect(editor.renderedLines.find('.line').text()).toBe " a line with tabs and spaces " it "displays newlines(¬) as their own token outside of the other tokens scope", -> diff --git a/src/app/config.coffee b/src/app/config.coffee index f2ae4bf4f..eeb76a8e6 100644 --- a/src/app/config.coffee +++ b/src/app/config.coffee @@ -1,5 +1,6 @@ fs = require 'fs' _ = require 'underscore' +EventEmitter = require 'event-emitter' module.exports = class Config @@ -8,14 +9,23 @@ class Config @configJsonPath = fs.join(@configDirPath, "config.json") @userInitScriptPath = fs.join(@configDirPath, "atom.coffee") + @core = {} + @editor = {} + load: -> if fs.exists(@configJsonPath) userConfig = JSON.parse(fs.read(@configJsonPath)) _.extend(this, userConfig) @requireUserInitScript() + update: -> + @trigger 'update' + + requireUserInitScript: -> try require @userInitScriptPath if fs.exists(@userInitScriptPath) catch error console.error "Failed to load `#{@userInitScriptPath}`", error.stack, error + +_.extend Config.prototype, EventEmitter diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5fdc1118d..fa3ca05e2 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -60,6 +60,7 @@ class Editor extends View @id = Editor.idCounter++ @lineCache = [] + @configure() @bindKeys() @handleEvents() @cursorViews = [] @@ -296,7 +297,12 @@ class Editor extends View scanInRange: (args...) -> @getBuffer().scanInRange(args...) backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...) + configure: -> + @setShowInvisibles(config.editor.showInvisibles ? false) + handleEvents: -> + config.on "update.editor#{@id}", => @configure() + @on 'focus', => @hiddenInput.focus() false @@ -658,6 +664,7 @@ class Editor extends View @destroyEditSessions() $(window).off ".editor#{@id}" + config.off ".editor#{@id}" rootView = @rootView() rootView?.off ".editor#{@id}" if @pane() then @pane().remove() else super