-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
208 additions
and
174 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
const { CompositeDisposable } = require('atom') | ||
|
||
class MinimapBookmarksBinding { | ||
constructor (minimap, bookmarks) { | ||
this.minimap = minimap | ||
this.bookmarks = bookmarks | ||
if ((this.minimap == null) || (this.bookmarks == null)) { return } | ||
|
||
this.subscriptions = new CompositeDisposable() | ||
this.editor = this.minimap.getTextEditor() | ||
this.decorationsByMarkerId = {} | ||
this.decorationSubscriptionsByMarkerId = {} | ||
|
||
// We need to wait until the bookmarks package had created its marker | ||
// layer before retrieving its id from the state. | ||
requestAnimationFrame(() => { | ||
// Also, targeting private properties on atom.packages is very brittle. | ||
// DO NOT DO THAT! | ||
// | ||
// If we really have to get the marker layer id from the | ||
// state (which can already break easily) it's better to get it from the | ||
// package `serialize` method since it's an API that is public and is | ||
// unlikely to change in a near future. | ||
const bookmarks = this.bookmarks.serialize()[this.editor.id] | ||
if (!bookmarks) { return } | ||
|
||
const markerLayer = this.editor.getMarkerLayer(bookmarks.markerLayerId) | ||
|
||
if (!markerLayer) { return } | ||
|
||
this.subscriptions.add(markerLayer.onDidCreateMarker(marker => { | ||
this.handleMarker(marker) | ||
})) | ||
|
||
markerLayer.findMarkers().forEach(marker => this.handleMarker(marker)) | ||
}) | ||
} | ||
|
||
handleMarker (marker) { | ||
const { id } = marker | ||
const decoration = this.minimap.decorateMarker(marker, { type: 'line', class: 'bookmark', plugin: 'bookmarks' }) | ||
this.decorationsByMarkerId[id] = decoration | ||
this.decorationSubscriptionsByMarkerId[id] = decoration.onDidDestroy(() => { | ||
this.decorationSubscriptionsByMarkerId[id].dispose() | ||
|
||
delete this.decorationsByMarkerId[id] | ||
delete this.decorationSubscriptionsByMarkerId[id] | ||
}) | ||
} | ||
|
||
destroy () { | ||
for (const id in this.decorationsByMarkerId) { | ||
const decoration = this.decorationsByMarkerId[id] | ||
this.decorationSubscriptionsByMarkerId[id].dispose() | ||
decoration.destroy() | ||
|
||
delete this.decorationsByMarkerId[id] | ||
delete this.decorationSubscriptionsByMarkerId[id] | ||
} | ||
|
||
this.subscriptions.dispose() | ||
} | ||
} | ||
|
||
module.exports = MinimapBookmarksBinding |
This file was deleted.
Oops, something went wrong.
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,73 @@ | ||
/* | ||
* decaffeinate suggestions: | ||
* DS102: Remove unnecessary code created because of implicit returns | ||
* DS201: Simplify complex destructure assignments | ||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md | ||
*/ | ||
const { CompositeDisposable } = require('atom') | ||
let MinimapBookmarksBinding | ||
|
||
module.exports = { | ||
isActive () { | ||
return this.active | ||
}, | ||
|
||
activate () { | ||
this.active = false | ||
this.subscriptions = new CompositeDisposable() | ||
this.bindings = {} | ||
require('atom-package-deps').install('minimap-git-diff') | ||
}, | ||
|
||
consumeMinimapServiceV1 (minimap) { | ||
this.minimap = minimap | ||
this.minimap.registerPlugin('bookmarks', this) | ||
}, | ||
|
||
deactivate () { | ||
if (this.minimap) { | ||
this.minimap.unregisterPlugin('bookmarks') | ||
} | ||
this.minimap = null | ||
}, | ||
|
||
activatePlugin () { | ||
if (this.active) { | ||
return | ||
} | ||
|
||
const bookmarksPkg = atom.packages.getLoadedPackage('bookmarks') | ||
if (!bookmarksPkg) { | ||
return | ||
} | ||
const bookmarks = bookmarksPkg.mainModule | ||
this.active = true | ||
|
||
this.minimapsSubscription = this.minimap.observeMinimaps(minimap => { | ||
if (!MinimapBookmarksBinding) { | ||
MinimapBookmarksBinding = require('./minimap-bookmarks-binding') | ||
} | ||
|
||
const binding = new MinimapBookmarksBinding(minimap, bookmarks) | ||
this.bindings[minimap.id] = binding | ||
|
||
const subscription = minimap.onDidDestroy(() => { | ||
binding.destroy() | ||
this.subscriptions.remove(subscription) | ||
subscription.dispose() | ||
delete this.bindings[minimap.id] | ||
}) | ||
this.subscriptions.add(subscription) | ||
}) | ||
}, | ||
|
||
deactivatePlugin () { | ||
if (!this.active) { return } | ||
|
||
for (const id in this.bindings) { const binding = this.bindings[id]; binding.destroy() } | ||
this.bindings = {} | ||
this.active = false | ||
this.minimapsSubscription.dispose() | ||
this.subscriptions.dispose() | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
/** @babel */ | ||
|
||
export const a = 1 |
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
// const MinimapBookmarks = require('../lib/minimap-bookmarks') | ||
|
||
describe('MinimapBookmarks', () => { | ||
let editor, editorElement, bookmarks | ||
|
||
const bookmarkedRangesForEditor = (editor) => { | ||
const obj = editor.decorationsStateForScreenRowRange(0, editor.getLastScreenRow()) | ||
return Object.keys(obj) | ||
.map(k => obj[k]) | ||
.filter(decoration => decoration.properties.class === 'bookmarked') | ||
.map(decoration => decoration.screenRange) | ||
} | ||
|
||
beforeEach(async () => { | ||
const workspace = atom.views.getView(atom.workspace) | ||
jasmine.attachToDOM(workspace) | ||
|
||
// Package activation will be deferred to the configured, activation hook, which is then triggered | ||
// Activate activation hook | ||
atom.packages.triggerDeferredActivationHooks() | ||
atom.packages.triggerActivationHook('core:loaded-shell-environment') | ||
|
||
editor = await atom.workspace.open('sample.js') | ||
editorElement = atom.views.getView(editor) | ||
|
||
bookmarks = (await atom.packages.activatePackage('bookmarks')).mainModule | ||
|
||
await atom.packages.activatePackage('minimap') | ||
await atom.packages.activatePackage('minimap-bookmarks') | ||
|
||
atom.packages.packageStates.bookmarks = bookmarks.serialize() | ||
}) | ||
|
||
describe('with an open editor that have a minimap', () => describe('when toggle switch bookmarks markers to the editor', () => { | ||
beforeEach(() => { | ||
editor.setCursorScreenPosition([2, 0]) | ||
atom.commands.dispatch(editorElement, 'bookmarks:toggle-bookmark') | ||
|
||
editor.setCursorScreenPosition([3, 0]) | ||
atom.commands.dispatch(editorElement, 'bookmarks:toggle-bookmark') | ||
|
||
editor.setCursorScreenPosition([1, 0]) | ||
atom.commands.dispatch(editorElement, 'bookmarks:toggle-bookmark') | ||
atom.commands.dispatch(editorElement, 'bookmarks:toggle-bookmark') | ||
}) | ||
|
||
it('creates tow markers', () => { | ||
expect(bookmarkedRangesForEditor(editor).length).toBe(2) | ||
}) | ||
|
||
it('creates state of bookmarks', () => { | ||
expect(Object.keys(atom.packages.packageStates.bookmarks).length).toBe(1) | ||
}) | ||
|
||
it('gets markerLayerId from state of bookmarks by editorId', () => { | ||
const { markerLayerId } = atom.packages.packageStates.bookmarks[editor.id] | ||
|
||
expect(markerLayerId).toBeDefined() | ||
}) | ||
|
||
it('finds marks by markerLayerId', () => { | ||
const { markerLayerId } = atom.packages.packageStates.bookmarks[editor.id] | ||
const markerLayer = editor.getMarkerLayer(markerLayerId) | ||
expect(markerLayer.findMarkers().length).toBe(2) | ||
}) | ||
})) | ||
}) |