From a2d271677f91ccc638f3cdad6bd275664dda11e8 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Wed, 15 Dec 2010 15:40:53 +0100 Subject: [PATCH] some Opera key handling fixes (not perfect yet) --- lib/ace/keybinding.js | 10 ++++++++-- plugins/pilot/core.js | 1 + plugins/pilot/event.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ace/keybinding.js b/lib/ace/keybinding.js index a57c71cc..fecf2463 100644 --- a/lib/ace/keybinding.js +++ b/lib/ace/keybinding.js @@ -49,8 +49,14 @@ var KeyBinding = function(element, editor, config) { var _self = this; event.addKeyListener(element, function(e) { - var hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) - | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0); + // opera on mac swaps ctrl and meta keys + if (core.isOpera && core.isMac) + var hashId = 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) + | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0); + else + var hashId = 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) + | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0); + var key = _self.keyNames[e.keyCode]; var commandName = (_self.config.reverse[hashId] || {})[(key diff --git a/plugins/pilot/core.js b/plugins/pilot/core.js index e0332633..40991657 100644 --- a/plugins/pilot/core.js +++ b/plugins/pilot/core.js @@ -44,6 +44,7 @@ exports.isMac = (os == "mac"); exports.isLinux = (os == "linux"); exports.isIE = ! + "\v1"; exports.isGecko = window.controllers && window.navigator.product === "Gecko"; +exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]"; exports.provide = function(namespace) { var parts = namespace.split("."); diff --git a/plugins/pilot/event.js b/plugins/pilot/event.js index 6b360007..2beaff41 100644 --- a/plugins/pilot/event.js +++ b/plugins/pilot/event.js @@ -224,7 +224,7 @@ exports.addKeyListener = function(el, callback) { }); // repeated keys are fired as keypress and not keydown events - if (core.isMac && core.isGecko) { + if (core.isMac && (core.isGecko || core.isOpera)) { exports.addListener(el, "keypress", function(e) { var keyId = e.keyIdentifier || e.keyCode; if (lastDown !== keyId) {