Skip to content

Commit

Permalink
Merge pull request #258 from fundon/fix/toggle
Browse files Browse the repository at this point in the history
Fix toggle, disable/enable
  • Loading branch information
fundon committed Feb 7, 2015
2 parents cfd3e9b + eae5ae6 commit e4bce06
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
20 changes: 13 additions & 7 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,21 @@ class Main
# Internal: Used only at export time.
constructor: ->
@emitter = new Emitter
@subscriptions = new CompositeDisposable

# Activates the minimap package.
activate: ->
# Commands Subscriptions
@subscriptionsOfCommands = new CompositeDisposable
@subscriptionsOfCommands.add atom.commands.add 'atom-workspace',
'minimap:toggle': => @toggle()
'minimap:generate-plugin': => @generatePlugin()

# Other Subscriptions
@subscriptions = new CompositeDisposable
MinimapElement ?= require './minimap-element'

MinimapElement ?= require './minimap-element'
MinimapElement.registerViewProvider()

@subscriptions.add atom.commands.add 'atom-workspace',
'minimap:toggle': => @toggle()
'minimap:generate-plugin': => @generatePlugin()
# Activates the minimap package.
activate: ->

@toggle() if atom.config.get 'minimap.autoToggle'

Expand Down Expand Up @@ -130,6 +133,9 @@ class Main
toggle: ->
if @toggled
@toggled = false
@editorsMinimaps?.forEach (value, key) =>
value.destroy()
@editorsMinimaps.delete(key)
@subscriptions.dispose()
else
@toggled = true
Expand Down
1 change: 1 addition & 0 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class MinimapElement extends HTMLElement
attach: ->
return if @attached
@swapMinimapPosition()
@attached = true

attachToLeft: ->
root = @getTextEditorElementRoot()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"mixto": "1.x",
"delegato": "1.x",
"semver": "~2.3.0",
"event-kit": "0.7.x",
"event-kit": "1.x",
"fs-plus": "2.x",
"temp": "0.5.0",
"underscore-plus": "1.x",
Expand Down
14 changes: 8 additions & 6 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ realOffsetLeft = (o) ->
transform = new WebKitCSSMatrix window.getComputedStyle(o).transform
o.offsetLeft + transform.m41

devicePixelRatio = window.devicePixelRatio || 1

sleep = (duration) ->
t = new Date
waitsFor -> new Date - t > duration
Expand Down Expand Up @@ -119,8 +121,8 @@ describe 'MinimapElement', ->
expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.clientWidth / 11, 0)

it 'resizes the canvas to fit the minimap', ->
expect(canvas.offsetHeight).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())
expect(canvas.offsetWidth).toEqual(minimapElement.offsetWidth)
expect(canvas.offsetHeight / devicePixelRatio).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())
expect(canvas.offsetWidth / devicePixelRatio).toEqual(minimapElement.offsetWidth)

it 'requests an update', ->
expect(minimapElement.frameRequested).toBeTruthy()
Expand Down Expand Up @@ -202,8 +204,8 @@ describe 'MinimapElement', ->
expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.offsetWidth / 11, 0)
expect(minimapElement.offsetHeight).toEqual(editorElement.offsetHeight)

expect(canvas.offsetWidth).toEqual(minimapElement.offsetWidth)
expect(canvas.offsetHeight).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())
expect(canvas.offsetWidth / devicePixelRatio).toEqual(minimapElement.offsetWidth)
expect(canvas.offsetHeight / devicePixelRatio).toEqual(minimapElement.offsetHeight + minimap.getLineHeight())

describe 'when the editor visible content is changed', ->
beforeEach ->
Expand Down Expand Up @@ -500,7 +502,7 @@ describe 'MinimapElement', ->
nextAnimationFrame()

it 'adjusts the width of the minimap canvas', ->
expect(minimapElement.canvas.width).toEqual(4)
expect(minimapElement.canvas.width / devicePixelRatio).toEqual(4)

it 'offsets the minimap by the difference', ->
expect(realOffsetLeft(minimapElement)).toBeCloseTo(editorElement.clientWidth - 4, -1)
Expand All @@ -511,7 +513,7 @@ describe 'MinimapElement', ->
sleep(150)
runs ->
nextAnimationFrame()
expect(minimapElement.canvas.width).toEqual(4)
expect(minimapElement.canvas.width / devicePixelRatio).toEqual(4)

describe 'when the editor is resized', ->
beforeEach ->
Expand Down

0 comments on commit e4bce06

Please sign in to comment.