Thursday, July 24, 2008

Don't treat Underscore as a word separator character on double-click

In just about all modern text-reading and text-writing applications, a double-left-click with the mouse on a word in the text causes that word to become selected.  Double-clicking a word in this manner is handy for quickly selecting a word in order to copy-and-paste or cut-and-paste it elsewhere, or to just delete the word.  (If you've never used double-click in this way before, go ahead and give it a try on one of the words in this post, right here in your web browser.)

I've recently noticed that not all applications handle double-click-selection of words that contain an underscore character (the character "_"; also called "underbar") in the same way.  Such words are frequently used by software developers for naming such things as variables and database fields; examples are max_records and customer_id. 

In some applications, double-clicking on any portion of a word containing an underscore results in the entire word being selected.  This is the behavior I want, since it lets me easily cut or copy the entire identifier elsewhere.  (For example, taking the example of the max_records identifier, if I double-click the word, it's far more common that what I'm trying to do is select and copy "max_records" for pasting elsewhere, rather than just "max" or just "records".)  The text editor Notepad2 works this way (shown here after a double-click on the word "max"):

underscore_notepad2

The problem is that in some applications, double-clicking a word containing an underscore results in just the clicked portion of the word becoming selected; the underscore gets treated as a word separator character (like a space character would be treated).  Firefox 3 works this way (again, shown after a double-click on "max"):

underscore_firefox

Since typical (non-developer) users are seldom or never going to be working with documents with words that include underscore characters (and therefore aren't affected one way or another by what the behavior is), I think that the default behavior across all applications should be to select the entire word when a word including an underscore character is double-clicked.  The underscore should not be treated as a word separator character for the purposes of an application's logic that selects a word on a double-click.

It still might make sense for underscore characters to be treated as word separator characters in some other cases.  Such cases might include an application's spell check logic; another case might be the handling of navigating through a document a word at a time via the Ctrl+LeftArrow and Ctrl+RightArrow shortcut keys.

A few applications that get this behavior "right" (double-click selects an entire word with an underscore; not all other punctuation characters are specially handled this way):

  • Visual Studio 2008
  • Eclipse 3.3
  • Notepad2 (2.1.19)
  • Microsoft Excel (2003)

A few applications that don't get the double-click behavior "right" (double-click selects only the portion of the clicked word up to the underscore character):

  • Firefox 3
  • Internet Explorer 6
  • Toad for Oracle (9.0.1.8)
  • Microsoft Word (2003)
  • Acrobat Reader 7

Developers of this latter set of applications: If you agree, please go forth and effect positive change!  :-)  Developers of new applications, please keep this issue in mind when coding up the mouse click UI behavior for your new app.

Update 4/4/2011: There is an existing, long-standing (March 2003) Mozilla (Firefox) Bugzilla ticket for this: Bug 196175 - underscore should be part of word, not punctuation. As discussed in that comments on that ticket, though, it isn't clear that special-case logic should be added for the underscore character, since behavior from application to application even on a single platform is inconsistent (as I noted above for Windows applications). I voted for the ticket, but I'm not going to hold my breath at this point for it to be addressed soon!