Skip to content

Commit

Permalink
Add a new adjustMinimapWidthOnlyIfSmaller setting to disable CSS limi…
Browse files Browse the repository at this point in the history
…tation

Closes #452
  • Loading branch information
abe33 committed May 20, 2016
1 parent e72e2dd commit cc7161e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ The scrolling speed when the `Independent Minimap Scroll On Mouse Wheel Events`

If checked the Minimap scroll is done using a `translate3d` transform, otherwise the `translate` transform is used. `(default=true)`

#### Adjust Minimap Width To Soft Wrap

If this option is enabled and Soft Wrap is checked then the Minimap max width is set to the Preferred Line Length value. `(default=true)`

#### Adjust Minimap Width Only When Smaller

If this option and `adjustMinimapWidthToSoftWrap` are enabled the minimap width will never go past the limit sets by CSS. On the other hand, when disabled the minimap will expand to honor the preferred line width. `(default=true)`

#### Absolute Mode

When enabled the Minimap uses an absolute positioning, letting the editor's content flow below the Minimap. `(default=false)`
Expand Down
5 changes: 5 additions & 0 deletions lib/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"default":true,
"description":"If this option is enabled and Soft Wrap is checked then the Minimap max width is set to the Preferred Line Length value."
},
"adjustMinimapWidthOnlyIfSmaller": {
"type":"boolean",
"default":true,
"description":"If this option and `adjustMinimapWidthToSoftWrap` are enabled the minimap width will never go past the limit sets by CSS. On the other hand, when disabled the minimap will expand to honor the preferred line width."
},
"devicePixelRatioRounding":{
"type":"boolean",
"default":true,
Expand Down
18 changes: 12 additions & 6 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ export default class MinimapElement {
if (this.attached) { this.measureHeightAndWidth() }
},

'minimap.adjustMinimapWidthOnlyIfSmaller': (adjustOnlyIfSmaller) => {
this.adjustOnlyIfSmaller = adjustOnlyIfSmaller

if (this.attached) { this.measureHeightAndWidth() }
},

'minimap.useHardwareAcceleration': (useHardwareAcceleration) => {
this.useHardwareAcceleration = useHardwareAcceleration

Expand Down Expand Up @@ -764,14 +770,14 @@ export default class MinimapElement {
*/
update () {
if (!(this.attached && this.isVisible() && this.minimap)) { return }
let minimap = this.minimap
const minimap = this.minimap
minimap.enableCache()
let canvas = this.getFrontCanvas()
const canvas = this.getFrontCanvas()

const devicePixelRatio = this.minimap.getDevicePixelRatio()
let visibleAreaLeft = minimap.getTextEditorScaledScrollLeft()
let visibleAreaTop = minimap.getTextEditorScaledScrollTop() - minimap.getScrollTop()
let visibleWidth = Math.min(canvas.width / devicePixelRatio, this.width)
const visibleAreaLeft = minimap.getTextEditorScaledScrollLeft()
const visibleAreaTop = minimap.getTextEditorScaledScrollTop() - minimap.getScrollTop()
const visibleWidth = Math.min(canvas.width / devicePixelRatio, this.width)

if (this.adjustToSoftWrap && this.flexBasis) {
this.style.flexBasis = this.flexBasis + 'px'
Expand Down Expand Up @@ -939,7 +945,7 @@ export default class MinimapElement {
let softWrapAtPreferredLineLength = atom.config.get('editor.softWrapAtPreferredLineLength')
let width = lineLength * this.minimap.getCharWidth()

if (softWrap && softWrapAtPreferredLineLength && lineLength && width <= this.width) {
if (softWrap && softWrapAtPreferredLineLength && lineLength && (width <= this.width || !this.adjustOnlyIfSmaller)) {
this.flexBasis = width
canvasWidth = width
} else {
Expand Down
20 changes: 20 additions & 0 deletions spec/minimap-element-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('MinimapElement', () => {
atom.config.set('minimap.interline', 1)
atom.config.set('minimap.textOpacity', 1)
atom.config.set('minimap.smoothScrolling', true)
atom.config.set('minimap.adjustMinimapWidthOnlyIfSmaller', true)
atom.config.set('minimap.plugins', {})

MinimapElement.registerViewProvider(Minimap)
Expand Down Expand Up @@ -1411,6 +1412,25 @@ describe('MinimapElement', () => {
expect(minimapElement.style.width).toEqual('')
})
})

describe('when adjustMinimapWidthOnlyIfSmaller is disabled', () => {
describe('and when preferredLineLength >= 16384', () => {
beforeEach(() => {
atom.config.set('minimap.adjustMinimapWidthOnlyIfSmaller', false)
atom.config.set('editor.preferredLineLength', 16384)

waitsFor('minimap frame requested', () => {
return minimapElement.frameRequested
})
runs(() => { nextAnimationFrame() })
})

it('adjusts the width of the minimap', () => {
expect(minimapElement.offsetWidth).toBeCloseTo(16384 * 2)
expect(minimapElement.style.width).toEqual(16384 * 2 + 'px')
})
})
})
})

describe('when minimap.minimapScrollIndicator setting is true', () => {
Expand Down

0 comments on commit cc7161e

Please sign in to comment.