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

GenericStyledArea.requestFollowCaret() does not show selection outside area on the right #1058

Closed
appsofteng opened this issue Dec 3, 2021 · 3 comments · Fixed by #1059
Closed

Comments

@appsofteng
Copy link

appsofteng commented Dec 3, 2021

When a selection of text in the area is on the right side outside of the visible area and GenericStyledArea.requestFollowCaret() is called, the flow scrolls only to the start of the selection, but the selection itself remains outside on the right.
This happens when the horizontal scrollbar is more far away from the beginning.

I made this change and it works now.

Only the relevant code shown. My comment [A]

private void followCaret() {

        // ...

        double graphicWidth = paragrafBox.getGraphicPrefWidth();
        Bounds region = extendLeft(caretBounds, graphicWidth);
        double scrollX = virtualFlow.getEstimatedScrollX();

        // Ordinarily when a caret ends a selection in the target paragraph and scrolling left is required to follow 
        // the caret then the selection won't be visible. So here we check for this scenario and adjust if needed.
        if ( ! isWrapText() && scrollX > 0.0 && getParagraphSelection( parIdx ).getLength() > 0 )
        {
           // [A] visibleLeftX has a rather large value when scrollX is big. This works fine for a selection outside the area
           // on the left but keeps a selection on the right outside the area. 
            double visibleLeftX = paragrafBox.getWidth() * scrollX / 100 - getWidth() + graphicWidth;

            CaretNode selectionStart = new CaretNode( "", this, getSelection().getStart() );
            paragrafBox.caretsProperty().add( selectionStart );
            Bounds startBounds = paragrafBox.getCaretBounds( selectionStart );
            paragrafBox.caretsProperty().remove( selectionStart );

            // [A] I use this changed condition and it works for both left and right.
            // startBounds.getMinX() - graphicWidth < scrollX
            if ( startBounds.getMinX() - graphicWidth < visibleLeftX ) {
                region = extendLeft( startBounds, graphicWidth );
            }
        }

    // ...

}
@Jugen
Copy link
Collaborator

Jugen commented Dec 3, 2021

So, just to confirm that the only change needed is for visibleLeftX to be scrollX to get the desired effect, like this ?

            if ( startBounds.getMinX() - graphicWidth < scrollX ) {
                region = extendLeft( startBounds, graphicWidth );
            }

@appsofteng
Copy link
Author

Yes, I confirm.

@Jugen
Copy link
Collaborator

Jugen commented Dec 15, 2021

Okay will submit PR to fix ....

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 a pull request may close this issue.

2 participants