fix contextmenu on mac and linux

This commit is contained in:
nightwing 2012-06-04 16:24:33 +04:00
commit b56f41e9a4
6 changed files with 24 additions and 25 deletions

View file

@ -281,10 +281,12 @@ var TextInput = function(parentNode, host) {
if (host.renderer.$keepTextAreaAtCursor)
host.renderer.$keepTextAreaAtCursor = null;
event.capture(host.container, function(e) {
text.style.left = e.clientX - 2 + "px";
text.style.top = e.clientY - 2 + "px";
}, onContextMenuClose);
// on windows context menu is opened after mouseup
if (useragent.isGecko && useragent.isWin)
event.capture(host.container, function(e) {
text.style.left = e.clientX - 2 + "px";
text.style.top = e.clientY - 2 + "px";
}, onContextMenuClose);
};
function onContextMenuClose() {

View file

@ -93,7 +93,7 @@ exports.preventDefault = function(e) {
exports.getButton = function(e) {
if (e.type == "dblclick")
return 0;
else if (e.type == "contextmenu")
if (e.type == "contextmenu" || (e.ctrlKey && useragent.isMac))
return 2;
// DOM Event

View file

@ -90,7 +90,7 @@ function DefaultHandlers(mouseHandler) {
// 2: contextmenu, 1: linux paste
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

View file

@ -40,6 +40,7 @@ define(function(require, exports, module) {
"use strict";
var event = require("../lib/event");
var useragent = require("../lib/useragent");
/*
* Custom Ace mouse event
@ -130,9 +131,9 @@ var MouseEvent = exports.MouseEvent = function(domEvent, editor) {
return this.domEvent.shiftKey;
};
this.getAccelKey = function() {
return this.domEvent.ctrlKey || this.domEvent.metaKey ;
};
this.getAccelKey = useragent.isMac
? function() { return this.domEvent.metaKey; }
: function() { return this.domEvent.ctrlKey; };
}).call(MouseEvent.prototype);

View file

@ -130,12 +130,12 @@ var MouseHandler = function(editor) {
renderer.$keepTextAreaAtCursor = null;
var self = this;
var onMouseSelection = function(e) {
var onMouseMove = function(e) {
self.x = e.clientX;
self.y = e.clientY;
};
var onMouseSelectionEnd = function(e) {
var onCaptureEnd = function(e) {
clearInterval(timerId);
self[self.state + "End"] && self[self.state + "End"](e);
self.$clickSelection = null;
@ -145,12 +145,12 @@ var MouseHandler = function(editor) {
}
};
var onSelectionInterval = function() {
var onCaptureInterval = function() {
self[self.state] && self[self.state]();
}
event.capture(this.editor.container, onMouseSelection, onMouseSelectionEnd);
var timerId = setInterval(onSelectionInterval, 20);
event.capture(this.editor.container, onMouseMove, onCaptureEnd);
var timerId = setInterval(onCaptureInterval, 20);
};
}).call(MouseHandler.prototype);

View file

@ -53,18 +53,14 @@ function onMouseDown(e) {
var ctrl = e.getAccelKey();
var button = e.getButton();
if (e.editor.inMultiSelectMode && button == 2) {
e.editor.textInput.onContextMenu(e.domEvent);
return;
}
if (!ctrl && !alt) {
if (e.editor.inMultiSelectMode) {
if (button == 0) {
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();
}
}
if (button == 0 && e.editor.inMultiSelectMode)
e.editor.exitMultiSelectMode();
return;
}