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

Fix flickering on text selection #17923

Merged
merged 1 commit into from May 14, 2024

Commits on May 14, 2024

  1. Fix flickering on text selection

    When seleciting on a touch screen device, whenever the finger moves to a
    blank area (so over `div.textLayer` directly rather than on a `<span>`),
    the selection jumps to include all the text between the beginning of the
    .textLayer and the selection side that is not being moved.
    
    The existing selection flickering fix when using the mouse cannot be
    trivially re-used on mobile, because when modifying a selection on
    a touchscreen device Firefox will not emit any pointer event (and
    Chrome will emit them inconsistently). Instead, we have to listen to the
    'selectionchange' event.
    
    The fix is different in Firefox and Chrome:
    - on Firefox, we have to make sure that, when modifying the selection,
      hovering on blank areas will hover on the .endOfContent element
      rather than on the .textLayer element. This is done by adjusting the
      z-indexes so that .endOfContent is above .textLayer.
    - on Chrome, hovering on blank areas needs to trigger hovering on an
      element that is either immediately after (or immediately before,
      depending on which side of the selection the user is moving) the
      currently selected text. This is done by moving the .endOfContent
      element around between the correct `<span>`s in the text layer.
    
    The new anti-flickering code is also used when selecting using a mouse:
    the improvement in Firefox is only observable on multi-page selection,
    while in Chrome it also affects selection within a single page.
    
    After this commit, the `z-index`es inside .textLayer are as follows:
    - .endOfContent has `z-index: 0`
    - everything else has `z-index: 1`
      - except for .markedContent, which have `z-index: 0`
        and their contents have `z-index: 1`.
    
    `.textLayer` has an explicit `z-index: 0` to introduce a new stacking context,
    so that its contents are not drawn on top of `.annotationLayer`.
    nicolo-ribaudo committed May 14, 2024
    Configuration menu
    Copy the full SHA
    6f2e4d0 View commit details
    Browse the repository at this point in the history