How to start this project...
J. Landman Gay
jacque at hyperactivesw.com
Sun Oct 8 15:44:29 EDT 2006
Adrian Williams wrote:
> I just need to get started on the proper method
> of detecting:
> Where the cursor is when its clicked in the text field?
> Because it may be at the line beginning or in the middle of a word.
> The function 'selectedChunk' returns the position of the entered
> character in the form of...
> char 1 to 0 of field 1 (the first character in the field)
> char 1 to 2 of field 1 (the second character in the field)
> etc, etc.
> So from that, how does Jacqueline get a simple plus or minus value...?
You're close but not quite right yet. In the first example, the
insertion point is blinking at the beginning of the line, but no text is
actually selected. If you were to begin typing, new text would be
inserted before the existing text.
In the second example, the user has actually dragged over the first and
second characters; there is a current selection. Any new text you type
at this point would replace the two characters.
Here is a visual representation of "char 1 to 0":
|abc -- cursor at beginning, no selection
Here is "char 1 to 2":
|ab|c -- where the double bars indicate a range of selected text
To determine whether text has been dragged over and selected, you
compare "word 2 of the selectedchunk" with "word 4 of the
selectedchunk". If word 2 is larger, you've got a blinking insertion
point with no selection. If word 4 is larger, the user has dragged
across some text and there is a selection.
Thus, if word 2 is larger, word 2 plus 1 will give you the character
position of the character after the blinking insertion point. If word 4
is larger, then word 4 plus 1 will give you the position of the
character after the selection.
To see how this works, put this into the script of a regular text field:
put the selectedchunk
Then type a few characers into the field, and start clicking and
dragging across some of them. Watch the message box to see how the
But from your jpg example, I'm not sure you even need all of this. Is
this a simple text substitution? If so, I think I'd just use a "keydown"
handler to see what the user has typed, and replace the character with
the substitution character you actually want to display.
Even easier, it seems to me, would be to just assign the cursive font to
the field and bypass the whole issue. The user's typing would
automatically be cursive.
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the Use-livecode