Skip to content

Free up free functions in CanvasDrawer #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { EventsDelegation, AncestorsMethods } from 'atom-utils-plus'
import elementResizeDetectorImport from 'element-resize-detector'

import * as Main from './main'
import DOMStylesReader from './dom-styles-reader'
import CanvasDrawer from './mixins/canvas-drawer'
import include from './decorators/include'
import element from './decorators/element'
Expand Down Expand Up @@ -83,10 +82,7 @@ class MinimapElement {
* @access private
*/
this.minimap = undefined
/**
* @access private
*/
this.editorElement = undefined

/**
* @access private
*/
Expand Down Expand Up @@ -181,11 +177,6 @@ class MinimapElement {
*/
this.quickSettingsElement = undefined

/**
* This MinimapElement's DOMStylesReader
*/
this.DOMStylesReader = new DOMStylesReader()

// States

/**
Expand Down Expand Up @@ -379,10 +370,10 @@ class MinimapElement {
this.measureHeightAndWidth()
this.updateMinimapFlexPosition()
this.attached = true
this.attachedToTextEditor = this.queryParentSelector('atom-text-editor') === this.getTextEditorElement()
this.attachedToTextEditor = this.queryParentSelector('atom-text-editor') === this.minimap.getTextEditorElement()

if (this.attachedToTextEditor) {
this.getTextEditorElement().setAttribute('with-minimap', '')
this.minimap.getTextEditorElement().setAttribute('with-minimap', '')
}

this.subscriptions.add(
Expand All @@ -408,7 +399,7 @@ class MinimapElement {
* @access private
*/
detachedCallback () {
this.getTextEditorElement().removeAttribute('with-minimap')
this.minimap.getTextEditorElement().removeAttribute('with-minimap')
this.attached = false
}

Expand Down Expand Up @@ -442,7 +433,7 @@ class MinimapElement {
attach (parent) {
if (this.attached) { return }

const container = parent || this.getTextEditorElement()
const container = parent || this.minimap.getTextEditorElement()
const minimaps = container.querySelectorAll('atom-text-editor-minimap')
if (minimaps.length) {
Array.prototype.forEach.call(minimaps, (el) => { el.destroy() })
Expand Down Expand Up @@ -666,25 +657,6 @@ class MinimapElement {
delete this.openQuickSettings
}

/**
* Returns the target `TextEditor` of the Minimap.
*
* @return {TextEditor} the minimap's text editor
*/
getTextEditor () { return this.minimap.getTextEditor() }

/**
* Returns the `TextEditorElement` for the Minimap's `TextEditor`.
*
* @return {TextEditorElement} the minimap's text editor element
*/
getTextEditorElement () {
if (this.editorElement) { return this.editorElement }

this.editorElement = atom.views.getView(this.getTextEditor())
return this.editorElement
}

// ## ## ####### ######## ######## ##
// ### ### ## ## ## ## ## ##
// #### #### ## ## ## ## ## ##
Expand Down Expand Up @@ -1088,7 +1060,7 @@ class MinimapElement {
const row = Math.floor(deltaY / this.minimap.getLineHeight()) + this.minimap.getFirstVisibleScreenRow()

const textEditor = this.minimap.getTextEditor()
const textEditorElement = this.getTextEditorElement()
const textEditorElement = this.minimap.getTextEditorElement()

const scrollTop = row * textEditor.getLineHeightInPixels() - this.minimap.getTextEditorHeight() / 2
const textEditorScrollTop = textEditorElement.pixelPositionForScreenPosition([row, 0]).top - this.minimap.getTextEditorHeight() / 2
Expand Down
19 changes: 19 additions & 0 deletions lib/minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export default class Minimap {
* @access private
*/
this.textEditor = options.textEditor

/**
* The Minimap's text editor element.
* @access private
*/
this.editorElement = undefined

/**
* The stand-alone state of the current Minimap.
*
Expand Down Expand Up @@ -525,6 +532,18 @@ export default class Minimap {
*/
getTextEditor () { return this.textEditor }

/**
* Returns the `TextEditorElement` for the Minimap's `TextEditor`.
*
* @return {TextEditorElement} the minimap's text editor element
*/
getTextEditorElement () {
if (this.editorElement) { return this.editorElement }

this.editorElement = atom.views.getView(this.getTextEditor())
return this.editorElement
}

/**
* Returns the height of the `TextEditor` at the Minimap scale.
*
Expand Down
Loading