-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a basic switch in main to enable v4 preview
- Loading branch information
Showing
3 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |