From d1e95aa87161b0444179f04e7988f04d0899d314 Mon Sep 17 00:00:00 2001 From: abe33 Date: Sun, 14 Dec 2014 14:06:08 +0100 Subject: [PATCH] Add view provider registration method on minimap element --- lib/minimap-element.coffee | 12 +++++++++++- spec/minimap-element-spec.coffee | 26 ++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index b636c932..87c2d8fb 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -4,10 +4,20 @@ class MinimapElement extends HTMLElement @initializeContent() attachedCallback: -> + detachedCallback: -> + attributeChangedCallback: (attrName, oldValue, newValue) -> + setModel: (model) -> + initializeContent: -> @shadowRoot = @createShadowRoot() -module.exports = MinimapElement = document.registerElement 'minimap', prototype: MinimapElement.prototype +module.exports = MinimapElement = document.registerElement 'atom-text-editor-minimap', prototype: MinimapElement.prototype + +MinimapElement.registerViewProvider = -> + atom.views.addViewProvider require('./minimap'), (model) -> + element = new MinimapElement + element.setModel(model) + element diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index bcce0c4b..d2fa45d7 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -1,6 +1,28 @@ +fs = require 'fs-plus' +{TextEditor} = require 'atom' +Minimap = require '../lib/minimap' +MinimapElement = require '../lib/minimap-element' describe 'MinimapElement', -> - jasmineContent = null + [editor, minimap, largeSample, smallSample, jasmineContent, editorElement, minimapElement] = [] beforeEach -> - jasmineContent = document.body.querySelector('#jasmine-content') + atom.config.set 'minimap.charHeight', 4 + atom.config.set 'minimap.charWidth', 2 + atom.config.set 'minimap.interline', 1 + + MinimapElement.registerViewProvider() + + editor = new TextEditor({}) + editor.setLineHeightInPixels(10) + editor.setHeight(50) + + minimap = new Minimap({textEditor: editor}) + largeSample = fs.readFileSync(atom.project.resolve('large-file.coffee')).toString() + smallSample = fs.readFileSync(atom.project.resolve('sample.coffee')).toString() + + editorElement = atom.views.getView(editor) + minimapElement = atom.views.getView(minimap) + + it 'has been registered in the view registry', -> + expect(minimapElement).toExist()