Skip to content

Commit e16bef5

Browse files
committed
mouse: fix single right click recognized as wheelzoom when using Macbook and Chrome
When right click with two fingers using Macbook's trackpad in Google Chrome browser, expect context menu but map zoomed in also.
1 parent 9957e26 commit e16bef5

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

my-mind.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -4783,12 +4783,12 @@ MM.Mouse.handleEvent = function(e) {
47834783
if (MM.App.editing && item == MM.App.current) { return; } /* ignore on edited node */
47844784
if (item) { MM.App.select(item); }
47854785
break;
4786-
4786+
47874787
case "dblclick":
47884788
var item = MM.App.map.getItemFor(e.target);
47894789
if (item) { MM.Command.Edit.execute(); }
47904790
break;
4791-
4791+
47924792
case "contextmenu":
47934793
this._endDrag();
47944794
e.preventDefault();
@@ -4811,17 +4811,17 @@ MM.Mouse.handleEvent = function(e) {
48114811
}
48124812

48134813
if (e.type == "mousedown") { e.preventDefault(); } /* to prevent blurring the clipboard node */
4814-
4814+
48154815
if (e.type == "touchstart") { /* context menu here, after we have the item */
4816-
this._touchTimeout = setTimeout(function() {
4816+
this._touchTimeout = setTimeout(function() {
48174817
item && MM.App.select(item);
48184818
MM.Menu.open(e.clientX, e.clientY);
48194819
}, this.TOUCH_DELAY);
48204820
}
48214821

48224822
this._startDrag(e, item);
48234823
break;
4824-
4824+
48254825
case "touchmove":
48264826
if (e.touches.length > 1) { return; }
48274827
e.clientX = e.touches[0].clientX;
@@ -4830,7 +4830,7 @@ MM.Mouse.handleEvent = function(e) {
48304830
case "mousemove":
48314831
this._processDrag(e);
48324832
break;
4833-
4833+
48344834
case "touchend":
48354835
clearTimeout(this._touchTimeout);
48364836
case "mouseup":
@@ -4839,10 +4839,24 @@ MM.Mouse.handleEvent = function(e) {
48394839

48404840
case "wheel":
48414841
case "mousewheel":
4842-
var dir = 1;
4843-
if (e.wheelDelta && e.wheelDelta < 0) { dir = -1; }
4844-
if (e.deltaY && e.deltaY > 0) { dir = -1; }
4845-
MM.App.adjustFontSize(dir);
4842+
var dir = 0;
4843+
if (e.wheelDelta) {
4844+
if (e.wheelDelta < 0) {
4845+
dir = -1;
4846+
} else if (e.wheelDelta > 0) {
4847+
dir = 1;
4848+
}
4849+
}
4850+
if (e.deltaY) {
4851+
if (e.deltaY > 0) {
4852+
dir = -1;
4853+
} else if (e.deltaY < 0) {
4854+
dir = 1;
4855+
}
4856+
}
4857+
if (dir) {
4858+
MM.App.adjustFontSize(dir);
4859+
}
48464860
break;
48474861
}
48484862
}
@@ -4861,7 +4875,7 @@ MM.Mouse._startDrag = function(e, item) {
48614875
this._cursor[0] = e.clientX;
48624876
this._cursor[1] = e.clientY;
48634877

4864-
if (item && !item.isRoot()) {
4878+
if (item && !item.isRoot()) {
48654879
this._mode = "drag";
48664880
this._item = item;
48674881
} else {
@@ -4879,9 +4893,9 @@ MM.Mouse._processDrag = function(e) {
48794893

48804894
switch (this._mode) {
48814895
case "drag":
4882-
if (!this._ghost) {
4896+
if (!this._ghost) {
48834897
this._port.style.cursor = "move";
4884-
this._buildGhost(dx, dy);
4898+
this._buildGhost(dx, dy);
48854899
}
48864900
this._moveGhost(dx, dy);
48874901
var state = this._computeDragState();
@@ -4972,7 +4986,7 @@ MM.Mouse._computeDragState = function() {
49724986
if (tmp == this._item) { return state; } /* drop on a child or self */
49734987
tmp = tmp.getParent();
49744988
}
4975-
4989+
49764990
var w1 = this._item.getDOM().content.offsetWidth;
49774991
var w2 = target.getDOM().content.offsetWidth;
49784992
var w = Math.max(w1, w2);

src/mouse.js

+28-14
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ MM.Mouse.handleEvent = function(e) {
2828
if (MM.App.editing && item == MM.App.current) { return; } /* ignore on edited node */
2929
if (item) { MM.App.select(item); }
3030
break;
31-
31+
3232
case "dblclick":
3333
var item = MM.App.map.getItemFor(e.target);
3434
if (item) { MM.Command.Edit.execute(); }
3535
break;
36-
36+
3737
case "contextmenu":
3838
this._endDrag();
3939
e.preventDefault();
@@ -56,17 +56,17 @@ MM.Mouse.handleEvent = function(e) {
5656
}
5757

5858
if (e.type == "mousedown") { e.preventDefault(); } /* to prevent blurring the clipboard node */
59-
59+
6060
if (e.type == "touchstart") { /* context menu here, after we have the item */
61-
this._touchTimeout = setTimeout(function() {
61+
this._touchTimeout = setTimeout(function() {
6262
item && MM.App.select(item);
6363
MM.Menu.open(e.clientX, e.clientY);
6464
}, this.TOUCH_DELAY);
6565
}
6666

6767
this._startDrag(e, item);
6868
break;
69-
69+
7070
case "touchmove":
7171
if (e.touches.length > 1) { return; }
7272
e.clientX = e.touches[0].clientX;
@@ -75,7 +75,7 @@ MM.Mouse.handleEvent = function(e) {
7575
case "mousemove":
7676
this._processDrag(e);
7777
break;
78-
78+
7979
case "touchend":
8080
clearTimeout(this._touchTimeout);
8181
case "mouseup":
@@ -84,10 +84,24 @@ MM.Mouse.handleEvent = function(e) {
8484

8585
case "wheel":
8686
case "mousewheel":
87-
var dir = 1;
88-
if (e.wheelDelta && e.wheelDelta < 0) { dir = -1; }
89-
if (e.deltaY && e.deltaY > 0) { dir = -1; }
90-
MM.App.adjustFontSize(dir);
87+
var dir = 0;
88+
if (e.wheelDelta) {
89+
if (e.wheelDelta < 0) {
90+
dir = -1;
91+
} else if (e.wheelDelta > 0) {
92+
dir = 1;
93+
}
94+
}
95+
if (e.deltaY) {
96+
if (e.deltaY > 0) {
97+
dir = -1;
98+
} else if (e.deltaY < 0) {
99+
dir = 1;
100+
}
101+
}
102+
if (dir) {
103+
MM.App.adjustFontSize(dir);
104+
}
91105
break;
92106
}
93107
}
@@ -106,7 +120,7 @@ MM.Mouse._startDrag = function(e, item) {
106120
this._cursor[0] = e.clientX;
107121
this._cursor[1] = e.clientY;
108122

109-
if (item && !item.isRoot()) {
123+
if (item && !item.isRoot()) {
110124
this._mode = "drag";
111125
this._item = item;
112126
} else {
@@ -124,9 +138,9 @@ MM.Mouse._processDrag = function(e) {
124138

125139
switch (this._mode) {
126140
case "drag":
127-
if (!this._ghost) {
141+
if (!this._ghost) {
128142
this._port.style.cursor = "move";
129-
this._buildGhost(dx, dy);
143+
this._buildGhost(dx, dy);
130144
}
131145
this._moveGhost(dx, dy);
132146
var state = this._computeDragState();
@@ -217,7 +231,7 @@ MM.Mouse._computeDragState = function() {
217231
if (tmp == this._item) { return state; } /* drop on a child or self */
218232
tmp = tmp.getParent();
219233
}
220-
234+
221235
var w1 = this._item.getDOM().content.offsetWidth;
222236
var w2 = target.getDOM().content.offsetWidth;
223237
var w = Math.max(w1, w2);

0 commit comments

Comments
 (0)