Skip to content

Commit

Permalink
refactor: drag select
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed Jul 4, 2021
1 parent b01d43c commit 6d893bd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/renderer/components/DragSelect/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
</template>

<script>
const getCoords = (e, containerRect) => ({
x: e.clientX - containerRect.left,
y: e.clientY - containerRect.top
})
const getDimensions = (p1, p2) => ({
width: Math.abs(p1.x - p2.x),
height: Math.abs(p1.y - p2.y)
Expand Down Expand Up @@ -51,12 +56,6 @@
const self = this
let containerRect = container.getBoundingClientRect()
const getCoords = e => ({
x: e.clientX - containerRect.left,
y: e.clientY - containerRect.top
})
const box = this.createBox()
let start = { x: 0, y: 0 }
let end = { x: 0, y: 0 }
Expand All @@ -74,7 +73,7 @@
function startDrag (e) {
containerRect = container.getBoundingClientRect()
self.children = container.childNodes
start = getCoords(e)
start = getCoords(e, containerRect)
end = start
document.addEventListener('mousemove', drag)
document.addEventListener('touchmove', touchMove)
Expand All @@ -87,7 +86,7 @@
}
function drag (e) {
end = getCoords(e)
end = getCoords(e, containerRect)
const dimensions = getDimensions(start, end)
if (end.x < start.x) {
Expand Down

0 comments on commit 6d893bd

Please sign in to comment.