I currently have a TextFlow, putting Text Nodes and other types of nodes into it, I'm trying to make the text selectable using mouse and key events, but the methods setSelectionStart and setSelectionEnd don't seem to behave the way they should, like it works fine for the first Text node but not for others
Here is a minimal reproducible example :
@Override
public void start(Stage ps) {
TextFlow flow = new TextFlow();
flow.setPadding(new Insets(10));
Text t1 = new TextNode("first ");
Text t2 = new TextNode("second ");
Text t3 = new TextNode("third");
t1.setSelectionStart(2);
t1.setSelectionEnd(6);
t2.setSelectionStart(0);
t2.setSelectionEnd(4);
flow.getChildren().addAll(t1, t2, t3);
ps.setScene(new Scene(flow,400,300));
ps.show();
}
private class TextNode extends Text {
public TextNode(String s) {
super(s);
setFont(Font.font(18));
setSelectionFill(Color.RED);
}
}
I'm basically creating a TextFlow and inserting 3 Text nodes into it, i want to be able to make a selection across the first and second Text nodes, but it's not working, see the screenshot below
The docs indicate that
When a Text node is inside of a TextFlow, some of its properties are ignored
But I don't seem to find the correct approach to make a continuous selection across Text nodes, note that i can't join them in a single Text node because there could be a non-text node between them, any help would be appreciated.