Safari 5.1: Hidden SPAN element adds extraneous carriage return

Posted by Pierre Igot in: Macintosh
March 9th, 2012 • 2:57 pm

Ever since TERMIUM, the Government of Canada’s on-line terminology database, became a free service last year, the people behind the web interface have been tinkering with it in ways that have made it sometimes frustrating to use.

A few days ago, they implemented yet another change, in which the “Search” and “Subject” tabs are now side by side instead of being one on top of the other.

I don’t mind the change, except that, at the same time, they have introduced another change that most definitely has an impact on the usability of the site for me.

See, quite often, when I look up a English term, I end up selecting the French equivalent by double-clicking on its first word and then dragging the mouse to the right to extend the selection and include the other words. I then copy the selection to the Clipboard and paste it into my word processor.

Now, when I double-click on the first word in the first result in the “French” column, I get this:

Selected word

The first clue that something is not quite right is the selection highlighting. As you can see, the highlighting (green on my machine) includes not just the word, but also an area above the word that spans the width of the column and appears to extend upwards underneath the column headings.

This extra highlighting remains even after I drag to extend the selection to the end of the term:

Selected term

It’s not as noticeable now because the selected words themselves extend all the way across the column, but you can definitely see it if you compare it to what happens when you select the words without using double-clicking, i.e. with a simple click-and-drag selection gesture:

Selected term

This is the way things used to look even with double-click-and-drag before they made the recent change to the TERMIUM user interface.

If it were just a visual thing, I wouldn’t really care. But this extraneous selection highlighting actually creates a very real problem, which is that, when I copy the selection to the Clipboard and then paste it into my word processor, OS X inserts an extraneous carriage return character before the pasted text, which I then have to delete manually each and every time. (I usually paste the copied term right into an existing paragraph.)

I cannot reproduce this problem with Firefox, and, as you can see in the third picture above, the problem only occurs when I use double-click-and-drag in Safari to select the term. I also cannot reproduce it with other terms after the first one in the second column. This only occurs with the very first word of the very first term in the column.

As far as I can tell from looking at the web site’s code, the problem is due to the presence of this bit of code right before the beginning of the contents of the second column, i.e. right before the first term:

<span lang="fr" xml:lang="fr" class="hidden">
			 Les vedettes principales, 
			 
			 Français
			  
			 </span>

It’s supposed to be hidden, and it is, except then Safari fails to ignore it when selecting text in the column using double-click-and-drag. In other words, double-clicking on the very first word after this bit of code causes Safari to somehow also select this hidden SPAN element and then OS X interprets the element as an extra carriage return character to include before the actual selected text.

I was able to verify this by archiving the web page locally and loading it in Safari after having removed that extra bit of code. Once I did that, I could no longer reproduce the problem. (Removing the white space and only keeping the code does not help. Only removing the entire SPAN element eliminates the problem.)

I’ve written to the TERMIUM folks about this, but of course I have little hope of them doing anything about it, since it only affects Safari and it’s quite clearly a Safari bug that they would have to work around.

I’ve also submitted a bug report to Apple via Bug Reporter. If you are a TERMIUM user or simply a Safari user who has noticed this problem with other sites, I strongly encourage you to submit a bug report as well. Maybe eventually Apple will do something about it.


One Response to “Safari 5.1: Hidden SPAN element adds extraneous carriage return”

  1. Betalogue » Really Smart Paste: Keyboard Maestro and BBEdit to fix copied text from on-line database and other sources says:

    [...] in rich text format (which font face, character size, colour, etc.); it can be surrounded by undesirable white space that is copied along with it; and whenever the text contains apostrophes, which is quite commun in [...]