RichTextFX icon indicating copy to clipboard operation
RichTextFX copied to clipboard

Bug: text area removes selection on text append

Open PavelTurk opened this issue 8 months ago • 10 comments

This is my code:

public class JavaFxTest8 extends Application {

   @Override
    public void start(Stage primaryStage) {
        var codeArea = new CodeArea("Some text is here.");
        var button1 = new Button("Jmi");
        codeArea.selectedTextProperty().addListener((ov, oldV, newV) -> System.err.println(newV.length()));

        button1.setOnAction(e -> {
            codeArea.appendText("Appended text");
        });

        Scene scene = new Scene(new VBox(codeArea, button1), 400, 200);
        primaryStage.setScene(scene);
        primaryStage.show();
        codeArea.selectRange(0, 4);
    }

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

If you click the button, then selection will be removed. I consider it is a bug because text appending have nothing with text selection. I tried to save selection and restore it after text appending but then I get two events in selectedTextProperty. So, one problem leads to another.

PavelTurk avatar Jun 03 '24 08:06 PavelTurk