TextComponent.getCaretPosition() treats VK_ENTER characters as if they were 2 ch

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 1.1
    • Component/s: client-libs
    • None
    • x86
    • windows_nt



      Name: sg39081 Date: 07/01/97


      - derive a class from java.awt.TextArea implementing KeyListener.
      - override processKeyEvent.
      - in processKeyEvent if the user types in a VK_TAB then consume
      the event and call TextArea.insert(" ", getCaretPosition());
      - run the code and type in bunch of text including a couple
      of VK_ENTER's.
      - Go the the second line, first column and type a VK_TAB.
      - the 4 spaces will get inserted incorrectly.

      NOTE: same problem using getStartPosition() and getEndPosition()

      EXAMPLE:
          protected void processKeyEvent(KeyEvent e)
          {
              if (e.getKeyCode() == KeyEvent.VK_UNDEFINED // KEY_PRESSED
              && e.getKeyChar() == KeyEvent.VK_TAB)
              {
                  // insert 4 spaces at the current caret position
                  insert(" ", getCaretPosition());
                  e.consume();
              }
          }




      ======================================================================

            Assignee:
            Eric Hawkes (Inactive)
            Reporter:
            Sheri Good (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: