Skip to content
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

fix: make CanvasDrawer a normal class #744

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
101d001
fix: convert CanvasDrawer to a normal class
aminya Jan 2, 2021
bd52649
fix: use minimap methods in CanvasDrawer
aminya Jan 2, 2021
ec7015b
fix: move this.displayCodeHighlights to CanvasDrawer
aminya Jan 2, 2021
b8d899a
fix: move ignoreWhitespacesInTokens to CanvasDrawer
aminya Jan 2, 2021
d2e2963
fix: set the initial value of the config values
aminya Jan 12, 2021
a6b39b5
test: use CanvasDrawer.DOMStylesReader
aminya Jan 12, 2021
93b6a29
test: use CanvasDrawer.drawLineDecoration
aminya Jan 12, 2021
f7659e6
test: use CanvasDrawer.drawHighlightDecoration
aminya Jan 12, 2021
5b4e5e9
test: use CanvasDrawer.drawHighlightOutlineDecoration
aminya Jan 12, 2021
3affc42
test: use CanvasDrawer.drawCustomDecoration
aminya Jan 12, 2021
06fef22
test: use CanvasDrawer.drawLines
aminya Jan 12, 2021
40d3bc3
test: use empty function
aminya Jan 12, 2021
f6c7460
Merge branch 'master' into canvas-drawer
aminya Apr 1, 2021
9362232
Merge branch 'master' into canvas-drawer
aminya Apr 1, 2021
29a7bf6
fix: get DecorationManagement through minimap
aminya Apr 1, 2021
a7c1b44
Merge branch 'master' into canvas-drawer
aminya Apr 2, 2021
5f838dd
fix: set CanvasDrawer textOpacity
aminya Apr 2, 2021
b5fc41e
fix: use minimap.getDecorationManagement
aminya Apr 2, 2021
9d5c203
test: spy on CanvasDrawer.drawHighlightOutlineDecoration
aminya Apr 2, 2021
5fee0cf
chore: add note about test only code [skip ci]
aminya Apr 2, 2021
d3177d6
Merge branch 'master' into canvas-drawer
aminya Apr 6, 2021
90a6da9
fix: add missing uninitialized properties to minimap-element
aminya Apr 6, 2021
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
63 changes: 35 additions & 28 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SPEC_MODE = atom.inSpecMode()
*/
class MinimapElement {
static initClass() {
include(this, CanvasDrawer, EventsDelegation, AncestorsMethods)
include(this, EventsDelegation, AncestorsMethods)
return element(this, "atom-text-editor-minimap")
}

Expand Down Expand Up @@ -146,6 +146,11 @@ class MinimapElement {
*/
this.quickSettingsElement = undefined

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

this.DecorationManagement = new DecorationManagement()

// States
Expand Down Expand Up @@ -221,15 +226,15 @@ class MinimapElement {
}),

atom.config.observe("minimap.textOpacity", (textOpacity) => {
this.textOpacity = textOpacity
this.CanvasDrawer.textOpacity = textOpacity

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

atom.config.observe("minimap.displayCodeHighlights", (displayCodeHighlights) => {
this.displayCodeHighlights = displayCodeHighlights
this.CanvasDrawer.displayCodeHighlights = displayCodeHighlights

if (this.attached) {
this.requestForcedUpdate()
Expand All @@ -241,9 +246,9 @@ class MinimapElement {

if (this.attached) {
if (!this.smoothScrolling) {
this.backLayer.canvas.style.cssText = ""
this.tokensLayer.canvas.style.cssText = ""
this.frontLayer.canvas.style.cssText = ""
this.CanvasDrawer.backLayer.canvas.style.cssText = ""
this.CanvasDrawer.tokensLayer.canvas.style.cssText = ""
this.CanvasDrawer.frontLayer.canvas.style.cssText = ""
} else {
this.requestUpdate()
}
Expand Down Expand Up @@ -291,7 +296,7 @@ class MinimapElement {
}),

atom.config.observe("minimap.ignoreWhitespacesInTokens", (ignoreWhitespacesInTokens) => {
this.ignoreWhitespacesInTokens = ignoreWhitespacesInTokens
this.CanvasDrawer.ignoreWhitespacesInTokens = ignoreWhitespacesInTokens

if (this.attached) {
this.requestForcedUpdate()
Expand Down Expand Up @@ -493,9 +498,9 @@ class MinimapElement {
* @access private
*/
initializeContent() {
this.initializeCanvas()
this.CanvasDrawer.initializeCanvas()

this.attachCanvases(this)
this.CanvasDrawer.attachCanvases(this)

this.createVisibleArea()
this.createControls()
Expand All @@ -514,7 +519,7 @@ class MinimapElement {
),

this.subscribeTo(
this.getFrontCanvas(),
this.CanvasDrawer.getFrontCanvas(),
{
mousedown: (e) => {
this.canvasPressed(extractMouseEventData(e))
Expand Down Expand Up @@ -663,7 +668,7 @@ class MinimapElement {
this.quickSettingsElement = null
})

const { top, left, right } = this.getFrontCanvas().getBoundingClientRect()
const { top, left, right } = this.CanvasDrawer.getFrontCanvas().getBoundingClientRect()
this.quickSettingsElement.style.top = `${top}px`
this.quickSettingsElement.attach()

Expand Down Expand Up @@ -726,6 +731,8 @@ class MinimapElement {
*/
setModel(minimap) {
this.minimap = minimap
// TODO: go direct
this.CanvasDrawer.minimap = minimap

// set minimapElement for Minimap
this.minimap.minimapElement = this
Expand Down Expand Up @@ -757,16 +764,16 @@ class MinimapElement {
}),

this.minimap.onDidChange((change) => {
this.pendingChanges.push(change)
this.CanvasDrawer.pendingChanges.push(change)
this.requestUpdate()
}),

this.DecorationManagement.onDidChangeDecorationRange((change) => {
const { type } = change
if (type === "line" || type === "highlight-under" || type === "background-custom") {
this.pendingBackDecorationChanges.push(change)
this.CanvasDrawer.pendingBackDecorationChanges.push(change)
} else {
this.pendingFrontDecorationChanges.push(change)
this.CanvasDrawer.pendingFrontDecorationChanges.push(change)
}
this.requestUpdate()
}),
Expand Down Expand Up @@ -856,7 +863,7 @@ class MinimapElement {
}
const minimap = this.minimap
minimap.enableCache()
const canvas = this.getFrontCanvas()
const canvas = this.CanvasDrawer.getFrontCanvas()

const devicePixelRatio = this.minimap.getDevicePixelRatio()
const visibleAreaLeft = minimap.getTextEditorScaledScrollLeft()
Expand Down Expand Up @@ -894,25 +901,25 @@ class MinimapElement {

if (this.smoothScrolling) {
if (SPEC_MODE) {
applyStyles(this.backLayer.canvas, { top: `${canvasTop}px` })
applyStyles(this.tokensLayer.canvas, { top: `${canvasTop}px` })
applyStyles(this.frontLayer.canvas, { top: `${canvasTop}px` })
applyStyles(this.CanvasDrawer.backLayer.canvas, { top: `${canvasTop}px` })
applyStyles(this.CanvasDrawer.tokensLayer.canvas, { top: `${canvasTop}px` })
applyStyles(this.CanvasDrawer.frontLayer.canvas, { top: `${canvasTop}px` })
} else {
let canvasTransform = makeTranslate(0, canvasTop, this.useHardwareAcceleration)
if (devicePixelRatio !== 1) {
const scale = 1 / devicePixelRatio
canvasTransform += ` ${makeScale(scale, scale, this.useHardwareAcceleration)}`
}
applyStyles(this.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.frontLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.frontLayer.canvas, { transform: canvasTransform })
}
} else {
const scale = 1 / devicePixelRatio
const canvasTransform = makeScale(scale, scale, this.useHardwareAcceleration)
applyStyles(this.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.frontLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.backLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.tokensLayer.canvas, { transform: canvasTransform })
applyStyles(this.CanvasDrawer.frontLayer.canvas, { transform: canvasTransform })
}

if (this.minimapScrollIndicator && !this.scrollIndicator && minimap.canScroll()) {
Expand Down Expand Up @@ -945,7 +952,7 @@ class MinimapElement {
this.updateCanvasesSize()
}

this.updateCanvas()
this.CanvasDrawer.updateCanvas()
minimap.clearCache()
}

Expand All @@ -956,7 +963,7 @@ class MinimapElement {
* highlights or not
*/
setDisplayCodeHighlights(displayCodeHighlights) {
this.displayCodeHighlights = displayCodeHighlights
this.CanvasDrawer.displayCodeHighlights = displayCodeHighlights
if (this.attached) {
this.requestForcedUpdate()
}
Expand Down Expand Up @@ -1076,14 +1083,14 @@ class MinimapElement {
this.absoluteMode && this.adjustAbsoluteModeHeight
? Math.min(this.minimap.getHeight(), maxCanvasHeight)
: maxCanvasHeight
const canvas = this.getFrontCanvas()
const canvas = this.CanvasDrawer.getFrontCanvas()

if (canvasWidth == null) {
canvasWidth = canvas.width / devicePixelRatio
}

if (canvasWidth !== canvas.width || newHeight !== canvas.height) {
this.setCanvasesSize(canvasWidth * devicePixelRatio, newHeight * devicePixelRatio)
this.CanvasDrawer.setCanvasesSize(canvasWidth * devicePixelRatio, newHeight * devicePixelRatio)
if (this.absoluteMode && this.adjustAbsoluteModeHeight) {
this.offscreenFirstRow = null
this.offscreenLastRow = null
Expand Down
20 changes: 14 additions & 6 deletions lib/mixins/canvas-drawer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict"

import { escapeRegExp } from "../deps/underscore-plus"
import Mixin from "mixto"

import * as Main from "../main"
import { domStylesReader } from "../main"
Expand All @@ -18,16 +17,25 @@ let thisSpec
* This mixin is injected in the `MinimapElement` prototype, so all these
* methods are available on any `MinimapElement` instance.
*/
export default class CanvasDrawer extends Mixin {
export default class CanvasDrawer {
constructor() {
// set in setModel of minimapElement
this.minimap = undefined

// set by minimapElement
this.displayCodeHighlights = atom.config.get("minimap.displayCodeHighlights")
this.ignoreWhitespacesInTokens = atom.config.get("minimap.ignoreWhitespacesInTokens")
this.textOpacity = atom.config.get("minimap.textOpacity")
}

/**
* Initializes the canvas elements needed to perform the `Minimap` rendering.
*/
initializeCanvas() {
// NOTE "Test Only Code": this code is removed in production code
if (SPEC_MODE) {
// class methods only used for spying the calls
this.drawLines = (firstLine, lastLine) => {
console.log({ firstLine, lastLine })
}
this.drawLines = (firstLine, lastLine) => firstLine + lastLine
this.drawLineDecoration = drawLineDecoration
this.drawGutterDecoration = drawGutterDecoration
this.drawHighlightDecoration = drawHighlightDecoration
Expand Down Expand Up @@ -163,7 +171,7 @@ export default class CanvasDrawer extends Mixin {
this.drawLines(firstRow, lastRow)
}

const decorations = this.DecorationManagement.decorationsByTypeThenRows(firstRow, lastRow)
const decorations = this.minimap.getDecorationManagement().decorationsByTypeThenRows(firstRow, lastRow)

const renderData = {
context: this.backLayer.context,
Expand Down
Loading