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

Wrong character insertion index on multi-line paragraphs when caret positioned at end of line-wrap #423

Closed
JordanMartinez opened this issue Jan 16, 2017 · 4 comments · Fixed by #572
Labels

Comments

@JordanMartinez
Copy link
Contributor

Line 1 text|
^Line 2 text
*Line 3 text

In a multi-line paragraph of at least 3 lines (above diagram), where | represents the initial caret position, it is expected that pressing DOWN arrow key will move caret to ^, but it actually moves it to *.

Additionally, pressing UP arrow key will not move the caret at all. Once one presses LEFT or RIGHT arrow key (i.e. press left, then right to reposition the caret at *), UP works again.

Run the code to reproduce the bug.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

public class DownLinesBug extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        String _3LinesOfText = "Some long amount of text to take up a lot of space in the given area.";
        InlineCssTextArea area = new InlineCssTextArea(_3LinesOfText + "\n" + _3LinesOfText);
        area.setWrapText(true);
        VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);

        area.moveTo(0, 27);

        Scene scene = new Scene(vsPane, 200, 400);
        primaryStage.setScene(scene);
        primaryStage.show();

        // press [DOWN] Key arrow to reproduce bug
    }
}
@JordanMartinez
Copy link
Contributor Author

This also occurs when pressing UP arrow key in this specific situation

Line 1 text^
*Line 2 text|
Line 3 text

where | represents the initial caret position, ^ is the expected new position and * is the actual new position.

@JordanMartinez
Copy link
Contributor Author

There's another situation in which this issue occurs, which points to TextFlowExt#hit(double, double) as the issue (or the underlying textLayout().hit(float, float) method call.

Paragraph 1's 1st line of text before^    ~|
*paragraph gets wrapped around the space   |
anotherReallyLongWord                      |

Given the above text, where | represents the right boundary of the area, clicking the mouse at ~ should position it at ^ but positions it at * in reality.

@JordanMartinez JordanMartinez changed the title downLines bug in multi-line paragraph Wrong character insertion index on multi-line paragraphs when caret positioned at end of word-wrap Jan 24, 2017
@JordanMartinez JordanMartinez changed the title Wrong character insertion index on multi-line paragraphs when caret positioned at end of word-wrap Wrong character insertion index on multi-line paragraphs when caret positioned at end of line-wrap Jan 24, 2017
@JordanMartinez
Copy link
Contributor Author

I wrote a TestFX test for this using NavigationTests.MultilineTests's setup. Turns out, this problem only occurs when the paragraph uses a non-monospace font.

@JordanMartinez
Copy link
Contributor Author

JordanMartinez commented Jun 23, 2017

Line 1 text|
Line 2 text^
*Line 3 text

Although the caret should be positioned at ^, it's positioned at *. If I modified the code somehow to make the caret appear at ^, it would cause the caret to appear at * when the wrapped lines' contents use a monospace font and happen to line up perfectly as they do in NavigationTests.MultilineTests.

Also, the caret is in the correct location (the end of the second line), even if it does not visually appear so:

Line 1 text| Line 2 text^ *Line 3 text

I think the real problem here is that pressing UP after pressing DOWN does not then move the caret. If this could be fixed, I think this bug should be closed.

@JFormDesigner your thoughts?

JFormDesigner pushed a commit to JFormDesigner/RichTextFX that referenced this issue Sep 5, 2017
JordanMartinez added a commit that referenced this issue Sep 6, 2017
fixed caret positioning in wrapped lines (issue #423)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant