views:

34

answers:

1

Hopefully this is possible by invoking a method that gets executed by browser internal code. Given a point x,y in dom coordinates. (that is can get relative to any node) in an element containing text I want effectively

charIndex = characterUnderPoint(textNode,nodex,nodey);

I figure if there is some sort of facilty to do

range = xx.creatRange(node,x,y)

or

selection = xx.createSelection(node,x,y)

or

range.setAnchorToLocation(node,x,y)

etc.

I can't find anything so far that implements effectively what happens when you click to set the caret position. all the methods seem to only take a character offset.

Mainly I want this because searching by incrementing a range through all the chars to test whether the point is in it is very slow (could be a binary search but) it should be done inside the layout engine in native code to be fast.

A: 

There's no easy way to do this. Range won't help you. It's all about nodes and offsets.

Tim Down