Added checks to mousemove handler to not commit all mouse movements (#27818)

This commit is contained in:
Catherine Liu 2018-12-28 13:55:27 -07:00 committed by GitHub
parent 3d96469ab1
commit 30ab2e307e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,9 +38,25 @@ const setupHandler = (commit, target) => {
return;
}
const canvasOrigin = canvasPage.getBoundingClientRect();
window.onmousemove = ({ clientX, clientY, altKey, metaKey, shiftKey, ctrlKey }) => {
window.onmousemove = ({
target,
buttons,
clientX,
clientY,
altKey,
metaKey,
shiftKey,
ctrlKey,
}) => {
const { x, y } = localMousePosition(canvasOrigin, clientX, clientY);
commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey });
// only commits the cursor position if the target is a nested element of canvasPage
// or if left button is being held down (i.e. an element is being dragged)
if (buttons === 1 || ancestorElement(target)) {
commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey });
} else {
// clears cursorPosition
commit('cursorPosition', {});
}
};
window.onmouseup = e => {
e.stopPropagation();
@ -79,8 +95,8 @@ const handleWheel = (
const handleMouseDown = (commit, e, isEditable) => {
e.stopPropagation();
const { target, clientX, clientY, button, altKey, metaKey, shiftKey, ctrlKey } = e;
if (button !== 0 || !isEditable) {
const { target, clientX, clientY, buttons, altKey, metaKey, shiftKey, ctrlKey } = e;
if (buttons !== 1 || !isEditable) {
resetHandler();
return; // left-click and edit mode only
}