Skip to content

Commit

Permalink
fix: make extractMouseEventData a free function
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Dec 29, 2020
1 parent 474b4c1 commit 31ca2e4
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions lib/minimap-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class MinimapElement {
this.subscribeTo(
this.getFrontCanvas(),
{
mousedown: (e) => { this.canvasPressed(this.extractMouseEventData(e)) },
mousedown: (e) => { this.canvasPressed(extractMouseEventData(e)) },
touchstart: (e) => { this.canvasPressed(this.extractTouchEventData(e)) }
},
{ passive: true }
Expand All @@ -532,7 +532,7 @@ class MinimapElement {
this.visibleArea.classList.add('minimap-visible-area')
this.appendChild(this.visibleArea)
this.visibleAreaSubscription = this.subscribeTo(this.visibleArea, {
mousedown: (e) => { this.startDrag(this.extractMouseEventData(e)) },
mousedown: (e) => { this.startDrag(extractMouseEventData(e)) },
touchstart: (e) => { this.startDrag(this.extractTouchEventData(e)) }
}, { passive: true })

Expand Down Expand Up @@ -1139,25 +1139,6 @@ class MinimapElement {
this.minimap.setTextEditorScrollTop(ratio * this.minimap.getTextEditorMaxScrollTop())
}

/**
* A method that extracts data from a `MouseEvent` which can then be used to
* process clicks and drags of the minimap.
*
* Used together with `extractTouchEventData` to provide a unified interface
* for `MouseEvent`s and `TouchEvent`s.
*
* @param {MouseEvent} mouseEvent the mouse event object
* @access private
*/
extractMouseEventData (mouseEvent) {
return {
x: mouseEvent.pageX,
y: mouseEvent.pageY,
isLeftMouse: mouseEvent.which === 1,
isMiddleMouse: mouseEvent.which === 2
}
}

/**
* A method that extracts data from a `TouchEvent` which can then be used to
* process clicks and drags of the minimap.
Expand Down Expand Up @@ -1227,7 +1208,7 @@ class MinimapElement {

const initial = { dragOffset, offsetTop }

const mousemoveHandler = (e) => this.drag(this.extractMouseEventData(e), initial)
const mousemoveHandler = (e) => this.drag(extractMouseEventData(e), initial)
const mouseupHandler = (e) => this.endDrag()

const touchmoveHandler = (e) => this.drag(this.extractTouchEventData(e), initial)
Expand Down Expand Up @@ -1288,6 +1269,33 @@ class MinimapElement {
const minimapElement = MinimapElement.initClass()
export default minimapElement

// ######## ## ## ######## ## ## ######## ######
// ## ## ## ## ### ## ## ## ##
// ## ## ## ## #### ## ## ##
// ###### ## ## ###### ## ## ## ## ######
// ## ## ## ## ## #### ## ##
// ## ## ## ## ## ### ## ## ##
// ######## ### ######## ## ## ## ######

/**
* A method that extracts data from a `MouseEvent` which can then be used to
* process clicks and drags of the minimap.
*
* Used together with `extractTouchEventData` to provide a unified interface
* for `MouseEvent`s and `TouchEvent`s.
*
* @param {MouseEvent} mouseEvent the mouse event object
* @access private
*/
function extractMouseEventData (mouseEvent) {
return {
x: mouseEvent.pageX,
y: mouseEvent.pageY,
isLeftMouse: mouseEvent.which === 1,
isMiddleMouse: mouseEvent.which === 2
}
}

// ###### ###### ######
// ## ## ## ## ## ##
// ## ## ##
Expand Down

0 comments on commit 31ca2e4

Please sign in to comment.