1. 27 Sep, 2021 2 commits
  2. 22 Sep, 2021 4 commits
  3. 20 Sep, 2021 7 commits
  4. 16 Sep, 2021 3 commits
    • Eduardo's avatar
      Minor improvements following PR feedback · 9e4a4717
      Eduardo authored
      * check that the iframe's `src` element is not 'about:blank'.
      * use EventTarget class and fake DOM element for tests
      * fix typos
      9e4a4717
    • Eduardo Sanz García's avatar
      Complete testing of the onDocumentReady function · 8575eb96
      Eduardo Sanz García authored
      I removed the `/* istanbul ignore test */` and created a facade to
      emulate and iframe for testing.
      8575eb96
    • Eduardo Sanz García's avatar
      Improve the logic that checks for iframe's document ready · 919e5bf1
      Eduardo Sanz García authored
      In certain situations, the logic to check when the iframe's document is
      ready didn't work as expected. The reason for that is that browsers
      create an initial blank document before the actual document loads.
      This blank document has a `readyState` of 'complete' in Safari and
      Chrome and of 'uninitialized' in Firefox. This blank document can be
      mistaken by the final document. I was able to reproduce a situation
      where the Hypothesis client was injected into the blank document. Then,
      the blank document was replaced by the actual document and the
      Hypothesis client was not not longer embedded.
      
      In addition, this commit:
      
      * renames `frame` to `iframe` (only in the test)
      * renames `_handledFrames` to _annotatableFrames`
      * removes `isAccessible` (no longer neede)
      919e5bf1
  5. 15 Sep, 2021 5 commits
    • Robert Knight's avatar
      Tweak comment · f7f8e24f
      Robert Knight authored
      Add commas for readability
      Co-authored-by: 's avatarLyza Gardner <439947+lyzadanger@users.noreply.github.com>
      f7f8e24f
    • Robert Knight's avatar
      Prevent sidebar controls overlapping scrollbar in PDFs · 32cea8cc
      Robert Knight authored
      When the sidebar is closed or there is not enough room to show the
      sidebar alongside the PDF content, reserve space for the sidebar's
      toolbar and bucket bar. This fixes an issue where the sidebar's controls
      would overlap the document's scrollbar, making scrolling the PDF less
      convenient, especially in long documents.
      
      This also removes the need for some CSS overrides that reposition
      elements in PDF.js's toolbar. By ensuring that the `<body>` does not
      overlap the sidebar controls, the PDF.js toolbar which is contained
      within the body doesn't either.
      
      Fixes #3759
      32cea8cc
    • Robert Knight's avatar
      Remove vestigial `undefined` from map value type · 4ecde083
      Robert Knight authored
      This is no longer needed after the `Record<K, V>` => `Map<K, V>` change.
      4ecde083
    • Robert Knight's avatar
      Fix map lookup · e822a31c
      Robert Knight authored
      I expected TypeScript to generate an error for this obvious mistake, but
      it seems that this only happens if `noImplicitAny` is enabled.
      e822a31c
    • Robert Knight's avatar
      Use maps for PDF text and anchoring caches · ecb9b47c
      Robert Knight authored
      Using maps is a little faster and avoids the need for `hasOwnProperty`
      checks. The quote position cache has been converted to a single level
      map as this is more ergonomic to work with and the second level maps
      almost always had exactly one entry in them.
      ecb9b47c
  6. 14 Sep, 2021 10 commits
  7. 13 Sep, 2021 9 commits
    • Robert Knight's avatar
      Refactor `strippedHint` initialization · 904810bd
      Robert Knight authored
      Combine two separate if blocks into one.
      904810bd
    • Robert Knight's avatar
    • Robert Knight's avatar
    • Robert Knight's avatar
      Check for context match before stopping search early · 0d193d1f
      Robert Knight authored
      To reduce the chances of mis-anchoring quotes, check for a context match
      before stopping early. This helps when the quote is a word or phrase
      that is common in the document and the position hint is wrong, which can
      occur if the quote selector was created when using a different PDF
      viewer or version of PDF.js, which exacts text differently.
      
      For quotes captured at the start or end of a page we expect a mismatch
      in the prefix and suffix respectively because quote selectors can currently
      capture parts of the surrounding pages / DOM in `describe`, but when
      anchoring we only search for matches in one page of text at a time.
      0d193d1f
    • Robert Knight's avatar
      Add a detailed test of PDF anchoring's use of `matchQuote` · a8c3e38e
      Robert Knight authored
      We have a basic test of quote matching from the perspective of the
      `anchor` caller, but we really need to check the data passed to the
      quote matching logic in more detail.
      a8c3e38e
    • Robert Knight's avatar
      Find best match for quote selectors across all pages ignoring whitespace · 96ecd3b3
      Robert Knight authored
      As described in #3705, stopping a quote search as soon as we find an
      approximate match could result in quotes anchoring to suboptimal matches
      if the position selector is no longer accurate.
      
      We want to balance finding the best match against making the search
      efficient in long documents. The approach taken in this commit is to
      continue to search pages in priority order, but instead of returning the
      first "good enough" match (below `matchQuote`'s error threshold), return
      the first exact match ignoring whitespace differences, or the nearest
      match in the whole document otherwise.
      
      We ignore whitespace differences because this is the main change between
      the current version of PDF.js that we include in Hypothesis products, and
      newer versions that we are trying to migrate to (see #3687). It is also
      likely to be the main source of text differences between PDF.js and
      other viewers.
      
       - Change `anchorQuote` to ignore whitespace differences when searching
         for approximate matches
       - Change `anchorQuote` to keep searching for the best match if it does
         not find a whitespace-insensitive exact match in the current page
       - Add tests for whitespace changes
      
      Fixes https://github.com/hypothesis/client/issues/3705
      96ecd3b3
    • Robert Knight's avatar
      Improve tests for invalid position selectors · bd223ffc
      Robert Knight authored
      Add tests to cover the cases where the position is on a page before the
      quote and where the position is negative.
      bd223ffc
    • Robert Knight's avatar
      Refactor and optimize quote anchoring in PDFs · d061e027
      Robert Knight authored
      Refactor quote anchoring logic to use async/await instead of Promise
      chains to make control flow easier to follow and change.
      
       - Convert `getPageOffset` and `findPage` helper functions to use
         async/await rather than Promise chains.
      
       - Combine the `prioritizePages` and `findInPages` functions into a
         single `anchorQuote` function.
      
         Combining the two functions allows some redundant work to be
         eliminated. `findInPages` used to call `getPageOffset` for the
         current page on each iteration which would in turn fetch the text of
         every page until it reached the given offset. `prioritizePages` would
         do a very similar loop in order to enumerate pages close to the given
         offset.
      
       - Replace use of `TextQuoteAnchor.fromSelector` with direct use of
         `matchQuote`. `fromSelector` wasn't providing any value over just
         calling `matchQuote` directly, and it required a dummy DOM element to
         be created and have its text populated.
      d061e027
    • Eduardo Sanz García's avatar
      Run `make format` for the latest prettier version (2.4.0) · 1ec83a57
      Eduardo Sanz García authored
      In scss files, `@use "..."` has been replaced by `@use '...'" (single
      quotes instead of double).
      1ec83a57