From 63cc37c27c69d1898b7e406a85481a0c725f90e0 Mon Sep 17 00:00:00 2001 From: fundon Date: Fri, 6 Feb 2015 18:51:56 +0800 Subject: [PATCH 1/3] fix toggle, #255 --- lib/main.coffee | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/main.coffee b/lib/main.coffee index 34866e5b..94932161 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -93,7 +93,6 @@ class Main # Activates the minimap package. activate: -> - @subscriptions = new CompositeDisposable MinimapElement ?= require './minimap-element' MinimapElement.registerViewProvider() @@ -130,7 +129,10 @@ class Main toggle: -> if @toggled @toggled = false - @subscriptions.dispose() + @editorsMinimaps?.forEach (value, key) => + value.destroy() + @editorsMinimaps.delete(key) + @editorsMinimaps = undefined else @toggled = true @initSubscriptions() diff --git a/package.json b/package.json index 60dc9fdf..6847b49d 100644 --- a/package.json +++ b/package.json @@ -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", From 6e5a18e7f825acf746d1564ffa9ceee0a9e95a6c Mon Sep 17 00:00:00 2001 From: fundon Date: Sat, 7 Feb 2015 02:44:04 +0800 Subject: [PATCH 2/3] use specific disposable for commands, fix disable/enable minimap-element attach bug --- lib/main.coffee | 18 +++++++++++------- lib/minimap-element.coffee | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/main.coffee b/lib/main.coffee index 94932161..af751356 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -89,17 +89,21 @@ class Main # Internal: Used only at export time. constructor: -> @emitter = new Emitter + + # Commands Subscriptions + @subscriptionsOfCommands = new CompositeDisposable + @subscriptionsOfCommands.add atom.commands.add 'atom-workspace', + 'minimap:toggle': => @toggle() + 'minimap:generate-plugin': => @generatePlugin() + + # Other Subscriptions @subscriptions = new CompositeDisposable - # Activates the minimap package. - activate: -> 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' @@ -132,7 +136,7 @@ class Main @editorsMinimaps?.forEach (value, key) => value.destroy() @editorsMinimaps.delete(key) - @editorsMinimaps = undefined + @subscriptions.dispose() else @toggled = true @initSubscriptions() diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index 71ea805c..e366a643 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -93,6 +93,7 @@ class MinimapElement extends HTMLElement attach: -> return if @attached @swapMinimapPosition() + @attached = true attachToLeft: -> root = @getTextEditorElementRoot() From eae5ae6dc811659b672a6c7091d802ff96823ceb Mon Sep 17 00:00:00 2001 From: fundon Date: Sat, 7 Feb 2015 13:15:40 +0800 Subject: [PATCH 3/3] add DPI for canvas tests --- spec/minimap-element-spec.coffee | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index 4713eaf3..c53c2ab3 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -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 @@ -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() @@ -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 -> @@ -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) @@ -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 ->