Flowless icon indicating copy to clipboard operation
Flowless copied to clipboard

Unexpected Scrolling Behavior in CodeArea when pressing enter at first line

Open Symeon94 opened this issue 7 months ago • 1 comments

Hello,

This is an issue which I have found in the RichTextFX library, but it is likely due to the Flowless library. I have documented in this issue the problem: https://github.com/FXMisc/RichTextFX/issues/1276

In short, I'm encountering an issue with CodeArea when using LineNumberFactory. Pressing Enter while scrolled to the top causes unexpected scrolling behavior. This is likely due to the way Navigator behaves when scrolling down from first line (there are details in the other issue).

I'll be posting further findings in both locations.

Thank you in advance, Syméon

Symeon94 avatar May 21 '25 12:05 Symeon94

The problem seems to be with ground being set to 1 in fillViewportFrom:

private void fillViewportFrom(int itemIndex) {
    int ground = fillTowardsGroundFrom0(itemIndex); // Set to 1 (itemIndex is the selected line after pressing enter 1,2,3,...)
    //…
    int first = Math.min(ground, sky);
    // ...
    firstVisibleIndex = first; // Should be 0, but it is 1 for itemIndex == 1
    lastVisibleIndex = last;
    positioner.cropTo(first, last + 1);
}

This comes from the following method which will receive as argument (1, 0.0) and output 1 for first line and (2, 0.0) for second and output 0.

It is not clear why the first case return 1 (and I have the impression it is being called multiple times).

int fillBackwardFrom0(int itemIndex, double upTo) {
    double min = orientation.minY(positioner.getVisibleCell(itemIndex));
    int i = itemIndex;
    while(min > upTo && i > 0) {
        --i;
        C c = positioner.placeEndFromStart(i, min);
        min = orientation.minY(c);
    }
    return i;
}

Symeon94 avatar May 21 '25 14:05 Symeon94