From c28fb69a56d9dc9af199932ceeb90e4b1324172a Mon Sep 17 00:00:00 2001 From: "silver%warwickcompsoc.co.uk" Date: Thu, 1 Mar 2007 12:23:50 +0000 Subject: [PATCH] Bug 265847 - Match browser tab shortcuts. ChatZilla only. r=silver p=comrade693+bmo@gmail.com (Shawn Wilsher) --- extensions/irc/xul/content/handlers.js | 75 ++++++++++++++++++-------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/extensions/irc/xul/content/handlers.js b/extensions/irc/xul/content/handlers.js index b83882ec1f17..e829b6538188 100644 --- a/extensions/irc/xul/content/handlers.js +++ b/extensions/irc/xul/content/handlers.js @@ -24,6 +24,7 @@ * Robert Ginda, rginda@netscape.com, original author * Samuel Sieb, samuel@sieb.net * Chiaki Koufugata chiaki@mozilla.gr.jp UI i18n + * Shawn Wilsher * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -545,27 +546,6 @@ function onWindowKeyPress (e) } break; - case 112: /* F1 */ - case 113: /* ... */ - case 114: - case 115: - case 116: - case 117: - case 118: - case 119: - case 120: - case 121: /* F10 */ - if (e.ctrlKey || e.shiftKey || e.Altkey || e.metaKey) - break; - var idx = code - 112; - if ((idx in client.viewsArray) && client.viewsArray[idx].source) - { - var newView = client.viewsArray[idx].source; - dispatch("set-current-view", { view: newView }); - } - e.preventDefault(); - break; - case 33: /* pgup */ if (e.ctrlKey) { @@ -606,6 +586,59 @@ function onWindowKeyPress (e) e.preventDefault(); break; } + + // Code is zero if we have an alphanumeric being given to us in the event. + if (code != 0) + return; + + // The following code is copied from: + // /mozilla/browser/base/content/browser.js + // Revision: 1.748 + // Lines: 1397-1421 + + // \d in a RegExp will find any Unicode character with the "decimal digit" + // property (Nd) + var regExp = /\d/; + if (!regExp.test(String.fromCharCode(e.charCode))) + return; + + // Some Unicode decimal digits are in the range U+xxx0 - U+xxx9 and some are + // in the range U+xxx6 - U+xxxF. Find the digit 1 corresponding to our + // character. + var digit1 = (e.charCode & 0xFFF0) | 1; + if (!regExp.test(String.fromCharCode(digit1))) + digit1 += 6; + + var idx = e.charCode - digit1; + + const isMac = client.platform == "Mac"; + const isLinux = client.platform == "Linux"; + const isWindows = client.platform == "Windows"; + const isOS2 = client.platform == "OS/2"; + const isUnknown = !(isMac || isLinux || isWindows || isOS2); + const isSuite = client.host == "Mozilla"; + + if ((0 <= idx) && (idx <= 8)) + { + if ((!isSuite && isMac && e.metaKey) || + (!isSuite && (isLinux || isOS2) && e.altKey) || + (!isSuite && (isWindows || isUnknown) && e.ctrlKey) || + (isSuite && e.altKey)) + { + // Pressing 1-8 takes you to that tab, while pressing 9 takes you + // to the last tab always. + if (idx == 8) + idx = client.viewsArray.length - 1; + + if ((idx in client.viewsArray) && client.viewsArray[idx].source) + { + var newView = client.viewsArray[idx].source; + dispatch("set-current-view", { view: newView }); + } + e.preventDefault(); + return; + } + } } function onWindowFocus(e)