FXMisc / Flowless

Efficient VirtualFlow for JavaFX
BSD 2-Clause "Simplified" License
185 stars 38 forks source link

Keyboard paging computation error while paging up #73

Closed Jugen closed 4 years ago

Jugen commented 4 years ago

This is from RichTextFX issue 935

Replicate

  1. Run the following JavaFX application, which uses RichTextFX:

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.ScrollPane;
    import javafx.stage.Stage;
    import org.fxmisc.flowless.VirtualizedScrollPane;
    import org.fxmisc.richtext.StyleClassedTextArea;
    
    public class Pagination extends Application {
      public static void main( final String[] args ) {
        launch( args );
      }
    
      @Override
      public void start( final Stage stage ) {
        final var editor = new StyleClassedTextArea( false );
        final var scrollbars = new VirtualizedScrollPane<>( editor );
    
        scrollbars.setVbarPolicy( ScrollPane.ScrollBarPolicy.ALWAYS );
        editor.setWrapText( true );
    
        stage.setScene( new Scene(scrollbars) );
        stage.show();
      }
    }
  2. Copy multiple text paragraphs (e.g., https://www.lipsum.com/feed/html).
  3. Paste the text 5 times (to ensure the scrollbar extends).
  4. Do not resize the window (you can, but it'll mean more steps; if you did, start over): small-window
  5. Press Ctrl+Home to navigate to the top of the document.
  6. Press Ctrl+End to navigate to the bottom of the document.
  7. Press and hold Page Up to navigate upwards.

Expected Results

The view port navigates back one page for as long as the key is held, or the top is reached.

Actual Results

The computation for the new caret position goes awry in a variety of ways, depending on how much text is pasted and the view port size, resulting in one of the following behaviours: