Skip to content

Commit

Permalink
Merge pull request ondras#60 from xyb/click
Browse files Browse the repository at this point in the history
mouse: fix single right click recognized as wheelzoom when using Macbook and Chrome
  • Loading branch information
ondras committed Mar 13, 2016
2 parents 9957e26 + e16bef5 commit f6c83db
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
42 changes: 28 additions & 14 deletions my-mind.js
Original file line number Diff line number Diff line change
Expand Up @@ -4783,12 +4783,12 @@ MM.Mouse.handleEvent = function(e) {
if (MM.App.editing && item == MM.App.current) { return; } /* ignore on edited node */
if (item) { MM.App.select(item); }
break;

case "dblclick":
var item = MM.App.map.getItemFor(e.target);
if (item) { MM.Command.Edit.execute(); }
break;

case "contextmenu":
this._endDrag();
e.preventDefault();
Expand All @@ -4811,17 +4811,17 @@ MM.Mouse.handleEvent = function(e) {
}

if (e.type == "mousedown") { e.preventDefault(); } /* to prevent blurring the clipboard node */

if (e.type == "touchstart") { /* context menu here, after we have the item */
this._touchTimeout = setTimeout(function() {
this._touchTimeout = setTimeout(function() {
item && MM.App.select(item);
MM.Menu.open(e.clientX, e.clientY);
}, this.TOUCH_DELAY);
}

this._startDrag(e, item);
break;

case "touchmove":
if (e.touches.length > 1) { return; }
e.clientX = e.touches[0].clientX;
Expand All @@ -4830,7 +4830,7 @@ MM.Mouse.handleEvent = function(e) {
case "mousemove":
this._processDrag(e);
break;

case "touchend":
clearTimeout(this._touchTimeout);
case "mouseup":
Expand All @@ -4839,10 +4839,24 @@ MM.Mouse.handleEvent = function(e) {

case "wheel":
case "mousewheel":
var dir = 1;
if (e.wheelDelta && e.wheelDelta < 0) { dir = -1; }
if (e.deltaY && e.deltaY > 0) { dir = -1; }
MM.App.adjustFontSize(dir);
var dir = 0;
if (e.wheelDelta) {
if (e.wheelDelta < 0) {
dir = -1;
} else if (e.wheelDelta > 0) {
dir = 1;
}
}
if (e.deltaY) {
if (e.deltaY > 0) {
dir = -1;
} else if (e.deltaY < 0) {
dir = 1;
}
}
if (dir) {
MM.App.adjustFontSize(dir);
}
break;
}
}
Expand All @@ -4861,7 +4875,7 @@ MM.Mouse._startDrag = function(e, item) {
this._cursor[0] = e.clientX;
this._cursor[1] = e.clientY;

if (item && !item.isRoot()) {
if (item && !item.isRoot()) {
this._mode = "drag";
this._item = item;
} else {
Expand All @@ -4879,9 +4893,9 @@ MM.Mouse._processDrag = function(e) {

switch (this._mode) {
case "drag":
if (!this._ghost) {
if (!this._ghost) {
this._port.style.cursor = "move";
this._buildGhost(dx, dy);
this._buildGhost(dx, dy);
}
this._moveGhost(dx, dy);
var state = this._computeDragState();
Expand Down Expand Up @@ -4972,7 +4986,7 @@ MM.Mouse._computeDragState = function() {
if (tmp == this._item) { return state; } /* drop on a child or self */
tmp = tmp.getParent();
}

var w1 = this._item.getDOM().content.offsetWidth;
var w2 = target.getDOM().content.offsetWidth;
var w = Math.max(w1, w2);
Expand Down
42 changes: 28 additions & 14 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ MM.Mouse.handleEvent = function(e) {
if (MM.App.editing && item == MM.App.current) { return; } /* ignore on edited node */
if (item) { MM.App.select(item); }
break;

case "dblclick":
var item = MM.App.map.getItemFor(e.target);
if (item) { MM.Command.Edit.execute(); }
break;

case "contextmenu":
this._endDrag();
e.preventDefault();
Expand All @@ -56,17 +56,17 @@ MM.Mouse.handleEvent = function(e) {
}

if (e.type == "mousedown") { e.preventDefault(); } /* to prevent blurring the clipboard node */

if (e.type == "touchstart") { /* context menu here, after we have the item */
this._touchTimeout = setTimeout(function() {
this._touchTimeout = setTimeout(function() {
item && MM.App.select(item);
MM.Menu.open(e.clientX, e.clientY);
}, this.TOUCH_DELAY);
}

this._startDrag(e, item);
break;

case "touchmove":
if (e.touches.length > 1) { return; }
e.clientX = e.touches[0].clientX;
Expand All @@ -75,7 +75,7 @@ MM.Mouse.handleEvent = function(e) {
case "mousemove":
this._processDrag(e);
break;

case "touchend":
clearTimeout(this._touchTimeout);
case "mouseup":
Expand All @@ -84,10 +84,24 @@ MM.Mouse.handleEvent = function(e) {

case "wheel":
case "mousewheel":
var dir = 1;
if (e.wheelDelta && e.wheelDelta < 0) { dir = -1; }
if (e.deltaY && e.deltaY > 0) { dir = -1; }
MM.App.adjustFontSize(dir);
var dir = 0;
if (e.wheelDelta) {
if (e.wheelDelta < 0) {
dir = -1;
} else if (e.wheelDelta > 0) {
dir = 1;
}
}
if (e.deltaY) {
if (e.deltaY > 0) {
dir = -1;
} else if (e.deltaY < 0) {
dir = 1;
}
}
if (dir) {
MM.App.adjustFontSize(dir);
}
break;
}
}
Expand All @@ -106,7 +120,7 @@ MM.Mouse._startDrag = function(e, item) {
this._cursor[0] = e.clientX;
this._cursor[1] = e.clientY;

if (item && !item.isRoot()) {
if (item && !item.isRoot()) {
this._mode = "drag";
this._item = item;
} else {
Expand All @@ -124,9 +138,9 @@ MM.Mouse._processDrag = function(e) {

switch (this._mode) {
case "drag":
if (!this._ghost) {
if (!this._ghost) {
this._port.style.cursor = "move";
this._buildGhost(dx, dy);
this._buildGhost(dx, dy);
}
this._moveGhost(dx, dy);
var state = this._computeDragState();
Expand Down Expand Up @@ -217,7 +231,7 @@ MM.Mouse._computeDragState = function() {
if (tmp == this._item) { return state; } /* drop on a child or self */
tmp = tmp.getParent();
}

var w1 = this._item.getDOM().content.offsetWidth;
var w2 = target.getDOM().content.offsetWidth;
var w = Math.max(w1, w2);
Expand Down

0 comments on commit f6c83db

Please sign in to comment.