Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeArea in Dialog wrong caret position calculation #196

Closed
daa84 opened this issue Oct 25, 2015 · 10 comments
Closed

CodeArea in Dialog wrong caret position calculation #196

daa84 opened this issue Oct 25, 2015 · 10 comments

Comments

@daa84
Copy link

daa84 commented Oct 25, 2015

Embed CodeArea to javafx javafx.scene.control.Dialog:

CodeArea codeArea = new CodeArea();
dialog.getDialogPane().setContent(codeArea);

Then try to select portion of text - looks like cursor position a bit shifted from original one, so it is hard to point to exact symbol.

@TomasMikula
Copy link
Member

Hi, thanks for reporting. Can you provide a self-contained (a single .java file) example that reproduces the issue?

Thanks,
Tomas

@daa84
Copy link
Author

daa84 commented Oct 29, 2015

import javafx.application.Application;
import javafx.scene.control.*;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;

public class Test extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Dialog<Boolean> dialog = new Dialog<>();

        CodeArea codeArea = new CodeArea("Text\nText\nText");
        dialog.getDialogPane().setContent(codeArea);
        dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);

        dialog.showAndWait();
    }
}

Try to position cursor by mouse to first line. Align mouse cursor to center of first line and click - cursor places on second line. In non dialog mode it works ok.

@TomasMikula
Copy link
Member

Thank you, I can reproduce the problem. So it seems that dialog adds some padding to its content node and CodeArea does not compensate for it.

A workaround is to wrap codeArea in an extra node, such as a StackPane:

dialog.getDialogPane().setContent(new StackPane(codeArea));

@daa84
Copy link
Author

daa84 commented Oct 31, 2015

Thank you for workaround.

@ondrej-kvasnovsky
Copy link

Or if you really have to hack it, then you might go to StyledTextAreaView and subtract the margin (5 pixes in the following example) there... not nice solution, but a working one.

    CharacterHit hit(double x, double y) {
        double xMinusMargin = x - 5;
        double yMinusMargin = y - 5;
        VirtualFlowHit<Cell<Paragraph<S, PS>, ParagraphBox<S, PS>>> hit = virtualFlow.hit(xMinusMargin, yMinusMargin);

@TomasMikula TomasMikula added this to the 0.7 milestone Sep 16, 2016
@JordanMartinez
Copy link
Contributor

Using Linux and this version of Java

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

I couldn't reproduce this problem with the above example.
Can another check and confirm whether this case arises on a different OS?

@TomasMikula
Copy link
Member

Now I can't reproduce it either, tried also with JDK 1.8.0_40. Not sure what version I tested this before, but dialogs were only added in 1.8.0_40 I believe... Weird.

@daa84
Copy link
Author

daa84 commented Oct 10, 2016

Problem still exists on windows platform, tested with jdk 1.8.0_65

@daa84
Copy link
Author

daa84 commented Oct 10, 2016

ups, sorry, i use old richtextfx version, latest version from git work fine for me.

@daa84
Copy link
Author

daa84 commented Oct 10, 2016

in latest git version this issue fixed.

@daa84 daa84 closed this as completed Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants