Skip to content

Commit

Permalink
fix: make makeTranslate a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 29, 2020
1 parent 7c5ab25 commit 9c5dbaf
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ class MinimapElement {
applyStyles(this.visibleArea, {
width: Math.round(visibleWidth) + 'px',
height: Math.round(minimap.getTextEditorScaledHeight()) + 'px',
transform: this.makeTranslate(0, visibleAreaTop),
transform: makeTranslate(0, visibleAreaTop, this.useHardwareAcceleration),
'border-left-width': Math.round(visibleAreaLeft) + 'px'
})
}
Expand All @@ -839,7 +839,7 @@ class MinimapElement {
applyStyles(this.tokensLayer.canvas, { top: canvasTop + 'px' })
applyStyles(this.frontLayer.canvas, { top: canvasTop + 'px' })
} else {
let canvasTransform = this.makeTranslate(0, canvasTop)
let canvasTransform = makeTranslate(0, canvasTop, this.useHardwareAcceleration)
if (devicePixelRatio !== 1) {
canvasTransform += ' ' + this.makeScale(1 / devicePixelRatio)
}
Expand Down Expand Up @@ -871,7 +871,7 @@ class MinimapElement {
} else {
applyStyles(this.scrollIndicator, {
height: indicatorHeight + 'px',
transform: this.makeTranslate(0, indicatorScroll)
transform: makeTranslate(0, indicatorScroll, this.useHardwareAcceleration)
})
}

Expand Down Expand Up @@ -1276,22 +1276,6 @@ class MinimapElement {
// ## ## ## ## ## ##
// ###### ###### ######

/**
* Returns a string with a CSS translation tranform value.
*
* @param {number} [x = 0] the x offset of the translation
* @param {number} [y = 0] the y offset of the translation
* @return {string} the CSS translation string
* @access private
*/
makeTranslate (x = 0, y = 0) {
if (this.useHardwareAcceleration) {
return `translate3d(${x}px, ${y}px, 0)`
} else {
return `translate(${x}px, ${y}px)`
}
}

/**
* Returns a string with a CSS scaling tranform value.
*
Expand Down Expand Up @@ -1377,6 +1361,23 @@ function applyStyles (element, styles) {
element.style.cssText = cssText
}

/**
* Returns a string with a CSS translation tranform value.
*
* @param {number} [x = 0] the x offset of the translation
* @param {number} [y = 0] the y offset of the translation
* @param {boolean} [useHardwareAcceleration = false] use hardware acceleration
* @return {string} the CSS translation string
* @access private
*/
function makeTranslate (x = 0, y = 0, useHardwareAcceleration = false) {
if (useHardwareAcceleration) {
return `translate3d(${x}px, ${y}px, 0)`
} else {
return `translate(${x}px, ${y}px)`
}
}

/**
* A method that return the current time as a Date.
*
Expand Down

0 comments on commit 9c5dbaf

Please sign in to comment.