Skip to content

Commit 2029c6a

Browse files
committed
fix: move getTextEditorElement method to Minimap class
1 parent f0ce080 commit 2029c6a

File tree

4 files changed

+48
-51
lines changed

4 files changed

+48
-51
lines changed

lib/minimap-element.js

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ class MinimapElement {
8383
* @access private
8484
*/
8585
this.minimap = undefined
86-
/**
87-
* @access private
88-
*/
89-
this.editorElement = undefined
86+
9087
/**
9188
* @access private
9289
*/
@@ -384,10 +381,10 @@ class MinimapElement {
384381
this.measureHeightAndWidth()
385382
this.updateMinimapFlexPosition()
386383
this.attached = true
387-
this.attachedToTextEditor = this.queryParentSelector('atom-text-editor') === this.getTextEditorElement()
384+
this.attachedToTextEditor = this.queryParentSelector('atom-text-editor') === this.minimap.getTextEditorElement()
388385

389386
if (this.attachedToTextEditor) {
390-
this.getTextEditorElement().setAttribute('with-minimap', '')
387+
this.minimap.getTextEditorElement().setAttribute('with-minimap', '')
391388
}
392389

393390
this.subscriptions.add(
@@ -413,7 +410,7 @@ class MinimapElement {
413410
* @access private
414411
*/
415412
detachedCallback () {
416-
this.getTextEditorElement().removeAttribute('with-minimap')
413+
this.minimap.getTextEditorElement().removeAttribute('with-minimap')
417414
this.attached = false
418415
}
419416

@@ -447,7 +444,7 @@ class MinimapElement {
447444
attach (parent) {
448445
if (this.attached) { return }
449446

450-
const container = parent || this.getTextEditorElement()
447+
const container = parent || this.minimap.getTextEditorElement()
451448
const minimaps = container.querySelectorAll('atom-text-editor-minimap')
452449
if (minimaps.length) {
453450
Array.prototype.forEach.call(minimaps, (el) => { el.destroy() })
@@ -671,25 +668,6 @@ class MinimapElement {
671668
delete this.openQuickSettings
672669
}
673670

674-
/**
675-
* Returns the target `TextEditor` of the Minimap.
676-
*
677-
* @return {TextEditor} the minimap's text editor
678-
*/
679-
getTextEditor () { return this.minimap.getTextEditor() }
680-
681-
/**
682-
* Returns the `TextEditorElement` for the Minimap's `TextEditor`.
683-
*
684-
* @return {TextEditorElement} the minimap's text editor element
685-
*/
686-
getTextEditorElement () {
687-
if (this.editorElement) { return this.editorElement }
688-
689-
this.editorElement = atom.views.getView(this.getTextEditor())
690-
return this.editorElement
691-
}
692-
693671
// ## ## ####### ######## ######## ##
694672
// ### ### ## ## ## ## ## ##
695673
// #### #### ## ## ## ## ## ##
@@ -1095,7 +1073,7 @@ class MinimapElement {
10951073
const row = Math.floor(deltaY / this.minimap.getLineHeight()) + this.minimap.getFirstVisibleScreenRow()
10961074

10971075
const textEditor = this.minimap.getTextEditor()
1098-
const textEditorElement = this.getTextEditorElement()
1076+
const textEditorElement = this.minimap.getTextEditorElement()
10991077

11001078
const scrollTop = row * textEditor.getLineHeightInPixels() - this.minimap.getTextEditorHeight() / 2
11011079
const textEditorScrollTop = textEditorElement.pixelPositionForScreenPosition([row, 0]).top - this.minimap.getTextEditorHeight() / 2

lib/minimap.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export default class Minimap {
4646
* @access private
4747
*/
4848
this.textEditor = options.textEditor
49+
50+
/**
51+
* The Minimap's text editor element.
52+
* @access private
53+
*/
54+
this.editorElement = undefined
55+
4956
/**
5057
* The stand-alone state of the current Minimap.
5158
*
@@ -525,6 +532,18 @@ export default class Minimap {
525532
*/
526533
getTextEditor () { return this.textEditor }
527534

535+
/**
536+
* Returns the `TextEditorElement` for the Minimap's `TextEditor`.
537+
*
538+
* @return {TextEditorElement} the minimap's text editor element
539+
*/
540+
getTextEditorElement () {
541+
if (this.editorElement) { return this.editorElement }
542+
543+
this.editorElement = atom.views.getView(this.getTextEditor())
544+
return this.editorElement
545+
}
546+
528547
/**
529548
* Returns the height of the `TextEditor` at the Minimap scale.
530549
*

lib/mixins/canvas-drawer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export default class CanvasDrawer {
194194
* @return {string} a CSS color
195195
*/
196196
getDefaultColor () {
197-
const color = this.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color', this.getTextEditorElement(), true)
197+
const color = this.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color', this.minimap.getTextEditorElement(), true)
198198
return transparentize(color, this.getTextOpacity())
199199
}
200200

@@ -209,7 +209,7 @@ export default class CanvasDrawer {
209209
*/
210210
getTokenColor (token) {
211211
const scopes = token.scopeDescriptor || token.scopes
212-
const color = this.DOMStylesReader.retrieveStyleFromDom(scopes, 'color', this.getTextEditorElement(), true)
212+
const color = this.DOMStylesReader.retrieveStyleFromDom(scopes, 'color', this.minimap.getTextEditorElement(), true)
213213

214214
return transparentize(color, this.getTextOpacity())
215215
}
@@ -230,7 +230,7 @@ export default class CanvasDrawer {
230230

231231
if (properties.scope) {
232232
const scopeString = properties.scope.split(/\s+/)
233-
return this.DOMStylesReader.retrieveStyleFromDom(scopeString, 'background-color', this.getTextEditorElement(), true)
233+
return this.DOMStylesReader.retrieveStyleFromDom(scopeString, 'background-color', this.minimap.getTextEditorElement(), true)
234234
} else {
235235
return this.getDefaultColor()
236236
}

spec/minimap-element-spec.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('MinimapElement', () => {
232232
})
233233
runs(() => {
234234
nextAnimationFrame()
235-
expect(minimapElement.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color'), minimapElement.getTextEditorElement()).toEqual(`rgb(0, ${0x6d}, ${0x6d})`)
235+
expect(minimapElement.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color'), minimapElement.minimap.getTextEditorElement()).toEqual(`rgb(0, ${0x6d}, ${0x6d})`)
236236
})
237237
})
238238
})
@@ -260,7 +260,7 @@ describe('MinimapElement', () => {
260260
})
261261
runs(() => {
262262
nextAnimationFrame()
263-
expect(minimapElement.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color'), minimapElement.getTextEditorElement()).toEqual(`rgba(0, ${0x6d}, ${0x6d}, 0)`)
263+
expect(minimapElement.DOMStylesReader.retrieveStyleFromDom(['.editor'], 'color'), minimapElement.minimap.getTextEditorElement()).toEqual(`rgba(0, ${0x6d}, ${0x6d}, 0)`)
264264
})
265265
})
266266
})
@@ -329,10 +329,10 @@ describe('MinimapElement', () => {
329329
atom.config.set('minimap.plugins.fooDecorationsZIndex', 1)
330330

331331
const calls = []
332-
spyOn(minimapElement, 'drawLineDecoration').andCallFake((d) => {
332+
spyOn(minimapElement.CanvasDrawer, 'drawLineDecoration').andCallFake((d) => {
333333
calls.push(d.getProperties().plugin)
334334
})
335-
spyOn(minimapElement, 'drawHighlightDecoration').andCallFake((d) => {
335+
spyOn(minimapElement.CanvasDrawer, 'drawHighlightDecoration').andCallFake((d) => {
336336
calls.push(d.getProperties().plugin)
337337
})
338338

@@ -369,7 +369,7 @@ describe('MinimapElement', () => {
369369
})
370370

371371
it('renders the visible line decorations', () => {
372-
spyOn(minimapElement, 'drawLineDecoration').andCallThrough()
372+
spyOn(minimapElement.CanvasDrawer, 'drawLineDecoration').andCallThrough()
373373

374374
minimap.decorateMarker(editor.markBufferRange([[1, 0], [1, 10]]), { type: 'line', color: '#0000FF' })
375375
minimap.decorateMarker(editor.markBufferRange([[10, 0], [10, 10]]), { type: 'line', color: '#0000FF' })
@@ -383,8 +383,8 @@ describe('MinimapElement', () => {
383383
runs(() => {
384384
nextAnimationFrame()
385385

386-
expect(minimapElement.drawLineDecoration).toHaveBeenCalled()
387-
expect(minimapElement.drawLineDecoration.calls.length).toEqual(2)
386+
expect(minimapElement.CanvasDrawer.drawLineDecoration).toHaveBeenCalled()
387+
expect(minimapElement.CanvasDrawer.drawLineDecoration.calls.length).toEqual(2)
388388
})
389389
})
390390

@@ -409,7 +409,7 @@ describe('MinimapElement', () => {
409409
})
410410

411411
it('renders the visible highlight decorations', () => {
412-
spyOn(minimapElement, 'drawHighlightDecoration').andCallThrough()
412+
spyOn(minimapElement.CanvasDrawer, 'drawHighlightDecoration').andCallThrough()
413413

414414
minimap.decorateMarker(editor.markBufferRange([[1, 0], [1, 4]]), { type: 'highlight-under', color: '#0000FF' })
415415
minimap.decorateMarker(editor.markBufferRange([[2, 20], [2, 30]]), { type: 'highlight-over', color: '#0000FF' })
@@ -429,7 +429,7 @@ describe('MinimapElement', () => {
429429
})
430430

431431
it('renders the visible outline decorations', () => {
432-
spyOn(minimapElement, 'drawHighlightOutlineDecoration').andCallThrough()
432+
spyOn(minimapElement.CanvasDrawer, 'drawHighlightOutlineDecoration').andCallThrough()
433433

434434
minimap.decorateMarker(editor.markBufferRange([[1, 4], [3, 6]]), { type: 'highlight-outline', color: '#0000ff' })
435435
minimap.decorateMarker(editor.markBufferRange([[6, 0], [6, 7]]), { type: 'highlight-outline', color: '#0000ff' })
@@ -443,13 +443,13 @@ describe('MinimapElement', () => {
443443
runs(() => {
444444
nextAnimationFrame()
445445

446-
expect(minimapElement.drawHighlightOutlineDecoration).toHaveBeenCalled()
447-
expect(minimapElement.drawHighlightOutlineDecoration.calls.length).toEqual(4)
446+
expect(minimapElement.CanvasDrawer.drawHighlightOutlineDecoration).toHaveBeenCalled()
447+
expect(minimapElement.CanvasDrawer.drawHighlightOutlineDecoration.calls.length).toEqual(4)
448448
})
449449
})
450450

451451
it('renders the visible custom foreground decorations', () => {
452-
spyOn(minimapElement, 'drawCustomDecoration').andCallThrough()
452+
spyOn(minimapElement.CanvasDrawer, 'drawCustomDecoration').andCallThrough()
453453

454454
const renderRoutine = jasmine.createSpy('renderRoutine')
455455

@@ -470,16 +470,16 @@ describe('MinimapElement', () => {
470470
runs(() => {
471471
nextAnimationFrame()
472472

473-
expect(minimapElement.drawCustomDecoration).toHaveBeenCalled()
474-
expect(minimapElement.drawCustomDecoration.calls.length).toEqual(4)
473+
expect(minimapElement.CanvasDrawer.drawCustomDecoration).toHaveBeenCalled()
474+
expect(minimapElement.CanvasDrawer.drawCustomDecoration.calls.length).toEqual(4)
475475

476476
expect(renderRoutine).toHaveBeenCalled()
477477
expect(renderRoutine.calls.length).toEqual(4)
478478
})
479479
})
480480

481481
it('renders the visible custom background decorations', () => {
482-
spyOn(minimapElement, 'drawCustomDecoration').andCallThrough()
482+
spyOn(minimapElement.CanvasDrawer, 'drawCustomDecoration').andCallThrough()
483483

484484
const renderRoutine = jasmine.createSpy('renderRoutine')
485485

@@ -500,8 +500,8 @@ describe('MinimapElement', () => {
500500
runs(() => {
501501
nextAnimationFrame()
502502

503-
expect(minimapElement.drawCustomDecoration).toHaveBeenCalled()
504-
expect(minimapElement.drawCustomDecoration.calls.length).toEqual(4)
503+
expect(minimapElement.CanvasDrawer.drawCustomDecoration).toHaveBeenCalled()
504+
expect(minimapElement.CanvasDrawer.drawCustomDecoration.calls.length).toEqual(4)
505505

506506
expect(renderRoutine).toHaveBeenCalled()
507507
expect(renderRoutine.calls.length).toEqual(4)
@@ -561,7 +561,7 @@ describe('MinimapElement', () => {
561561
runs(() => {
562562
nextAnimationFrame()
563563

564-
spyOn(minimapElement, 'drawLines').andCallThrough()
564+
spyOn(minimapElement.CanvasDrawer, 'drawLines').andCallThrough()
565565
editor.insertText('foo')
566566
})
567567
})
@@ -573,9 +573,9 @@ describe('MinimapElement', () => {
573573
runs(() => {
574574
nextAnimationFrame()
575575

576-
expect(minimapElement.drawLines).toHaveBeenCalled()
576+
expect(minimapElement.CanvasDrawer.drawLines).toHaveBeenCalled()
577577

578-
const [firstLine, lastLine] = minimapElement.drawLines.argsForCall[0]
578+
const [firstLine, lastLine] = minimapElement.CanvasDrawer.drawLines.argsForCall[0]
579579

580580
// These tests are very flaky, depending on Atom's version the
581581
// measured values can changed so we have

0 commit comments

Comments
 (0)