Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8282290

TextField Cursor Position one off

XMLWordPrintable

    • b21
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Archlinux with Linux 5.16.1-arch1-1

      openjdk version "11.0.14.1" 2022-02-08 LTS
      OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
      OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)

      javafx 17.0.2

      The problem also occurs on Windows and MacOS although I lack precise version numbers.

      A DESCRIPTION OF THE PROBLEM :
      When pasting a word into a TextField after the mouse clicked at the end of the TextField, the cursor is placed at the wrong position.

      I have no deep insights into JavaFX but maybe these pointers are helpful:

      javafx.scene.control.skin.TextFieldSkin.updateTextNodeCaretPos() sets the cursor to the wrong position as isForwardBias() is false and the position is different from 0.
      javafx.scene.control.skin.TextFieldSkin.positionCaret() is called upon the mouse click and ends up modifying the forwardBias property.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program attached
      Verify the TextField has focus. Don't click it.
      Enter "1234" into the TextField
      Select the text via keyboard shortcut (Ctrl-A for me)
      Copy to Clipboard (Ctrl-C)
      Paste from Clipboard (Ctrl-V). Verify normal behaviour
      Left mouse click into the TextField to the right of the text, like intending to place the cursor to the end of the text although it's already there
      Select the text via keyboard shortcut (Ctrl-A)
      Paste from Clipboard (Ctrl-V)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The cursor is at the end of the pasted text.
       
      Follow-Up:
      Pushing the keyboard right-arrow key should now move the cursor to the right
      Pushing the keyboard left-arrow key should now move the cursor to the left
      ACTUAL -
      The cursor is one character left of the end of the pasted text.

      Follow-Up:
      Pushing the keyboard right-arrow key doesn't move the cursor
      Pushing the keyboard left-arrow key shows no effect on first pushing. Further pushing moves it to the left and also undoes the wrong behaviour, so selecting and pasting again behaves well until the mouse clicks again.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;

      public class Login extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          @Override
          public void start(Stage primaryStage) {
              GridPane grid = new GridPane();
              grid.setAlignment(Pos.CENTER);
              grid.setHgap(10);
              grid.setVgap(10);
              grid.setPadding(new Insets(25, 25, 25, 25));

              TextField userTextField = new TextField();
              grid.add(userTextField, 1, 1);

              Scene scene = new Scene(grid, 300, 275);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Login.java
          0.8 kB
          Praveen Narayanaswamy
        2. TestInputEvent.java
          3 kB
          Praveen Narayanaswamy

            kpk Karthik P K
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: