Skip to content

Commit

Permalink
Implement a basic switch in main to enable v4 preview
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 16, 2014
1 parent 625b395 commit 2d07292
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 10 deletions.
42 changes: 42 additions & 0 deletions lib/main-v4.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{CompositeDisposable} = require 'event-kit'
[Minimap, MinimapElement] = []

module.exports =
class V4Main
@includeInto: (base) ->
for k,v of @prototype
base::[k] = v

activateV4: ->
@editorsMinimaps = {}
@subscriptions = new CompositeDisposable
MinimapElement ?= require './minimap-element'

MinimapElement.registerViewProvider()

deactivate: ->
@subscriptions.dispose()
@editorsMinimaps = {}
@toggled = false

toggle: ->
if @toggled
@toggled = false
@subscriptions.dispose()
else
@toggled = true
@initSubscriptions()

minimapForEditor: (editor) -> @editorsMinimaps[editor.id]

initSubscriptions: ->
Minimap ?= require './minimap'

@subscriptions.add atom.workspace.observeTextEditors (textEditor) =>
minimap = new Minimap({textEditor})
@editorsMinimaps[textEditor.id] = minimap

editorElement = atom.views.getView(textEditor)
minimapElement = atom.views.getView(minimap)

minimapElement.attach()
36 changes: 26 additions & 10 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ViewManagement = require './mixins/view-management'
PluginManagement = require './mixins/plugin-management'
V4Main = null

[MinimapPluginGeneratorView, deprecate, semver] = []

Expand Down Expand Up @@ -80,6 +81,10 @@ class Main
minimum: 0
maximum: 1
description: "The opacity used to render the line's text in the minimap."
v4Preview:
type: 'boolean'
default: false
description: "Require Atom restart. Plugins will be disabled."

# Internal: The activation state of the minimap package.
active: false
Expand All @@ -91,20 +96,31 @@ class Main

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

if @v4Preview
@version = '4.0.0-preview'
V4Main = require './main-v4'

V4Main.includeInto(Main)

workspaceElement = atom.views.getView(atom.workspace)
@activateV4()

if atom.config.get('minimap.displayPluginsControls')
else
@subscriptions.add atom.commands.add 'atom-workspace',
'minimap:open-quick-settings': ->
editor = atom.workspace.getActiveEditor()
@minimapForEditor(editor).openQuickSettings.mousedown()
'minimap:toggle': => @toggle()
'minimap:generate-plugin': => @generatePlugin()

workspaceElement = atom.views.getView(atom.workspace)

if atom.config.get('minimap.displayPluginsControls')
@subscriptions.add atom.commands.add 'atom-workspace',
'minimap:open-quick-settings': ->
editor = atom.workspace.getActiveEditor()
@minimapForEditor(editor).openQuickSettings.mousedown()

@subscriptions.add atom.config.observe 'minimap.displayMinimapOnLeft', (value) ->
workspaceElement.classList.toggle 'minimap-on-left', value
@subscriptions.add atom.config.observe 'minimap.displayMinimapOnLeft', (value) ->
workspaceElement.classList.toggle 'minimap-on-left', value

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

Expand Down
52 changes: 52 additions & 0 deletions spec/minimap-v4-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{TextEditor} = require 'atom'
Minimap = require '../lib/minimap'

describe 'Minimap package v4', ->
[workspaceElement, minimapPackage] = []

beforeEach ->
atom.config.set 'minimap.v4Preview', true

waitsFor -> atom.packages.activatePackage('minimap')

runs ->
minimapPackage = atom.packages.getLoadedPackage('minimap').mainModule

afterEach ->
minimapPackage.deactivate()

it 'returns a custom version instead of the one in package.json', ->
expect(minimapPackage.version).toEqual('4.0.0-preview')

it 'match semver expression in 4.x', ->
expect(minimapPackage.versionMatch('4.x')).toBeTruthy()

it 'registers the minimap views provider', ->
textEditor = new TextEditor({})
minimap = new Minimap({textEditor})
minimapElement = atom.views.getView(minimap)

expect(minimapElement).toExist()

describe 'when an editor is opened', ->
[editor, minimap, editorElement, minimapElement] = []

beforeEach ->
waitsFor ->
atom.workspace.open('sample.coffee')

runs ->
workspaceElement = atom.views.getView(atom.workspace)
jasmine.attachToDOM(workspaceElement)

waitsFor -> atom.workspace.getActiveTextEditor()

runs ->
editor = atom.workspace.getActiveTextEditor()
editorElement = atom.views.getView(editor)

it 'creates a minimap model for the editor', ->
expect(minimapPackage.minimapForEditor(editor)).toBeDefined()

it 'attaches a minimap element to the editor view', ->
expect(editorElement.shadowRoot.querySelector('atom-text-editor-minimap')).toExist()

0 comments on commit 2d07292

Please sign in to comment.