Skip to content

Commit

Permalink
🐛 Fix position of right positioned controls without using offset
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 18, 2014
1 parent f28f41d commit 4f32ca7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,23 @@ class MinimapElement extends HTMLElement
@visibleArea.classList.add('minimap-visible-area')
@shadowRoot.appendChild(@visibleArea)

@controls = document.createElement('div')
@controls.classList.add('minimap-controls')
@shadowRoot.appendChild(@controls)

initializeScrollIndicator: ->
@scrollIndicator = document.createElement('div')
@scrollIndicator.classList.add 'minimap-scroll-indicator'
@shadowRoot.appendChild(@scrollIndicator)
@controls.appendChild(@scrollIndicator)

disposeScrollIndicator: ->
@shadowRoot.removeChild(@scrollIndicator)
@controls.removeChild(@scrollIndicator)
@scrollIndicator = undefined

initializeOpenQuickSettings: ->
@openQuickSettings = document.createElement('div')
@openQuickSettings.classList.add 'open-minimap-quick-settings'
@shadowRoot.appendChild(@openQuickSettings)
@controls.appendChild(@openQuickSettings)
@openQuickSettings.addEventListener 'click', (e) =>
MinimapQuickSettingsView ?= require './minimap-quick-settings-view'

Expand All @@ -145,7 +149,7 @@ class MinimapElement extends HTMLElement
})

disposeOpenQuickSettings: ->
@shadowRoot.removeChild(@openQuickSettings)
@controls.removeChild(@openQuickSettings)
@openQuickSettings = undefined

pauseDOMPolling: ->
Expand Down Expand Up @@ -230,6 +234,8 @@ class MinimapElement extends HTMLElement
@visibleArea.style.height = @minimap.getTextEditorHeight() + 'px'
@transformElement @visibleArea, @makeTranslate(visibleAreaLeft, visibleAreaTop)

@controls.style.width = @canvas.width + 'px'

canvasTop = @minimap.getFirstVisibleScreenRow() * @minimap.getLineHeight() - @minimap.getMinimapScrollTop()

@transformElement(@canvas, @makeTranslate(0, canvasTop))
Expand All @@ -241,11 +247,8 @@ class MinimapElement extends HTMLElement
editorHeight = @getTextEditor().getHeight()
indicatorHeight = editorHeight * (editorHeight / @minimap.getHeight())
indicatorScroll = (editorHeight - indicatorHeight) * @minimap.getTextEditorScrollRatio()
indicatorOffset = 0
indicatorOffset = @marginRight if @adjustToSoftWrap

@scrollIndicator.style.height = indicatorHeight + 'px'
@transformElement @scrollIndicator, @makeTranslate(indicatorOffset, indicatorScroll)
@transformElement @scrollIndicator, @makeTranslate(0, indicatorScroll)

@disposeScrollIndicator() if not @minimap.canScroll()

Expand Down
9 changes: 9 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ describe 'MinimapElement', ->
indicator = minimapElement.shadowRoot.querySelector('.minimap-scroll-indicator')
expect(realOffsetLeft(indicator)).toBeCloseTo(2, -1)

describe 'and when minimap.displayPluginsControls setting is true', ->
beforeEach ->
atom.config.set 'minimap.displayPluginsControls', true
nextAnimationFrame()

it 'offsets the scroll indicator by the difference', ->
openQuickSettings = minimapElement.shadowRoot.querySelector('.open-minimap-quick-settings')
expect(realOffsetLeft(openQuickSettings)).toBeCloseTo(2 - openQuickSettings.offsetWidth, -1)

describe 'and then disabled', ->
beforeEach ->
atom.config.set 'minimap.adjustMinimapWidthToSoftWrap', false
Expand Down
5 changes: 5 additions & 0 deletions stylesheets/minimap.less
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ atom-text-editor::shadow, atom-text-editor {
cursor: -webkit-grab;
}

.minimap-controls {
position: relative;
height: 100%;
}

.minimap-scroll-indicator {
position: absolute;
display: block;
Expand Down

0 comments on commit 4f32ca7

Please sign in to comment.