Skip to content

Commit

Permalink
Add support for adjustMinimapWidthToSoftWrap config
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Dec 16, 2014
1 parent a92fd5d commit b66bbbb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
50 changes: 36 additions & 14 deletions lib/minimap-element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@ class MinimapElement extends HTMLElement
@subscriptions = new CompositeDisposable
@initializeContent()

@subscriptions.add atom.config.observe 'minimap.displayMinimapOnLeft', (displayMinimapOnLeft) =>
swapPosition = @attached and displayMinimapOnLeft isnt @displayMinimapOnLeft
@displayMinimapOnLeft = displayMinimapOnLeft
@observeConfig
'minimap.displayMinimapOnLeft': (displayMinimapOnLeft) =>
swapPosition = @attached and displayMinimapOnLeft isnt @displayMinimapOnLeft
@displayMinimapOnLeft = displayMinimapOnLeft

@swapMinimapPosition() if swapPosition
@swapMinimapPosition() if swapPosition

@subscriptions.add atom.config.observe 'minimap.minimapScrollIndicator', (@minimapScrollIndicator) =>
if @minimapScrollIndicator and not @scrollIndicator?
@initializeScrollIndicator()
else if @scrollIndicator?
@disposeScrollIndicator()
'minimap.minimapScrollIndicator': (@minimapScrollIndicator) =>
if @minimapScrollIndicator and not @scrollIndicator?
@initializeScrollIndicator()
else if @scrollIndicator?
@disposeScrollIndicator()

@subscriptions.add atom.config.observe 'minimap.textOpacity', (@textOpacity) =>
@requestForcedUpdate() if @attached
'minimap.textOpacity': (@textOpacity) =>
@requestForcedUpdate() if @attached

@subscriptions.add atom.config.observe 'minimap.displayCodeHighlights', (@displayCodeHighlights) =>
@requestForcedUpdate() if @attached
'minimap.displayCodeHighlights': (@displayCodeHighlights) =>
@requestForcedUpdate() if @attached

'minimap.adjustMinimapWidthToSoftWrap': (@adjustToSoftWrap) =>
if @attached
@measureHeightAndWidth()
@requestForcedUpdate()

observeConfig: (configs={}) ->
for config, callback of configs
@subscriptions.add atom.config.observe config, callback

attachedCallback: ->
@domPollingIntervalId = setInterval((=> @pollDOM()), @domPollingInterval)
Expand Down Expand Up @@ -120,8 +130,15 @@ class MinimapElement extends HTMLElement
@requestUpdate()

measureHeightAndWidth: ->
@width = @clientWidth
@height = @clientHeight
@width = @clientWidth

if @adjustToSoftWrap
lineLength = atom.config.get('editor.preferredLineLength')
softWrap = atom.config.get('editor.softWrap')
width = lineLength * @minimap.getCharWidth()

@width = width if softWrap and lineLength and width < @width

if @width isnt @canvas.width or @height isnt @canvas.height
@canvas.width = @width * devicePixelRatio
Expand Down Expand Up @@ -159,6 +176,11 @@ class MinimapElement extends HTMLElement
update: ->
return unless @attached

if @adjustToSoftWrap
@style.width = @width + 'px'
else
@style.width = null

@visibleArea.style.width = @clientWidth + 'px'
@visibleArea.style.height = @minimap.getTextEditorHeight() + 'px'
@visibleArea.style.top = (@minimap.getTextEditorScrollTop() - @minimap.getMinimapScrollTop()) + 'px'
Expand Down
21 changes: 21 additions & 0 deletions spec/minimap-element-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ describe 'MinimapElement', ->
it 'moves the attached minimap to the left', ->
expect(Array::indexOf.call(editorElement.shadowRoot.children, minimapElement)).toEqual(0)

describe 'when minimap.adjustMinimapWidthToSoftWrap is true', ->
beforeEach ->
atom.config.set 'editor.softWrap', true
atom.config.set 'editor.softWrapAtPreferredLineLength', true
atom.config.set 'editor.preferredLineLength', 2

atom.config.set 'minimap.adjustMinimapWidthToSoftWrap', true
nextAnimationFrame()

it 'adjusts the width of the minimap', ->
expect(minimapElement.offsetWidth).toEqual(4)

describe 'and then disabled', ->
beforeEach ->
atom.config.set 'minimap.adjustMinimapWidthToSoftWrap', false
nextAnimationFrame()

it 'adjusts the width of the minimap', ->
expect(minimapElement.offsetWidth).toBeCloseTo(editorElement.offsetWidth / 11, 0)
expect(minimapElement.style.width).toEqual('')

describe 'when minimap.minimapScrollIndicator setting is true', ->
beforeEach ->
editor.setText(mediumSample)
Expand Down

0 comments on commit b66bbbb

Please sign in to comment.