Re: proposal to expose word breaker through JavaScript

Hi Anne, Alfonso,
Thanks for your reply and the reference to Microsoft's range.expand.
Please see my reply inline.


On Wed, Jul 29, 2009 at 6:35 AM, Anne van Kesteren <annevk@opera.com> wrote:

> Initially I did not quite understand what this API was proposing, but after
> reading it a few times it seems to mimic the behavior of what typically
> happens when you double-click a "word".
>

Yes. you are right. It is to identify a word when user mouse over or
click on a page. A specific use case is dictionary, which shows the
word definition when user mouse over or click in a webpage.

For example: following JS code would locate a word under mouse.

var range = document.caretRangeFromPoint(event.clientX, event.clientY);

var word = document.expandRange(range, 'word');


> I'm still not quite sure whether I understand the API though. Is "word" a
> keyword on how the range is to be extended or is it an example? Also,
> wouldn't it be better to put the method on Range rather than Document?


"word" is a keyword.  Like Microsoft's
spec<http://msdn.microsoft.com/en-us/library/ms536421%28VS.85%29.aspx>,
a range could be extended to a 'character', a 'word', a 'sentence', or a
'line' etc.

As to whether it should be a method in Document or in Range, it is open to
discussion.



>
>
> And finally, use cases would help as well as a definition of "word
> boundary" and how this works/won't work in an international context.


A word is the smallest semantic form in one language. In languages use space
to break word, such as English, a word is a collection of characters
terminated by a space or punctuation. In languages do not use space to break
word, such as Chinese, word breaker is needed to break a word.

The API should work for English, at least. Whether it works in an
international context depends on whether the layout engine/browser supports
correct word breaker in that language.

Thanks,
Xiaomei




>
>
> Cheers,
>
>
> --
> Anne van Kesteren
> http://annevankesteren.nl/
>

Received on Wednesday, 29 July 2009 18:17:54 UTC