Skip to content

Commit

Permalink
Add a flag in minimap element to know whether it has been attached to…
Browse files Browse the repository at this point in the history
… a text editor or not
  • Loading branch information
abe33 committed Aug 15, 2015
1 parent 225293f commit 5f37e22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -22,6 +22,7 @@ class MinimapElement extends HTMLElement
DOMStylesReader.includeInto(this)
CanvasDrawer.includeInto(this)
EventsDelegation.includeInto(this)
AncestorsMethods.includeInto(this)

### Public ###

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5f37e22

Please sign in to comment.