fix contextmenu on mac and linux
This commit is contained in:
parent
11eba737d1
commit
b56f41e9a4
6 changed files with 24 additions and 25 deletions
|
|
@ -281,6 +281,8 @@ var TextInput = function(parentNode, host) {
|
||||||
if (host.renderer.$keepTextAreaAtCursor)
|
if (host.renderer.$keepTextAreaAtCursor)
|
||||||
host.renderer.$keepTextAreaAtCursor = null;
|
host.renderer.$keepTextAreaAtCursor = null;
|
||||||
|
|
||||||
|
// on windows context menu is opened after mouseup
|
||||||
|
if (useragent.isGecko && useragent.isWin)
|
||||||
event.capture(host.container, function(e) {
|
event.capture(host.container, function(e) {
|
||||||
text.style.left = e.clientX - 2 + "px";
|
text.style.left = e.clientX - 2 + "px";
|
||||||
text.style.top = e.clientY - 2 + "px";
|
text.style.top = e.clientY - 2 + "px";
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ exports.preventDefault = function(e) {
|
||||||
exports.getButton = function(e) {
|
exports.getButton = function(e) {
|
||||||
if (e.type == "dblclick")
|
if (e.type == "dblclick")
|
||||||
return 0;
|
return 0;
|
||||||
else if (e.type == "contextmenu")
|
if (e.type == "contextmenu" || (e.ctrlKey && useragent.isMac))
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
// DOM Event
|
// DOM Event
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ function DefaultHandlers(mouseHandler) {
|
||||||
|
|
||||||
// 2: contextmenu, 1: linux paste
|
// 2: contextmenu, 1: linux paste
|
||||||
editor.textInput.onContextMenu(ev.domEvent);
|
editor.textInput.onContextMenu(ev.domEvent);
|
||||||
return ev.stop();
|
return; // stopping event here breaks contextmenu on ff mac
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this click caused the editor to be focused should not clear the
|
// if this click caused the editor to be focused should not clear the
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var event = require("../lib/event");
|
var event = require("../lib/event");
|
||||||
|
var useragent = require("../lib/useragent");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom Ace mouse event
|
* Custom Ace mouse event
|
||||||
|
|
@ -130,9 +131,9 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
|
||||||
return this.domEvent.shiftKey;
|
return this.domEvent.shiftKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getAccelKey = function() {
|
this.getAccelKey = useragent.isMac
|
||||||
return this.domEvent.ctrlKey || this.domEvent.metaKey ;
|
? function() { return this.domEvent.metaKey; }
|
||||||
};
|
: function() { return this.domEvent.ctrlKey; };
|
||||||
|
|
||||||
}).call(MouseEvent.prototype);
|
}).call(MouseEvent.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,12 +130,12 @@ var MouseHandler = function(editor) {
|
||||||
renderer.$keepTextAreaAtCursor = null;
|
renderer.$keepTextAreaAtCursor = null;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var onMouseSelection = function(e) {
|
var onMouseMove = function(e) {
|
||||||
self.x = e.clientX;
|
self.x = e.clientX;
|
||||||
self.y = e.clientY;
|
self.y = e.clientY;
|
||||||
};
|
};
|
||||||
|
|
||||||
var onMouseSelectionEnd = function(e) {
|
var onCaptureEnd = function(e) {
|
||||||
clearInterval(timerId);
|
clearInterval(timerId);
|
||||||
self[self.state + "End"] && self[self.state + "End"](e);
|
self[self.state + "End"] && self[self.state + "End"](e);
|
||||||
self.$clickSelection = null;
|
self.$clickSelection = null;
|
||||||
|
|
@ -145,12 +145,12 @@ var MouseHandler = function(editor) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var onSelectionInterval = function() {
|
var onCaptureInterval = function() {
|
||||||
self[self.state] && self[self.state]();
|
self[self.state] && self[self.state]();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.capture(this.editor.container, onMouseSelection, onMouseSelectionEnd);
|
event.capture(this.editor.container, onMouseMove, onCaptureEnd);
|
||||||
var timerId = setInterval(onSelectionInterval, 20);
|
var timerId = setInterval(onCaptureInterval, 20);
|
||||||
};
|
};
|
||||||
}).call(MouseHandler.prototype);
|
}).call(MouseHandler.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,18 +53,14 @@ function onMouseDown(e) {
|
||||||
var ctrl = e.getAccelKey();
|
var ctrl = e.getAccelKey();
|
||||||
var button = e.getButton();
|
var button = e.getButton();
|
||||||
|
|
||||||
|
if (e.editor.inMultiSelectMode && button == 2) {
|
||||||
|
e.editor.textInput.onContextMenu(e.domEvent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ctrl && !alt) {
|
if (!ctrl && !alt) {
|
||||||
if (e.editor.inMultiSelectMode) {
|
if (button == 0 && e.editor.inMultiSelectMode)
|
||||||
if (button == 0) {
|
|
||||||
e.editor.exitMultiSelectMode();
|
e.editor.exitMultiSelectMode();
|
||||||
} else if (button == 2) {
|
|
||||||
var editor = e.editor;
|
|
||||||
var selectionEmpty = editor.selection.isEmpty();
|
|
||||||
editor.textInput.onContextMenu({x: e.clientX, y: e.clientY}, selectionEmpty);
|
|
||||||
event.capture(editor.container, function(){}, editor.textInput.onContextMenuClose);
|
|
||||||
e.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue