From 5f37e22cc5ed9527689fa832a667fed59ffe2fb3 Mon Sep 17 00:00:00 2001 From: abe33 Date: Sat, 15 Aug 2015 14:47:17 +0200 Subject: [PATCH] Add a flag in minimap element to know whether it has been attached to a text editor or not --- lib/minimap-element.coffee | 5 +++-- spec/minimap-element-spec.coffee | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/minimap-element.coffee b/lib/minimap-element.coffee index a60f85fc..5846e7bc 100644 --- a/lib/minimap-element.coffee +++ b/lib/minimap-element.coffee @@ -1,6 +1,6 @@ {debounce} = require 'underscore-plus' {CompositeDisposable, Disposable} = require 'event-kit' -{EventsDelegation} = require 'atom-utils' +{EventsDelegation, AncestorsMethods} = require 'atom-utils' DOMStylesReader = require './mixins/dom-styles-reader' CanvasDrawer = require './mixins/canvas-drawer' @@ -22,6 +22,7 @@ class MinimapElement extends HTMLElement DOMStylesReader.includeInto(this) CanvasDrawer.includeInto(this) EventsDelegation.includeInto(this) + AncestorsMethods.includeInto(this) ### Public ### @@ -90,6 +91,7 @@ class MinimapElement extends HTMLElement @measureHeightAndWidth() @updateMinimapFlexPosition() @attached = true + @attachedToTextEditor = @parentNode is @getTextEditorElementRoot() # Uses of `atom.styles.onDidAddStyleElement` instead of # `atom.themes.onDidChangeActiveThemes`. @@ -332,7 +334,6 @@ class MinimapElement extends HTMLElement visibleAreaTop = @minimap.getTextEditorScaledScrollTop() - @minimap.getScrollTop() visibleWidth = Math.min(@canvas.width / devicePixelRatio, @width) - @applyStyles @visibleArea, width: visibleWidth + 'px' height: @minimap.getTextEditorScaledHeight() + 'px' diff --git a/spec/minimap-element-spec.coffee b/spec/minimap-element-spec.coffee index 66febc74..1923d2f7 100644 --- a/spec/minimap-element-spec.coffee +++ b/spec/minimap-element-spec.coffee @@ -130,6 +130,9 @@ describe 'MinimapElement', -> # and not 20px expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.clientWidth / 11, 0) + it 'knows when attached to a text editor', -> + expect(minimapElement.attachedToTextEditor).toBeTruthy() + it 'resizes the canvas to fit the minimap', -> expect(canvas.offsetHeight / devicePixelRatio).toBeCloseTo(minimapElement.offsetHeight + minimap.getLineHeight(), 0) expect(canvas.offsetWidth / devicePixelRatio).toBeCloseTo(minimapElement.offsetWidth, 0)