Uploaded image for project: 'Apache Flex'
  1. Apache Flex
  2. FLEX-21494

getCharIndexAtPoint does not work as expected on textAreas and horizontal scroll

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Adobe Flex SDK 3.4 (Release)
    • None
    • mx: TextArea, mx: TextInput
    • None
    • Affected OS(s): All OS Platforms
      Affected OS(s): All OS Platforms
      Browser: Internet Explorer 6.x
      Language Found: English

    Description

      Steps to reproduce:
      1. extend a TextArea field and implement the following functions:
      public function mouseToCursorPos(x: uint, y: uint): uint {
      var p: Point = textField.globalToLocal(localToGlobal(new Point(x + horizontalScrollPosition, y + verticalScrollPosition)));
      x = p.x; y = p.y;
      var index: int = textField.getCharIndexAtPoint(x, y);
      if (index == -1)

      { index = textField.getLineIndexAtPoint(x, y); if (index == -1) index = textField.numLines - 1; index = textField.getLineOffset(index) + textField.getLineLength(index) - 1; }

      }

      public function set cursorPos(value: uint): void { selectionBeginIndex = value; selectionEndIndex = value; }
      2. on mouse move set the cursorPos to the result of mouseToCursorPos(event.localX, event.localY);
      3. disable wordwrap on the text area
      4. enter enough text to horizontally scroll, then scroll across to the right and move the mouse so the carrot follows it.

      Actual Results:
      carrot does not follow the cursor if the x position is greater then the width of the textField, getCharIndexAtPoint is returning -1;

      Expected Results:
      The cursor should be correctly offset by the horizontal scroll position and follow the cursor around.

      Workaround (if any):
      Update the function with the version below that contains a kludge to widen the textField temporally

      public function mouseToCursorPos(x: uint, y: uint): uint {
      /* kludge to work around flex SDK bug */
      var oldwidth: int;
      var oldscroll: int;
      oldwidth = textField.width;
      oldscroll = horizontalScrollPosition;
      textField.width = 10000;

      var p: Point = textField.globalToLocal(localToGlobal(new Point(x + horizontalScrollPosition, y + verticalScrollPosition)));
      x = p.x; y = p.y;
      var index: int = textField.getCharIndexAtPoint(x, y);
      if (index == -1) { index = textField.getLineIndexAtPoint(x, y); if (index == -1) index = textField.numLines - 1; index = textField.getLineOffset(index) + textField.getLineLength(index) - 1; }

      /* undo the kludge to work around the bug */
      textField.width = oldwidth;
      horizontalScrollPosition = oldscroll;
      return index;
      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            adobejira Adobe JIRA
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: