Saturday, May 10, 2008

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

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!

28 comments:

Ryan said...

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!

Matthew V Ball said...

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.

Leth said...

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

Richard Bronosky said...

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.

Turadg said...

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?

Matthew V Ball said...

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.

The Truth Hurts said...

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

Anonymous said...

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

Anonymous said...

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).

peach said...

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?

Matthew V Ball said...

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.

j said...

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?

Matthew V Ball said...

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

Kris said...

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.

Kevin Carmony said...

Thank you!!!

Kevin

sam said...

is there a way to reverse this?

Matthew V Ball said...

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

Anonymous said...

Many thanks Matt!!!

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

Guus said...

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.

Matthew V Ball said...

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... :)

Guus said...

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.

Amanda said...

Thank you! :)

damo said...

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.

Troy McHenry said...

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

Wouter said...

Thank you Matt!

You're my hero ! ! !

(it makes my work a lot easier)

douglas said...

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

Matthew V Ball said...

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!

Anonymous said...

THANK YOU SO MUCH FOR THIS FIX!!!!!!!!!!!!!!!!!!!!!!!