Short version: I seem to be getting wrong values for line #
when I try
to detect to which line the Return key I am deleting belongs.
My objective is to know which line the user has deleted.
Long description (incl. the code below - to test simply
attach it to a
field member and set wrap to false.)
Run the method with an empty field.
1. Press Enter.
2. Press Enter again.
3. Now you should be on the 3rd line of your text. Press
It will report that you deleted the Enter key that was part
of line #3
4. Press Backspace again. It will say you deleted a Enter key
part of line #2 (also correct).
5. Now press Enter key again (creating a 2nd line again).
6. Press Backspace. It will report you deleted Enter which is
line #1 - but it is part of line #2!!! If you will now press
Enter twice again
and then press backspace twice, it will report deleting lines
3 and 2 (correct again!)
This is driving me mad. What am I doing wrong?
The output I get when deleting line #2 after deleting line
"going to delete char #1 at loc 18. It is part of line #2"
The output I get when deleting line #2 (yes, the same!),
line #2 and pressing backspace:
"going to delete char #1 at loc 18. It is part of line #1"
on beginSprite me
currMember = sprite(me.spriteNum).member
on keyDown me
currSel = the selection
if currSel <> EMPTY AND currSel contains RETURN then
alert "Cannot delete more than one line at a time. Use
case the key of
charToEraseNum = (currMember.selection)
charToErase = currMember.char[charToEraseNum]
if charToErase = RETURN then
charToEraseLoc = currMember.charPosToLoc(charToEraseNum)
currLine = currMember.locVToLinePos(charToEraseLoc)
put "going to delete char #" & charToEraseNum & " at
loc " &
charToEraseLoc & \
". It is part of line #" & currLine
actually, I'm getting it reported as line #2, then #1... not
#3 at all when I follow your instructions... I would also expect to
get it saying line #2 for the first one because the RETURN is on
line #2 and not line #3... if it was on line #3 then my insertion
carat would be on line #4.