Add config.editor.showInvisibles

This commit is contained in:
Nathan Sobo
2012-12-12 13:50:58 -08:00
parent d89549c58a
commit b3303bc21d
3 changed files with 25 additions and 4 deletions

View File

@@ -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", ->

View File

@@ -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

View File

@@ -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