Saturday, May 10, 2008

Fixing Home and End Keys on Firefox 3 for Mac OS X

[Update: Keyfixer 0.4 is now available; see new blog post]

Since I'm a heavy gmail user, I make significant use of the editor window in my web browser. Ever since moving to a Macbook as my primary computer, I've been struggling with re-learning the Mac navigation key shortcuts. Since I still use Windows a lot, I decided to instead reconfigure the Mac shortcuts to emulate Windows shortcuts.

This strategy worked well, except for in Firefox, which doesn't respect the Mac DefaultKeyBinding.dict file. For Firefox 2, I solved this problem by running Keyfixer as published by Starry Hope. Unfortunately, this stopped working for me when I updated to Firefox 2.0.0.14. I switched to Safari for a while, but Safari's other bugs and "features" started to annoy me. I wanted my Firefox back.

After digging into what Keyfixer does, I've put together an updated version 0.3 that should work for Firefox 2.0.0.14 and Firefox 3.0 beta 5 (tested on Mac OS X 10.5.2). The new solution performs patches instead of straight copies of the keymapping xml file, so I'm hoping it is more robust against future changes in Firefox.

Click here to get Firefox Keyfixer 0.3.

Compared to version 0.2, this new version has the following updates:
  • Support for both Firefox 2 and 3 (versions on or after May 2008)
  • Running the program twice will uninstall the patch. This is useful when performing upgrades (Firefox won't upgrade if Keyfixer has been applied -- you have to remove it first)
  • PageUp and PageDown now moves the cursor instead of just moving the screen. This is more consistent with Firefox on Windows.
As a side note, it looks like there was an intention in Firefox to follow standard Mac behavior by mapping Command-Left Arrow and Command-Right Arrow to move the cursor to the beginning and end of line, respectively. However, this doesn't seem to work (at least when using gmail). I'm interested to know if anyone else has seen this issue, because it's a bug.

If you have any problems or questions with this version, please drop a comment and I'll see what I can do to help!

47 comments:

  1. I am having the same problem in FireFox 3 (all betas and RC1) while using gMail.

    cmd+left arrow/cmd+right arrow and fn+left arrow/fn+right arrow don't do anything at all.

    They work fine in other google apps, such as docs.


    Using your patch makes fn+left/right work as home/end. Thank you so much!

    If you could make cmd+left/right work as home/end, it would be absolutely perfect!

    ReplyDelete
  2. Ryan: If Firefox properly supported cmd+left/right arrow for moving to the beginning/end of a line, then this whole mess wouldn't has started. I'm convinced this is a bug in the Mac Firefox code because these shortcuts are already included in the platformHTMLBindings.xml file (the file modified by keyfixer to update the keyboard shortcuts):

    <handler event="keypress" keycode="VK_LEFT" modifiers="accel" command="cmd_beginLine"/>
    <handler event="keypress" keycode="VK_RIGHT" modifiers="accel" command="cmd_endLine"/>

    (The "accel" modifier equals the "Command" key on a Mac Keyboard)

    I think the reason behind this bug is that the Firefox browser uses Cmd+left/right Arrow to go backward or forward in the browse history whenever you're not in a text box. Safari also does this while navigating, but correctly handles moving to the beginning or end of a line when in a text box using the standard cmd+arrow combos.

    So the short answer is that I can't fix cmd+left/right arrow without digging deep into the guts of Firefox.

    Just as a side note, Macbooks don't label the 'Home', 'End', 'PageUp', and 'PageDown', keys, but expect you to know to use Fn + Left/Right/Up/Down Arrow instead. The MacBook Pros label these functions keys (Apple must be assuming that the Pro users are smarter, or something).

    Keyfixer affects the Fn + arrow key behavior on the various Macbooks. If you attach a full sized USB keyboard, Keyfixer will affect the Home/End/PageUp/PageDown keys.

    ReplyDelete
  3. Aha! Excellent, I was just about to look into implementing this sort of patch hackery with keyfixer myself.

    Fortunately I did a quick google aiming to see if FF handles keybindings the same way in version 3, and came across your post.
    Good thinking with the unpatching functonality btw :)

    I've not gone quite as far as you, I only have home and end rebound in defaultkeybindings, however it never ceases to amaze me how much of the official osx software doesn't pay any attention to it.

    Thanks a bunch

    ReplyDelete
  4. Ryan, I have researched this in depth. http://groups.google.com/group/Gmail-Help-Organizing-Messages-en/browse_thread/thread/abf1cbd023e57302 It's not so much as a bug in FF that is causing Ryan's concern as it is a poor design choice on the part of the FF team. Using Cmd-[Arrow] for history navigation is as poor of a choice in Mac design as using Home and End would have been in windows design. It should have been Ctrl-[Arrow] for history navigation.

    Anyway, another key point to the URL above is that in it I give an example of how Yahoo! has implemented a rich text editor that respects Cmd-[Arrow] cursor movements. I have worked for Yahoo! and know many Googlers. Comparing the 2 companies I'm VERY shocked that Yahoo! are the ones who better respect Mac users.

    ReplyDelete
  5. I can confirm this is still a problem in Firefox 3.0 RC2 on Mac. And it's not just Gmail. The bug is evident when using Google Docs as well.

    That command-arrow is also used for navigation isn't a valid excuse, since the proper end-of-line behavior happens when in a text field such as URL bar or Gmail's search box. The problem appears to be only in text areas.

    This is a bug. Anyone found or submitted this in Bugzilla? I guess it's too late for 3.0, but maybe 3.0.0.1?

    ReplyDelete
  6. I've found an active bug that covers the issue of Cmd+Right/Left Arrow not working in Gmail compose mode on Firefox for Mac:

    https://bugzilla.mozilla.org/show_bug.cgi?id=341886

    This bug has been outstanding for two years now, and hasn't seen a resolution. It looks like Gmail somehow steals the Cmd+Arrow shortcut when using the "Rich formatting" mode for entering e-mails.

    ReplyDelete
  7. Thank you for making the update for FF3 - your keyfixer has been a godsend for me!

    ReplyDelete
  8. Matt, thanks for doing this. I was just about to do the same thing you did. You saved me some time. Word.

    ReplyDelete
  9. Thanks much! I've been using all the Firefox 3 RCs. Each test-release brought me back to ground zero for home/end key functionality. I do tons of wiki page editing and this was such a problem for me. This works great with Firefox 3 (final).

    ReplyDelete
  10. Unfortunately this did not work on my Mac. Both in Yahoo mail and Gmail the Home key doesn't take me to the beginning of the line like it would in Windows. Do you know of any other programs I could try?

    ReplyDelete
  11. Hi Peach,

    Could you provide more information about your system? (version of OS X and version of Firefox). This utility has only been tested on Firefox 2.0.0.14 and Firefox 3, and may not work on previous versions.

    Lifehacker has linked this article, so there may be some more clues there (see http://lifehacker.com/396685/firefox-keyfixer-makes-home-and-end-keys-work-like-windows) -- although it looks like you've already commented on that blog...

    There may be some issues if you try to install other 'keyfixer' variants before running this one. If this is the case, try reinstalling Firefox (preferably version 3), then run Firefox Keyfixer version 0.3 (from this article). Let me know if that fails to work, and we can try to debug it.

    ReplyDelete
  12. great fix. any chance you'd work on one to modify F3 functionality. i have the function keys set to be special features but would like, only in firefox for F3 to give me the next search result. can this even be done?

    ReplyDelete
  13. Hi J,

    I probably won't work on an 'F3' extension anytime soon, since I don't use this shortcut. :( However, I can give you a couple hints how to fix it.

    (I'm going off memory since I've got a Windows computer right now, so the exact text may be wrong...) One thing you can do is to use the Keyboard configuration under Mac OS X 'System Preferences...' menu (click the Apple icon, typically in the upper left, then go to System Preferences). Once in System preferences, click on the keyboard icon, and then you can go into the right-most tab that lets you bind particular keystrokes to menu commands. In this case, you want to bind F3 to 'Find Again' for Firefox.

    Modifying keyfixer to do this is probably tricky and may not be possible. What you want is to invoke 'Browser:FindAgain', but the closest cmd_ available is 'cmd_findTypeText', which I think is the behavior you get when you press '/'.

    In short, I hope you're able to get the Mac Preferences thing working, because going the 'keyfixer' route looks tricky...

    ReplyDelete
  14. This is a great thing, thanks for the fix!

    As far as not being able to use Cmd + Arrow on the Macbook keyboard, that's fine with me. As long as I have a consistent way to have an effective home and end keystroke, I'll adjust my habits! I end up using an external USB keyboard most of the time anyway.

    Now I can use my Google Docs and GMail and tons of other things with ease. Thanks again.

    ReplyDelete
  15. is there a way to reverse this?

    ReplyDelete
  16. If you run the program again, it will remove a previous patch, which also makes Firefox ready for an upgrade.

    ReplyDelete
  17. Many thanks Matt!!!

    This firefox-end-key problem really really really frustrating me with the Mac. Thanks so much for doing a fix!!

    ReplyDelete
  18. Hi Matt, great this works for me with Mac OS X 10.5.4 and FF 3.01 too in creating and editing text in Gmail and Google Docs.
    Now I've an extended wish that I could use the Home and End key in combination with Shift in selecting text from a webpage. I do a lot of copying text to mail messages and your latest keyfixer 0.3 won't work on selecting text on a webpage.

    ReplyDelete
  19. Hi Guus,

    I'm not sure if I quite understand the request, but will try to help. Do you want to select from the cursor to the top or bottom of the document using Cmd+Home or Cmd+End? If your goal is to select all the text on a page, you can use Cmd+A. If you're talking about a "web page" instead of a "text box", then I don't know how to make Cmd+Home or Cmd+End work because there isn't really a current cursor location -- cursors are only in textboxes.

    If (in a text box) you want to select from the cursor to the top or bottom of the document, you can use Cmd+Shift+UpArrow or Cmd+Shift+DownArrow. I think this will address your issue, although it doesn't use keys familiar to Windows users.

    After installing Keyfixer 3.0, Cmd+Home and Cmd+End will select from the cursor to either the beginning or end of the current line. The rough Windows equivalent of selecting from the cursor to the top or bottom of the page is Cmd+Shift+Home or Cmd+Shift+End. This was a minor oversight on my part when I put this patch together, but you can expect it fixed in subsequent versions. I'll have time to start work again in October, or when a Firefox upgrade breaks keyfixer, whichever comes first... :)

    ReplyDelete
  20. Sorry for the confusion, Matt.
    Your Keyfixer worked so perfect I wanted to use the Home and End key also for selecting text from a non-editing page. For example selecting text next to this text box, but you're right there is no cursor in a non-editing page. ;-{. Under Windows Vista of XP it works neither.

    I'm just started with Mac OS X, coming from Windows XP and Vista I missed the Home and End key on my iMac heavily in composing messages in Gmail.

    Luckily using the Home and End key under OpenOffice Writer, even the Cmd+Shift+Home or Cmd+Shift+End for selecting text from cursor to the beginning or the end, works as expected. So if you manage to add the Cmd+Shift+Home/End functionality to the next version of Keyfixer I would appreciate that strongly.
    Thanks.

    ReplyDelete
  21. Regarding those that have lost the ability to Command-Left/Right in Gmail, just turn off the Rich text formatting by clicking "Plain Text" below the subject.

    Hey presto! It works. So it's a Gmail bug not a FF3 bug.

    ReplyDelete
  22. Thank you so much for updating the .2 version. I'm a long time PC user and love FireFox, but not being able to use the home and end keys to quickly edit URL's has been driving me nuts.

    T-H-A-N-K-S !!!

    ReplyDelete
  23. Thank you Matt!

    You're my hero ! ! !

    (it makes my work a lot easier)

    ReplyDelete
  24. I wish this was a firefox add-on. Every time a new version of firefox is released, I have to install your fix.

    ReplyDelete
  25. Douglas: I feel your pain, because I have to uninstall, then reinstall this patch whenever Firefox is upgraded, just like everyone else!

    I don't know of a way to easily solve this problem using a firefox plug-in. I wrote a post on an existing Firefox plug-in named keyconfig, but it's unclear to me whether the Firefox plug-in API is rich enough to allow the low-level changes required by Keyfixer. If anyone can find a way to modify keyconfig to do what keyfixer does, I'd be very interested to hear!

    ReplyDelete
  26. THANK YOU SO MUCH FOR THIS FIX!!!!!!!!!!!!!!!!!!!!!!!

    ReplyDelete
  27. Thanks so much. This was driving me nuts!

    ReplyDelete
  28. This is the best! Thanks for the little app. Next time I see you in Starbucks, coffee is on me! :-)

    ReplyDelete
  29. Oh God of the Mac Keyboard, will you be releasing an update for Firefox 3.1b2? Working gMail keyboard shortcuts and multi-touch gesturing...

    one can only dream...

    ReplyDelete
  30. I hacked together a version that appears to work on Firefox 3.1b2 (nightly builds). I am not 100% sure what I'm doing, but I ran it and it works. But be careful and make a backup before using it.

    http://www.matznerd.com/2008/11/firefox-31b2-homeend-keyfix.html

    ReplyDelete
  31. Hi Ryan and Anonymous,

    You guys butter me up way too much... :)

    I haven't tried Firefox 3.1b2 yet, but probably should give it a spin shortly.

    I appreciate that the hacker community is able to take my weekend's worth of work from 6 months ago and quickly turn a bugfix. For my own part, I just stole this code from Starry Hope, who did the real work, and tweaked a couple things to work with the latest XML files.

    Ryan, I've glanced through your fix and suspect that it won't work for existing users because the path to Firefox has changed from '/Applications/Firefox.app' to '/Applications/Minefield.app'. With a few minor changes, I think this can be easily remedied.

    Do we know whether Firefox 3.1 will install to '/Applications/Firefox.app' or Minefield.app? Maybe this is just a weird quirk with the beta version. As a longer term fix, we might want to allow the user to specify where Firefox is installed....

    I'm hoping to get some time over the Thanksgiving weekend to hack through some of these issues and produce a nice .dmg file for installation...

    Thoughts? Thanks for quickly finding a solution!

    ReplyDelete
  32. Okay, I discovered that it is possible to change keyfixer into an Extension. Keyfixer 0.4 is now available. See updated blog text.

    ReplyDelete
  33. It did not work for me, but the add-on "keyconfig" did. See http://www.macosxhints.com/article.php?story=20070511123925218

    ReplyDelete
  34. Thank you so much!!! I've been loving everything about my mac except for the freaking Home/End keys not functioning like what I'm used to using on my windows machine.. Now I can finally live in peace :) Thanks again.

    ReplyDelete
  35. thanks a lot! works fine!

    makus

    ReplyDelete
  36. I hope you're all using version 0.4 (see top of post) and not version 0.3. Version 0.4 is much better... This blog post is basically dead and is just here for posterity. :)

    ReplyDelete
  37. Any chance we can get a Thunderbird plugin?

    ReplyDelete
  38. See https://addons.mozilla.org/en-US/thunderbird/addon/9796 for the Thunderbird plugin page. Note, though, that this is an identical extension as for Firefox.

    ReplyDelete
  39. It didn't work for me on OS X 10.5.6 and Firefox 3.5.2. When I opened the dmg it said "can't find Firefox in /applications/" even though it is there. Any ideas?

    ReplyDelete
  40. This has been replaced with a FireFox Plugin: https://addons.mozilla.org/en-US/firefox/addon/9796

    ReplyDelete
  41. As previous commenter noted, there is a Firefox plugin ("KeyFixer") which accomplishes this, but it also changes *all* the keybindings to windows style (ctrl key <--> apple key) with no "preferences" dialog to change this. To get just the home/end behavior, go to http://drop.io/huudjy4 . Hopefully, there will be an offical mozilla supported version soon.

    ReplyDelete
  42. Huh? The keyfixer addon given by payments worked fine for me with no side effects on apple keys, e.g. apple+T still opens a new tab etc.

    ReplyDelete
  43. Thanks Matt Much appreciated

    ReplyDelete
  44. Hello man, I know this is an old blog post but it is still relevant for me. Just wanted to give a heads up that the links are broken, even though changing the host part of the URL to heisencoder.net took me where I wanted to go ;-)

    Cheers

    ReplyDelete
  45. Thanks for catching the old link! I've updated it to the correct link.

    ReplyDelete

Note: Only a member of this blog may post a comment.