PDA

View Full Version : inputtext text selection position


ftroop
04-14-2005, 10:31 AM
Hi,

<b>I am using 3.0b2.</b>

Building on the following threads:

http://www.laszlosystems.com/developers/community/forums/showthread.php?threadid=2263&highlight=getSelectionPosition
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=665&highlight=getSelectionPosition
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=809&highlight=getSelectionPosition

I am simply trying to get the starting position and size of SELECTED text within a body of text entered
into an inputtext component. This is proving less straight-forward than I had hoped. My code is similar to the following:

<view name="my_view">
<inputtext name=itext" width="200" height="75">
<method event="onselected" args="k">
<![CDATA[
debug.write(this + ".onselected"+"-"+k);
Debug.write('onselected pos :'+ getSelectionPosition());
Debug.write('onselected size :'+ getSelectionSize());
]]>
</method>
</inputtext>
</view>

I want the Debug statements above to fire whenever a user enters some text and highlights, with the mouse, certain portions of that text. The code above never seems to get the onselected event and no debug statements are written.

In sum, I am wondering:

1.) Does the 'onselected' event work as I have used it, or am I using it incorrectly, in the wrong place, whatever?

2.) Do getSelectedPosition() and getSelectedSize() work in 3.0b2? If so, how are they to be correctly used?

3.) Should I be using a different event for this? I've tried several others to no avail. For example, ondblclick returns -1's for both getSelectedPos. and getSelectedSize.

Thanks in advance!

ftroop
04-14-2005, 01:26 PM
The answer lies in hints sprinkled throughout the forum, but for dolts like me, not clearly enough. Perhaps the following code will enlighten and entertain:

library.lzx

<library>
<class name="myinputtext" extends="inputtext">
<attribute name="xpos" value="0" type="number"/>
<attribute name="sizepos" value="0" type="number"/>
<method name="dothis">
<![CDATA[
Debug.write("SIZE: " + getSelectionSize());
Debug.write("POSITION: " + getSelectionPosition());

var a = getSelectionSize();
var b = getSelectionPosition();

setAttribute('xpos', a);
setAttribute('sizepos', b);
]]>
</method>
</class>
</library>

main.lzx

<canvas width="900" height="300" bgcolor="white">
<include href="library.lzx"/>

<debug x="250"/>

<view name="main">
<button name="click_me">Click Me
<method event="onclick">
<![CDATA[
var a = parent.second_test.getAttribute('xpos');
var b = parent.second_test.getAttribute('sizepos');

Debug.write("Got A: " + a);
Debug.write("Got B: " + b);
]]>
</method>

<method event="onmouseover">
<![CDATA[
parent.second_test.dothis();
]]>
</method>
</button>
<myinputtext name="second_test" width="300" height="120" y="${click_me.y+40}" bgcolor="yellow">Test</myinputtext>
</view>
</canvas>

Select all or part of the text in the custom inputtext field and click the button to see what range of chars was selected.