Skip to content

Commit

Permalink
Add support for scoped settings for both editor and minimap settings
Browse files Browse the repository at this point in the history
Fixes #456
  • Loading branch information
abe33 committed Mar 5, 2016
1 parent 0a17d2e commit 92a3c66
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 25 deletions.
70 changes: 45 additions & 25 deletions lib/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,32 +193,18 @@ export default class Minimap {
this.scrollTop = 0
}

let subs = this.subscriptions
subs.add(atom.config.observe('editor.scrollPastEnd', (scrollPastEnd) => {
this.scrollPastEnd = scrollPastEnd
this.adapter.scrollPastEnd = this.scrollPastEnd
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.charHeight', (configCharHeight) => {
this.configCharHeight = configCharHeight
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.charWidth', (configCharWidth) => {
this.configCharWidth = configCharWidth
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.interline', (configInterline) => {
this.configInterline = configInterline
this.emitter.emit('did-change-config')
const subs = this.subscriptions
let configSubscription = this.subscribeToConfig()

subs.add(configSubscription)

subs.add(this.textEditor.onDidChangeGrammar(() => {
subs.remove(configSubscription)
configSubscription.dispose()

configSubscription = this.subscribeToConfig()
subs.add(configSubscription)
}))
// cdprr is shorthand for configDevicePixelRatioRounding
subs.add(atom.config.observe(
'minimap.devicePixelRatioRounding',
(cdprr) => {
this.configDevicePixelRatioRounding = cdprr
this.emitter.emit('did-change-config')
}
))

subs.add(this.adapter.onDidChangeScrollTop(() => {
if (!this.standAlone) {
Expand Down Expand Up @@ -363,6 +349,40 @@ export default class Minimap {
return this.emitter.on('did-destroy', callback)
}

subscribeToConfig () {
const subs = new CompositeDisposable()
const opts = {scope: this.textEditor.getRootScopeDescriptor()}

subs.add(atom.config.observe('editor.scrollPastEnd', opts, (scrollPastEnd) => {
this.scrollPastEnd = scrollPastEnd
this.adapter.scrollPastEnd = this.scrollPastEnd
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.charHeight', opts, (configCharHeight) => {
this.configCharHeight = configCharHeight
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.charWidth', opts, (configCharWidth) => {
this.configCharWidth = configCharWidth
this.emitter.emit('did-change-config')
}))
subs.add(atom.config.observe('minimap.interline', opts, (configInterline) => {
this.configInterline = configInterline
this.emitter.emit('did-change-config')
}))
// cdprr is shorthand for configDevicePixelRatioRounding
subs.add(atom.config.observe(
'minimap.devicePixelRatioRounding',
opts,
(cdprr) => {
this.configDevicePixelRatioRounding = cdprr
this.emitter.emit('did-change-config')
}
))

return subs
}

/**
* Returns `true` when the current Minimap is a stand-alone minimap.
*
Expand Down
24 changes: 24 additions & 0 deletions spec/minimap-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ describe('Minimap', () => {
})
})

describe('with scoped settings', () => {
beforeEach(() => {
waitsForPromise(() => {
return atom.packages.activatePackage('language-javascript')
})

runs(() => {
const opts = {scopeSelector: '.source.js'}

atom.config.set('minimap.charHeight', 8, opts)
atom.config.set('minimap.charWidth', 4, opts)
atom.config.set('minimap.interline', 2, opts)

editor.setGrammar(atom.grammars.grammarForScopeName('source.js'))
})
})

it('honors the scoped settings for the current editor new grammar', () => {
expect(minimap.getCharHeight()).toEqual(8)
expect(minimap.getCharWidth()).toEqual(4)
expect(minimap.getInterline()).toEqual(2)
})
})

// ######## ######## ###### #######
// ## ## ## ## ## ## ##
// ## ## ## ## ## ##
Expand Down

0 comments on commit 92a3c66

Please sign in to comment.