JDK-8282290 : TextField Cursor Position one off
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: jfx11,8,jfx17,jfx18
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-02-22
  • Updated: 2023-12-08
  • Resolved: 2023-12-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
jfx22 b21Fixed
Related Reports
Relates :  
Description
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



Comments
Changeset: 2108ecf9 Author: Karthik P K <kpk@openjdk.org> Date: 2023-12-06 03:51:34 +0000 URL: https://git.openjdk.org/jfx/commit/2108ecf9d7c8c459964a9e8b5e37485b3507b028
06-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1287 Date: 2023-11-14 10:24:20 +0000
14-11-2023

Checked with attached testcases in Windows 10 and Ubuntu 20.04, Issue is reproducible Step ==== 1 Exceution of testcase 2 Enter "1234" into the TextField 3 Select the text via keyboard shortcut(Ctrl-A) 4 Copy to Clipboard (Ctrl-C) 5 Paste from Clipboard (Ctrl-V) in the same textfielf 6 click Left mouse button on the TextField, to the right of the text((Focus)) [although focus of the cursor is to the right most] 7 Select the text via keyboard shortcut (Ctrl-A) 8 Paste from Clipboard (Ctrl-V) Test Result: ========= 8: Fail 8u321: Fail openjfx11: Fail openjfx17: Fail openjfx18ea10: Fail
23-02-2022

might be related to JDK-8248914
23-02-2022