diff --git a/src/Selection.js b/src/Selection.js index 2adbc0a73..63592a145 100644 --- a/src/Selection.js +++ b/src/Selection.js @@ -12,6 +12,8 @@ function isOverContainer(container, x, y){ return !container || contains(container, document.elementFromPoint(x, y)) } +const clickTolerance = 5; + class Selection { constructor(node, global = false){ @@ -120,15 +122,9 @@ class Selection { if (!this._mouseDownData) return; - let clickTolerance = 5; - - var { x, y } = this._mouseDownData; var inRoot = !this.container || contains(this.container(), e.target); var bounds = this._selectRect; - var click = ( - Math.abs(e.pageX - x) <= clickTolerance && - Math.abs(e.pageY - y) <= clickTolerance - ); + var click = this.isClick(e.pageX, e.pageY); this._mouseDownData = null @@ -161,19 +157,28 @@ class Selection { this.emit('selectStart', this._mouseDownData) } - this.emit('selecting', this._selectRect = { - top, - left, - x: e.pageX, - y: e.pageY, - right: left + w, - bottom: top + h - }); + if (!this.isClick(e.pageX, e.pageY)) + this.emit('selecting', this._selectRect = { + top, + left, + x: e.pageX, + y: e.pageY, + right: left + w, + bottom: top + h + }); } _keyListener(e) { this.ctrl = (e.metaKey || e.ctrlKey) } + + isClick(pageX, pageY){ + var { x, y } = this._mouseDownData; + return ( + Math.abs(pageX - x) <= clickTolerance && + Math.abs(pageY - y) <= clickTolerance + ); + } } /** diff --git a/src/utils/dates.js b/src/utils/dates.js index 4a5c94275..cc8ed1c51 100644 --- a/src/utils/dates.js +++ b/src/utils/dates.js @@ -45,6 +45,12 @@ let dates = Object.assign(dateMath, { return days }, + ceil(date, unit){ + let floor = dates.startOf(date, unit) + + return dates.eq(floor, date) ? floor : dates.add(floor, 1, unit) + }, + move(date, min, max, unit, direction){ let isUpOrDown = direction === directions.UP || direction === directions.DOWN , addUnit = isUpOrDown ? 'week' : 'day' diff --git a/src/utils/eventLevels.js b/src/utils/eventLevels.js index 2f8db98c8..ff28516fd 100644 --- a/src/utils/eventLevels.js +++ b/src/utils/eventLevels.js @@ -4,7 +4,7 @@ import { accessor as get } from './accessors'; export function eventSegments(event, first, last, { startAccessor, endAccessor, culture }){ let slots = dates.diff(first, last, 'day') let start = dates.max(get(event, startAccessor), first); - let end = dates.min(get(event, endAccessor), dates.add(last, 1, 'day')) + let end = dates.min(dates.ceil(get(event, endAccessor), 'day'), dates.add(last, 1, 'day')) let span = dates.diff(start, end, 'day');