Skip to content

Commit

Permalink
Fix cursor misalignment in SearchField when left node is present
Browse files Browse the repository at this point in the history
When a left-side node is added to the SearchField component, clicking inside the text field does not position the cursor correctly. This commit overrides the getIndex method in SearchFieldEditorSkin to adjust the x-coordinate by subtracting the width of the left node before invoking the superclass method. This correction ensures that the cursor accurately reflects the user's click position within the text field, even when a left node is present.
  • Loading branch information
leewyatt committed Oct 25, 2024
1 parent 07202ca commit ae9722e
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.TextField;
import javafx.scene.control.skin.TextFieldSkin;
import javafx.scene.layout.StackPane;
import javafx.scene.text.HitInfo;
import javafx.scene.text.Text;

import java.util.Optional;
Expand Down Expand Up @@ -207,4 +208,11 @@ protected void layoutChildren(double x, double y, double w, double h) {
Math.max(0, Math.min(autoCompleteWidth, w - autoCompletionX)),
h);
}

@Override
public HitInfo getIndex(double x, double y) {
final double leftWidth = leftPane == null ? 0.0 : snapSizeX(leftPane.prefWidth(getSkinnable().getHeight()));
return super.getIndex(x - leftWidth, y);
}

}

0 comments on commit ae9722e

Please sign in to comment.