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) if (host.renderer.$keepTextAreaAtCursor)
host.renderer.$keepTextAreaAtCursor = null; host.renderer.$keepTextAreaAtCursor = null;
event.capture(host.container, function(e) { // on windows context menu is opened after mouseup
text.style.left = e.clientX - 2 + "px"; if (useragent.isGecko && useragent.isWin)
text.style.top = e.clientY - 2 + "px"; event.capture(host.container, function(e) {
}, onContextMenuClose); text.style.left = e.clientX - 2 + "px";
text.style.top = e.clientY - 2 + "px";
}, onContextMenuClose);
}; };
function onContextMenuClose() { function onContextMenuClose() {

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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;
} }