Skip to content

fixed caret positioning in wrapped lines (issue #423)#572

Merged
JordanMartinez merged 2 commits intoFXMisc:masterfrom
JFormDesigner:caret-positioning-fix
Sep 6, 2017
Merged

fixed caret positioning in wrapped lines (issue #423)#572
JordanMartinez merged 2 commits intoFXMisc:masterfrom
JFormDesigner:caret-positioning-fix

Conversation

@JFormDesigner
Copy link
Copy Markdown
Contributor

This PR fixes some issues with caret positioning in wrapped lines:

  1. pressing DOWN key at end of line now moves caret to end of next line (and not beginning of line after next line).
    E.g. if caret is at | then DOWN key moves it to ^ (and not * as before).
01234|
678^
*01
  1. UP key now always works as expected (and no longer "locks" at * as before)

  2. when clicking with the mouse after text in a wrapped line (e.g. right to ^), then the caret is now positioned at the end of the hit line (and not at the beginning of the next line as before)

Here is some code to reproduce:

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

public class HitWrappedBug extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        InlineCssTextArea area = new InlineCssTextArea("01234 678 01");
        area.setWrapText(true);
        area.setStyle("-fx-font-size: 30pt");
        VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);

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

I think this fixes #423


TextLine line = getLines()[lineIdx];
TextLine[] lines = getLines();
TextLine line = lines[lineIdx];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you break this up so that it's easier to read? Or is this "noise" (as some might call it) unintentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The lines variable is used in a if statement to check whether this is a wrapped paragraph 😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... I see now. Sorry, I misread it.

@JordanMartinez
Copy link
Copy Markdown
Contributor

I'll submit a PR to your repo with a test that can tell us for sure.

@JordanMartinez
Copy link
Copy Markdown
Contributor

JordanMartinez commented Sep 5, 2017

@JFormDesigner In your PR, could you add MultilineJaggerdTests (see below) into NavigationTests by following the example below?

Edit: Sorry, I said before I'd submit a PR to yours. I've pulled a local branch of yours with my test and it works. Please merge my PR to yours and then I'll merge yours here.

@JordanMartinez
Copy link
Copy Markdown
Contributor

Also, thank you for figuring out a way to resolve this. I'd tried a number of times and never got anything to work since I didn't understand the internal API for TextLayout.

@JordanMartinez JordanMartinez merged commit cd7a966 into FXMisc:master Sep 6, 2017
@JFormDesigner JFormDesigner deleted the caret-positioning-fix branch September 6, 2017 17:22
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

Successfully merging this pull request may close these issues.

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

3 participants