Skip to content

Commit 358d781

Browse files
authored
fix: view provider returns correct minimap element (#781)
1 parent a8cd95a commit 358d781

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/main.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import DOMStylesReader from "./dom-styles-reader"
1111
export { default as config } from "./config.json"
1212
export * from "./plugin-management"
1313
export { default as Minimap } from "./minimap"
14+
export { default as MinimapElement } from "./minimap-element"
1415

1516
/**
1617
* The `Minimap` package provides an eagle-eye view of text buffers.
@@ -111,8 +112,11 @@ export function activate() {
111112
*/
112113
export function minimapViewProvider(model) {
113114
if (model instanceof Minimap) {
114-
const element = new MinimapElement()
115-
element.setModel(model)
115+
let element = model.getMinimapElement()
116+
if (!element) {
117+
element = new MinimapElement()
118+
element.setModel(model)
119+
}
116120
return element
117121
}
118122
}
@@ -397,7 +401,7 @@ function initSubscriptions() {
397401
subscriptions.add(
398402
atom.workspace.observeTextEditors((textEditor) => {
399403
const minimap = minimapForEditor(textEditor)
400-
const minimapElement = minimap.getMinimapElement() || minimapViewProvider(minimap)
404+
const minimapElement = minimapViewProvider(minimap)
401405

402406
emitter.emit("did-create-minimap", minimap)
403407
minimapElement.attach(textEditor.getElement())

spec/minimap-main-spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
process.env.NODE_ENV = "test"
33

44
require("./helpers/workspace")
5-
const { Minimap } = require("../dist/main")
5+
const { Minimap, MinimapElement } = require("../dist/main")
66

77
describe("Minimap package", () => {
88
let [editor, minimap, editorElement, minimapElement, workspaceElement, minimapPackage] = []
@@ -49,6 +49,16 @@ describe("Minimap package", () => {
4949
expect(minimapElement).toExist()
5050
})
5151

52+
it("provider returns minimap.minimapElement", () => {
53+
const textEditor = atom.workspace.buildTextEditor({})
54+
minimap = new Minimap({ textEditor })
55+
minimapElement = new MinimapElement()
56+
minimapElement.setModel(minimap)
57+
const minimapView = atom.views.getView(minimap)
58+
59+
expect(minimapView).toBe(minimapElement)
60+
})
61+
5262
describe("when an editor is opened", () => {
5363
it("creates a minimap model for the editor", () => {
5464
expect(minimapPackage.minimapForEditor(editor)).toBeDefined()

0 commit comments

Comments
 (0)