[Laszlo-user] text editing and insertion point position

Benjamin Shine ben at laszlosystems.com
Tue Mar 14 00:39:18 EST 2006

I suggest putting a transparent overlay on top of the non-selected  
text field. When the overlay gets a click, set editable of the  
associated text field to true, set the focus to that text field, and  
hide the overlay.

The kind of text measurements required to go from a click's x, y  
position to its position in the text is really expensive and fragile,  
if it's even possible. Instead, look at the text's  
getSelectionPosition() and getSelectionSize() methods. When LzFocus  
is on the text field, getSelectionPosition() is the index of the  
insertion point into the text's string.

Be wary of the order and timing of events triggered by a user event.  
The methods that operate on a text field's selection only work  
properly if they're called when the text field has focus, but focus  
is lost easily. We handle this with much gnashing of teeth in the  
rich text editor in the incubator; see especially the formatbtn and  
the restore selection delegate.

On Mar 10, 2006, at 10:21 AM, Daniel Pool wrote:

> I can see two possible solutions but I don't know how to implement
> either of them. For selected but non-editable fields:
> 1...When the field gets a click set the editable property to true and
> then post the click event to the field again, or create an event to  
> post
> to the field.
> 2...When the field gets the click from the x,y position of the click
> determine the offset into the text-string of the field and call
> setSelection based on the offset into the text-string.

benjamin shine
software engineer
ben at laszlosystems.com

More information about the Laszlo-user mailing list