1 Reply Latest reply on Nov 11, 2006 6:07 PM by Chunick

    get line # from locVToLinePos doesn't work?

      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 Backspace.
      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 that is
      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 part of
      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 #3:
      "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!), after adding
      line #2 and pressing backspace:
      "going to delete char #1 at loc 18. It is part of line #1"

      property currMember

      on beginSprite me

      currMember = sprite(me.spriteNum).member

      end beginSprite

      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 Backspace to
      erase lines."
      case the key of
      charToEraseNum = (currMember.selection)[1]
      charToErase = currMember.char[charToEraseNum]
      if charToErase = RETURN then
      charToEraseLoc = currMember.charPosToLoc(charToEraseNum)
      currLine = currMember.locVToLinePos(charToEraseLoc[2])
      put "going to delete char #" & charToEraseNum & " at loc " &
      charToEraseLoc[2] & \
      ". It is part of line #" & currLine
      end if
      end case
      end if

      end keyDown