Move more config observation out of text editor

This commit is contained in:
Max Brunsfeld 2016-07-08 17:54:24 -07:00
parent eec1b70967
commit d91895961e
3 changed files with 34 additions and 5 deletions

View File

@ -146,5 +146,29 @@ describe('TextEditorRegistry', function () {
atom.config.set('editor.invisibles', invisibles1)
expect(editor.getInvisibles()).toEqual(invisibles1)
});
it('enables or disables the indent guide based on the config', function () {
editor.setShowIndentGuide(true)
expect(editor.doesShowIndentGuide()).toBe(true)
atom.config.set('editor.showIndentGuide', false)
registry.maintainConfig(editor)
expect(editor.doesShowIndentGuide()).toBe(false)
atom.config.set('editor.showIndentGuide', true)
expect(editor.doesShowIndentGuide()).toBe(true)
});
it('enables or disables soft wrap based on the config', function () {
editor.setSoftWrapped(true)
expect(editor.isSoftWrapped()).toBe(true)
atom.config.set('editor.softWrap', false)
registry.maintainConfig(editor)
expect(editor.isSoftWrapped()).toBe(false)
atom.config.set('editor.softWrap', true)
expect(editor.isSoftWrapped()).toBe(true)
});
})
})

View File

@ -8,6 +8,8 @@ const EDITOR_SETTER_NAMES_BY_SETTING_KEY = [
['editor.showInvisibles', 'setShowInvisibles'],
['editor.tabLength', 'setTabLength'],
['editor.invisibles', 'setInvisibles'],
['editor.showIndentGuide', 'setShowIndentGuide'],
['editor.softWrap', 'setSoftWrapped'],
]
// Experimental: This global registry tracks registered `TextEditors`.

View File

@ -231,9 +231,6 @@ class TextEditor extends Model
@scopedConfigSubscriptions = subscriptions = new CompositeDisposable
scopeDescriptor = @getRootScopeDescriptor()
subscriptions.add @config.onDidChange 'editor.tabLength', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
subscriptions.add @config.onDidChange 'editor.showIndentGuide', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
subscriptions.add @config.onDidChange 'editor.softWrap', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
subscriptions.add @config.onDidChange 'editor.softWrapHangingIndent', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
subscriptions.add @config.onDidChange 'editor.softWrapAtPreferredLineLength', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
subscriptions.add @config.onDidChange 'editor.preferredLineLength', scope: scopeDescriptor, @resetDisplayLayer.bind(this)
@ -2761,6 +2758,13 @@ class TextEditor extends Model
@invisibles = invisibles
@resetDisplayLayer()
doesShowIndentGuide: -> @showIndentGuide
setShowIndentGuide: (showIndentGuide) ->
return if showIndentGuide is @showIndentGuide
@showIndentGuide = showIndentGuide
@resetDisplayLayer()
# Extended: Determine if the buffer uses hard or soft tabs.
#
# Returns `true` if the first non-comment line with leading whitespace starts
@ -2817,8 +2821,7 @@ class TextEditor extends Model
if @largeFileMode
false
else
scopeDescriptor = @getRootScopeDescriptor()
@softWrapped ? @config.get('editor.softWrap', scope: scopeDescriptor) ? false
@softWrapped
# Essential: Enable or disable soft wrapping for this editor.
#