views:

57

answers:

2

I have an input box: input type="text" class="rulerInputText" id="rulerInputBox" readonly
I have Javascript code to detect the selected text and play around with it.

The issue comes when I am allowing the user to actually select text. The text is basic with spaces. When the user begins selecting, there is no issue, but when a space is reached, the user selects it and the next word is automatically selected. Essentially, I want to prevent automatic selection of the entire word. I only want to select exactly what the user wishes to select with the mouse.

Is this possible or do I need to use some sort of crazy Javascript hacks to get this done?

A: 

This is a feature of Operating System. The OS provided textbox does auto-selection for better user experience. You do not have any control over here. (I just confirmed on IE/Windows7)

Ankit Jain
this would be the browser providing the auto-selection, not the OS. You have some control over it, varying between browsers, but not the way of selecting text, as far as I know.
Jasper
Well that's just depressing. Now I have to go all out to get a better text selection method. Thank you for your help.
lighthazard
@Ankit: I, for one, don't find this behavior to constitute a "better" user experience.
Robusto
@Robusto - it helps in quickly selecting text. If your last word selection is partial word only, just move the pointer back and forth again and now the last word is partially selected based on your pointer location.
Ankit Jain
@Ankit But it also decides to highlight the partial word before the space as well. To solve that issue, one has to deselect it and start over, from right to left.
lighthazard
@Ankit: I still don't see how that's easier than letting you select what you want in the first place. A workaround is not preferable to something that just works right the first time. YMMV, but I find this behavior very annoying.
Robusto
A: 

This is a feature of IE specifically; no other browser has this behaviour. It's a deliberate “smart selection”(*) feature copied from Office, though in newer versions of Office it works less annoyingly, allowing you to revert to character selection if you move the pointer back.

There is as far as I know no way to turn it off in IE, either at the client or server end, because Microsoft think it's such a great feature. Sigh. Even JavaScript hacks don't provide a way round.

About all you could do would be to put invisible spaces between each character, so that IE thought each character was a second word. eg. try selecting:

f​o​o b​a​r b​o​f z​o​t

these have Unicode U+200B ZERO WIDTH SPACE characters between letters. This has side effects though; if the user tries to edit or copy-and-paste the text, they'll get weird invisible characters in the way potentially messing it up.

(*: As usual, “smart” means second-guessing the user, usually getting it wrong, and insisting it's right. aka. “stupid”. Run a mile from anything describing itself as smart.)

bobince
I was thinking of using this method, since the user only needs to see a visual representation. Then I realized I cannot easily modify selection background color, and etc, so it might be easier to just make my own custom script for it.
lighthazard