Skip to content

Commit 830622c

Browse files
committed
Merge branch 'dev'
2 parents 02456b6 + fcda1bc commit 830622c

File tree

9 files changed

+350
-67
lines changed

9 files changed

+350
-67
lines changed

Readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Minimap package
22

3-
A preview of the full source code, likes Sublime Text minimap.
3+
A preview of the full source code.
44

55
![Minimap Screenshot](https://github.com/fundon/atom-minimap/blob/master/screenshot.png?raw=true)
66

@@ -23,6 +23,14 @@ apm install minimap
2323
* `ctrl-k ctrl-m` toggle the minimap without the logs
2424
* `ctrl-k ctrl-d` toggle the minimap with the logs
2525

26+
Customizing Key Bindings
27+
28+
```cson
29+
'.editor':
30+
'cmd-m': 'minimap:toggle'
31+
'cmd-d': 'minimap:toggle-debug'
32+
```
33+
2634
### Contributors
2735

2836
https://github.com/fundon/atom-minimap/graphs/contributors
@@ -33,6 +41,7 @@ The minimap can be augmented with plugins, belows the list of available plugins
3341

3442
* [Find And Replace](https://atom.io/packages/minimap-find-and-replace)
3543
* [Git Diff](https://atom.io/packages/minimap-git-diff)
44+
* [Color Highlight](https://atom.io/packages/minimap-color-highlight)
3645

3746
### Roadmap
3847

lib/minimap-view.coffee

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class MinimapView extends View
7272
@paneView.removeClass('with-minimap')
7373
@detachFromPaneView()
7474

75+
activeViewSupportMinimap: -> @getEditor()?
7576
minimapIsAttached: -> @paneView.find('.minimap').length is 1
7677

7778
# EDITOR VIEW MANAGEMENT
@@ -104,7 +105,7 @@ class MinimapView extends View
104105

105106
getScrollViewClientRect: -> @scrollViewLines[0].getBoundingClientRect()
106107

107-
# See https://atom.io/docs/api/v0.83.0/api/classes/Pane.html#getActiveEditor-instance
108+
# See Atom's API /api/classes/Pane.html#getActiveEditor-instance
108109
# Returns an Editor if the pane item is an Editor, or null otherwise.
109110
getEditor: -> @paneView.model.getActiveEditor()
110111

@@ -162,7 +163,7 @@ class MinimapView extends View
162163
return if item is @activeItem
163164
@activeItem = item
164165

165-
if @activeTabSupportMinimap()
166+
if @activeViewSupportMinimap()
166167
@log 'minimap is supported by the current tab'
167168
@activatePaneViewMinimap() unless @minimapIsAttached()
168169
@storeActiveEditor()
@@ -219,8 +220,6 @@ class MinimapView extends View
219220

220221
# OTHER PRIVATE METHODS
221222

222-
activeTabSupportMinimap: -> @getEditor()
223-
224223
scale: (x=1,y=1) -> "scale(#{x}, #{y}) "
225224
translateY: (y=0) -> "translate3d(0, #{y}px, 0)"
226225
transform: (el, transform) ->

lib/minimap.coffee

Lines changed: 97 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,127 @@
11
{Emitter} = require 'emissary'
2-
MinimapView = require './minimap-view'
32
Debug = require 'prolix'
43

4+
ViewManagement = require './mixins/view-management'
5+
PluginManagement = require './mixins/plugin-management'
6+
57
require '../vendor/resizeend'
68

9+
# Public: The `Minimap` package provides an eagle-eye view of text buffers.
10+
#
11+
# It also provides API for plugin packages that want to interact with the
12+
# minimap and be available to the user through the minimap settings.
13+
#
14+
# ## Events
15+
#
16+
# * `activated` -
17+
# Emitted synchronously when the package is activated. By suscribing
18+
# to this event other packages can be notified of the activation of the
19+
# minimap. At that point the minimap views have been created.
20+
#
21+
# * `deactivated` -
22+
# Emitted synchronously when the package have been deactivated. The views
23+
# are no longer available at that point.
24+
#
25+
# * `minimap-view:created` -
26+
# Emitted synchronously when a {MinimapView} have been created for
27+
# an active {PaneView}.
28+
# Your handler will be called with an object containing the following keys.
29+
# * `view`: The {MinimapView} that was created
30+
#
31+
# * `minimap-view:will-be-destroyed` -
32+
# Emitted synchronously when a {MinimapView} is about to be destroyed.
33+
# Your handler will be called with an object containing the following keys.
34+
# * `view`: The {MinimapView} that was created
35+
#
36+
# * `minimap-view:destroyed` -
37+
# Emitted synchronously when a {MinimapView} was destroyed, at that point
38+
# the view have been removed from the DOM.
39+
# Your handler will be called with an object containing the following keys.
40+
# * `view`: The {MinimapView} that was created
41+
#
42+
# * `plugin:added` -
43+
# Emitted synchronously when a minimap plugin was registered.
44+
# Your handler will be called with an object containing the following keys.
45+
# * `name` - The {String} name used to register the plugin
46+
# * `plugin` - The plugin {Object} that was registered
47+
#
48+
# * `plugin:removed` -
49+
# Emitted synchronously when a minimap plugin was unregistered.
50+
# Your handler will be called with an object containing the following keys.
51+
# * `name` - The {String} name used to register the plugin
52+
# * `plugin` - The plugin {Object} that was unregistered
53+
#
54+
# * `plugin:activated` -
55+
# Emitted synchronously when a minimap plugin was activated.
56+
# Your handler will be called with an object containing the following keys.
57+
# * `name` - The {String} name used to register the plugin
58+
# * `plugin` - The plugin {Object} that was activated
59+
#
60+
# * `plugin:deactivated` -
61+
# Emitted synchronously when a minimap plugin was deactivated.
62+
# Your handler will be called with an object containing the following keys.
63+
# * `name` - The {String} name used to register the plugin
64+
# * `plugin` - The plugin {Object} that was deactivated
65+
#
66+
# ## Plugins Interface
67+
#
68+
# Plugins should conform to the following interface:
69+
#
70+
# ```coffee
71+
# class Plugin
72+
# void activatePlugin: ->
73+
# void deactivatePlugin: ->
74+
# bool isActive: ->
75+
# ```
776
class Minimap
877
Emitter.includeInto(this)
978
Debug('minimap').includeInto(this)
79+
ViewManagement.includeInto(this)
80+
PluginManagement.includeInto(this)
1081

11-
# We'll be storing each MinimapView using the id of their PaneView
12-
minimapViews: {}
82+
# Public: The default minimap settings
83+
configDefaults:
84+
plugins: {}
85+
autoToggle: false
1386

14-
# We'll be using this property to store the toggle state as the
15-
# minimapViews object will never be set to null.
87+
# Internal: The activation state of the minimap package.
1688
active: false
1789

90+
# Public: Activates the minimap package.
1891
activate: ->
1992
atom.workspaceView.command 'minimap:toggle', => @toggleNoDebug()
2093
atom.workspaceView.command 'minimap:toggle-debug', => @toggleDebug()
94+
@toggleNoDebug() if atom.config.get 'minimap.autoToggle'
2195

96+
# Public: Deactivates the minimap package.
2297
deactivate: ->
23-
view.destroy() for id, view of @minimapViews
24-
@eachPaneViewSubscription.off()
25-
@minimapViews = {}
98+
@destroyViews()
2699
@emit('deactivated')
27100

28-
toggle: () ->
29-
if @active
30-
@active = false
31-
@deactivate()
32-
else
33-
@open()
34-
@active = true
35-
@emit('activated')
36-
101+
# Public: Toggles the minimap activation state with debug turned on.
37102
toggleDebug: ->
38103
@getChannel().activate()
39104
@toggle()
40105

106+
# Public: Toggles the minimap activation state with debug turned off.
41107
toggleNoDebug: ->
42108
@getChannel().deactivate()
43109
@toggle()
44110

45-
updateAllViews: ->
46-
view.onScrollViewResized() for id,view of @minimapViews
47-
48-
minimapForEditorView: (editorView) ->
49-
@minimapForPaneView(editorView.getPane())
50-
51-
minimapForPaneView: (paneView) -> @minimapForPane(paneView.model)
52-
minimapForPane: (pane) -> @minimapViews[pane.id]
53-
54-
open: ->
55-
# When toggled we'll look for each existing and future pane thanks to
56-
# the `eachPaneView` method. It returns a subscription object so we'll
57-
# store it and it will be used in the `deactivate` method to removes
58-
# the callback.
59-
@eachPaneViewSubscription = atom.workspaceView.eachPaneView (paneView) =>
60-
paneId = paneView.model.id
61-
view = new MinimapView(paneView)
62-
view.onActiveItemChanged(paneView.getActiveItem())
63-
@updateAllViews()
64-
65-
@minimapViews[paneId] = view
66-
@emit('minimap-view:created', view)
67-
68-
paneView.model.on 'destroyed', =>
69-
view = @minimapViews[paneId]
70-
71-
if view?
72-
@emit('minimap-view:before-destruction', view)
73-
74-
view.destroy()
75-
delete @minimapViews[paneId]
76-
@updateAllViews()
77-
111+
# Public: Returns the char width ratio of the minimap compared to the real
112+
# editor. **The value is currently hard-coded until we find a good way to
113+
# compute it from the editor state**.
114+
getCharWidthRatio: -> 0.8
78115

116+
# Internal: Toggles the minimap activation state.
117+
toggle: () ->
118+
if @active
119+
@active = false
120+
@deactivate()
121+
else
122+
@createViews()
123+
@active = true
124+
@emit('activated')
79125

126+
# The minimap module is an instance of the {Minimap} class.
80127
module.exports = new Minimap()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Mixin = require 'mixto'
2+
3+
# Public: Provides methods to manage minimap plugins.
4+
#
5+
# Minimap plugins are Atom packages that will augment the minimap.
6+
# They have a secondary activation cycle going on constrained by the minimap
7+
# package activation. A minimap plugin life cycle will generally look like this:
8+
#
9+
# 1. The plugin module is activated by Atom through the `activate` method
10+
# 2. The plugin then register itself as a minimap plugin using `registerPlugin`
11+
# 3. The plugin is activated/deactivated according to the minimap settings.
12+
# 4. On the plugin module deactivation, the plugin must unregisters itself
13+
# from the minimap using the `unregisterPlugin`.
14+
module.exports =
15+
class PluginManagement extends Mixin
16+
# Internal: Stores the minimap plugin with their identifying name as key.
17+
plugins: {}
18+
19+
# Public: Registers a minimap `plugin` with the given `name`.
20+
#
21+
# name - The identifying name of the plugin. It will be used as activation
22+
# settings name as well as the key to unregister the module.
23+
# plugin - The plugin {Object} to register.
24+
registerPlugin: (name, plugin) ->
25+
settingsKey = "minimap.plugins.#{name}"
26+
27+
@configDefaults.plugins[name] = true
28+
atom.config.set(settingsKey, true) unless atom.config.get(settingsKey)?
29+
30+
@plugins[name] = plugin
31+
32+
@emit('plugin:added', {name, plugin})
33+
34+
atom.config.observe settingsKey, =>
35+
@updatesPluginActivationState(name)
36+
37+
atom.workspaceView.command "minimap:toggle-#{name}", =>
38+
atom.config.set settingsKey, not atom.config.get(settingsKey)
39+
@updatesPluginActivationState(name)
40+
41+
@updatesPluginActivationState(name)
42+
43+
# Public: Unregisters a plugin from the minimap.
44+
#
45+
# name - The identifying name of the plugin to unregister.
46+
unregisterPlugin: (name) ->
47+
atom.config.unobserve "minimap.plugins.#{name}"
48+
atom.workspaceView.off "minimap:toggle-#{name}"
49+
plugin = @plugins[name]
50+
delete @configDefaults.plugins[name]
51+
delete @plugins[name]
52+
@emit('plugin:removed', {name, plugin})
53+
54+
# Internal: Updates the plugin activation state according to the current
55+
# config.
56+
updatesPluginActivationState: (name) ->
57+
plugin = @plugins[name]
58+
59+
pluginActive = plugin.isActive()
60+
settingActive = atom.config.get("minimap.plugins.#{name}")
61+
62+
if settingActive and not pluginActive
63+
plugin.activatePlugin()
64+
@emit('plugin:activated', {name, plugin})
65+
else if pluginActive and not settingActive
66+
plugin.deactivatePlugin()
67+
@emit('plugin:deactivated', {name, plugin})

lib/mixins/view-management.coffee

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Mixin = require 'mixto'
2+
MinimapView = require '../minimap-view'
3+
4+
# Public: Provides methods to manage minimap views per pane.
5+
module.exports =
6+
class ViewManagement extends Mixin
7+
# Internal: Stores each MinimapView using the id of their PaneView
8+
minimapViews: {}
9+
10+
# Public: Updates all views currently in use.
11+
updateAllViews: ->
12+
view.onScrollViewResized() for id,view of @minimapViews
13+
14+
# Public: Returns the {MinimapView} object associated to the pane containing
15+
# the passed-in {EditorView}.
16+
#
17+
# editorView - An {EditorView} instance
18+
#
19+
# Returns the {MinimapView} object associated to the pane containing
20+
# the passed-in {EditorView}.
21+
minimapForEditorView: (editorView) ->
22+
@minimapForPaneView(editorView?.getPane())
23+
24+
# Public: Returns the {MinimapView} object associated to the passed-in
25+
# {PaneView} object.
26+
#
27+
# paneView - A {PaneView} instance
28+
#
29+
# Returns the {MinimapView} object associated to the passed-in
30+
# {PaneView} object.
31+
minimapForPaneView: (paneView) -> @minimapForPane(paneView?.model)
32+
33+
# Public: Returns the {MinimapView} object associated to the passed-in
34+
# {Pane} object.
35+
#
36+
# pane - A {Pane} instance
37+
#
38+
# Returns the {MinimapView} object associated to the passed-in
39+
# {Pane} object.
40+
minimapForPane: (pane) -> @minimapViews[pane.id] if pane?
41+
42+
# Internal: Destroys all views currently in use.
43+
destroyViews: ->
44+
view.destroy() for id, view of @minimapViews
45+
@eachPaneViewSubscription.off()
46+
@minimapViews = {}
47+
48+
# Internal: Registers to each pane view existing or to be created and creates
49+
# a {MinimapView} instance for each.
50+
createViews: ->
51+
# When toggled we'll look for each existing and future pane thanks to
52+
# the `eachPaneView` method. It returns a subscription object so we'll
53+
# store it and it will be used in the `deactivate` method to removes
54+
# the callback.
55+
@eachPaneViewSubscription = atom.workspaceView.eachPaneView (paneView) =>
56+
paneId = paneView.model.id
57+
view = new MinimapView(paneView)
58+
view.onActiveItemChanged(paneView.getActiveItem())
59+
@updateAllViews()
60+
61+
@minimapViews[paneId] = view
62+
@emit('minimap-view:created', {view})
63+
64+
paneView.model.on 'destroyed', =>
65+
view = @minimapViews[paneId]
66+
67+
if view?
68+
@emit('minimap-view:will-be-destroyed', {view})
69+
70+
view.destroy()
71+
delete @minimapViews[paneId]
72+
@emit('minimap-view:destroyed', {view})
73+
@updateAllViews()

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@
1515
"email": "[email protected]"
1616
}
1717
],
18-
"activationEvents": [
19-
"minimap:toggle",
20-
"minimap:toggle-debug"
21-
],
22-
"repository": "https://github.com/fundon/atom-minimap",
18+
"repository": "https://github.com/atom-minimap/atom-minimap",
2319
"license": "MIT",
2420
"engines": {
2521
"atom": ">0.50.0"

0 commit comments

Comments
 (0)