Skip to content

Commit

Permalink
fix: view provider returns correct minimap element (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Feb 1, 2021
1 parent a8cd95a commit 358d781
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DOMStylesReader from "./dom-styles-reader"
export { default as config } from "./config.json"
export * from "./plugin-management"
export { default as Minimap } from "./minimap"
export { default as MinimapElement } from "./minimap-element"

/**
* The `Minimap` package provides an eagle-eye view of text buffers.
Expand Down Expand Up @@ -111,8 +112,11 @@ export function activate() {
*/
export function minimapViewProvider(model) {
if (model instanceof Minimap) {
const element = new MinimapElement()
element.setModel(model)
let element = model.getMinimapElement()
if (!element) {
element = new MinimapElement()
element.setModel(model)
}
return element
}
}
Expand Down Expand Up @@ -397,7 +401,7 @@ function initSubscriptions() {
subscriptions.add(
atom.workspace.observeTextEditors((textEditor) => {
const minimap = minimapForEditor(textEditor)
const minimapElement = minimap.getMinimapElement() || minimapViewProvider(minimap)
const minimapElement = minimapViewProvider(minimap)

emitter.emit("did-create-minimap", minimap)
minimapElement.attach(textEditor.getElement())
Expand Down
12 changes: 11 additions & 1 deletion spec/minimap-main-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
process.env.NODE_ENV = "test"

require("./helpers/workspace")
const { Minimap } = require("../dist/main")
const { Minimap, MinimapElement } = require("../dist/main")

describe("Minimap package", () => {
let [editor, minimap, editorElement, minimapElement, workspaceElement, minimapPackage] = []
Expand Down Expand Up @@ -49,6 +49,16 @@ describe("Minimap package", () => {
expect(minimapElement).toExist()
})

it("provider returns minimap.minimapElement", () => {
const textEditor = atom.workspace.buildTextEditor({})
minimap = new Minimap({ textEditor })
minimapElement = new MinimapElement()
minimapElement.setModel(minimap)
const minimapView = atom.views.getView(minimap)

expect(minimapView).toBe(minimapElement)
})

describe("when an editor is opened", () => {
it("creates a minimap model for the editor", () => {
expect(minimapPackage.minimapForEditor(editor)).toBeDefined()
Expand Down

0 comments on commit 358d781

Please sign in to comment.