Skip to content

Commit

Permalink
Implement config observers to update minimap elements
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 16, 2014
1 parent 1128bb4 commit 5bea545
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class MinimapElement extends HTMLElement
else if @scrollIndicator?
@disposeScrollIndicator()

@subscriptions.add atom.config.observe 'minimap.textOpacity', (@textOpacity) =>
@requestForcedUpdate() if @attached

attachedCallback: ->
@domPollingIntervalId = setInterval((=> @pollDOM()), @domPollingInterval)
@measureHeightAndWidth()
Expand Down Expand Up @@ -67,6 +70,8 @@ class MinimapElement extends HTMLElement
setModel: (@minimap) ->
@subscriptions.add @minimap.onDidChangeScrollTop => @requestUpdate()
@subscriptions.add @minimap.onDidChangeScrollLeft => @requestUpdate()
@subscriptions.add @minimap.onDidChangeConfig =>
@requestForcedUpdate() if @attached
@subscriptions.add @minimap.onDidChange (change) =>
@pendingChanges.push(change)
@requestUpdate()
Expand Down Expand Up @@ -142,7 +147,14 @@ class MinimapElement extends HTMLElement
@update()
@frameRequested = false

requestForcedUpdate: ->
@offscreenFirstRow = null
@offscreenLastRow = null
@requestUpdate()

update: ->
return unless @attached

@visibleArea.style.width = @clientWidth + 'px'
@visibleArea.style.height = @minimap.getTextEditorHeight() + 'px'
@visibleArea.style.top = (@minimap.getTextEditorScrollTop() - @minimap.getMinimapScrollTop()) + 'px'
Expand Down
5 changes: 5 additions & 0 deletions lib/minimap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class Minimap extends Model
@initializeDecorations()

subs.add atom.config.observe 'minimap.charHeight', (@charHeight) =>
@emitter.emit('did-change-config')
subs.add atom.config.observe 'minimap.charWidth', (@charWidth) =>
@emitter.emit('did-change-config')
subs.add atom.config.observe 'minimap.interline', (@interline) =>
@emitter.emit('did-change-config')

subs.add @textEditor.onDidChange (changes) => @emitChanges(changes)
subs.add @textEditor.onDidChangeScrollTop (scrollTop) =>
Expand All @@ -27,6 +30,8 @@ class Minimap extends Model

onDidChange: (callback) -> @emitter.on 'did-change', callback

onDidChangeConfig: (callback) -> @emitter.on 'did-change-config', callback

onDidChangeScrollTop: (callback) ->
@emitter.on 'did-change-scroll-top', callback

Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/canvas-drawer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CanvasDrawer extends Mixin
# ## ## ## ## ## ## ## ## ## ## ##
# ###### ####### ######## ####### ## ## ######

getTextOpacity: -> 0.6
getTextOpacity: -> @textOpacity

# Returns the default text color for an editor content.
#
Expand Down
38 changes: 37 additions & 1 deletion spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe 'MinimapElement', ->
atom.config.set 'minimap.charHeight', 4
atom.config.set 'minimap.charWidth', 2
atom.config.set 'minimap.interline', 1
atom.config.set 'minimap.textOpacity', 1

MinimapElement.registerViewProvider()

Expand Down Expand Up @@ -221,13 +222,48 @@ describe 'MinimapElement', ->
# ## ## ## ## ## ### ## ## ## ##
# ###### ####### ## ## ## #### ######

describe 'when minimap.textOpacity is changed', ->
beforeEach ->
spyOn(minimapElement, 'requestForcedUpdate').andCallThrough()
atom.config.set 'minimap.textOpacity', 0.3
nextAnimationFrame()

it 'requests a complete update', ->
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()

describe 'when minimap.charWidth is changed', ->
beforeEach ->
spyOn(minimapElement, 'requestForcedUpdate').andCallThrough()
atom.config.set 'minimap.charWidth', 1
nextAnimationFrame()

it 'requests a complete update', ->
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()

describe 'when minimap.charHeight is changed', ->
beforeEach ->
spyOn(minimapElement, 'requestForcedUpdate').andCallThrough()
atom.config.set 'minimap.charHeight', 1
nextAnimationFrame()

it 'requests a complete update', ->
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()

describe 'when minimap.interline is changed', ->
beforeEach ->
spyOn(minimapElement, 'requestForcedUpdate').andCallThrough()
atom.config.set 'minimap.interline', 2
nextAnimationFrame()

it 'requests a complete update', ->
expect(minimapElement.requestForcedUpdate).toHaveBeenCalled()

describe 'when minimap.displayMinimapOnLeft setting is true', ->
beforeEach ->
atom.config.set 'minimap.displayMinimapOnLeft', true

it 'moves the attached minimap to the left', ->
expect(Array::indexOf.call(editorElement.shadowRoot.children, minimapElement)).toEqual(0)
nextAnimationFrame()

describe 'when minimap.minimapScrollIndicator setting is true', ->
beforeEach ->
Expand Down

0 comments on commit 5bea545

Please sign in to comment.