Blogging Robots

On Anchored Selections

Pierre Igot wrote a blog post – Shrinking and expanding selections in Mac OS X (via Daring Fireball), in the first part of which he explains how text selection works on Mac OS X, and complains that this behavior is wrong. I disagree.

Let me explain. On Windows and Gnome, when you’re selecting text with mouse, the anchor is being placed on the final point of your selection (and it’s displayed with a blinking indicator in some applications like Notepad). If you select text from left to right, the anchor appears at the end of your selection:

Windows: anchor at the end

If you go from right to left, the anchor is at the beginning of it:

Windows: anchor at the
beginning

Pierre writes:

What if I overshot by one character or two and actually only wanted to select the first two words? To me, since the selection with the mouse was made from left to right, intuitively I should be able to shrink the selection by one or two characters by pressing shift-Left a couple of times on my keyboard.

This seems logical: if you go left to right, you’ll probably miss a character of two, so placing anchor to the end of your selection is the right way. But this logic is flawed. It’s no harder to miss a character when you begin selecting text, than to miss it when you finish. Actually, there’s no way to select missing characters at the beginning at all, apart from starting your selection from scratch. There’s also a problem with double-clicking the word. Where should be the anchor placed in this case? Windows places it at the end of the word, while Gnome places it at the beginning.

Cocoa text controls behave differently. When you select text with mouse, the anchor is undefined. When you switch to keyboard, you control the anchor point: if you start by pressing Shift+Right, the anchor is being placed at the end of your selection, but with Shift+Left it’s being placed at the beginning. This way you can easily select missing characters in any part of your selection. Also, without anchor, you can continue growing your selection both ways.

Notice that I didn’t say that Mac OS X behave differently, just Cocoa. Carbon handle this the third way (the anchor is always where you click), but Apple is getting rid of it. That’s why Finder has anchored text selection with mouse. Good thing there are rumors that it’s being rewritten in Cocoa for Snow Leopard.

Yes, there’s inconsistency between text selection and list selection, but I have no explanation for this :)

Update: Pierre published a follow-up.