harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
37 stars 30 forks source link

Fix elisions in reading mode by moving DOM modifications later #1887

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

I thought this was complicated but it was simple, and it is because I did something silly.

Before

Note the elision placement at the end of the paragraph (this is correct):

image

Reader view was placing the elision off into the middle of the next paragraph:

image

After

image

Offset calculations for annotations in reading mode are represented as Ranges, which can be computed before a document tree is inserted into the DOM. Doing it this way means I don't have to account for newly-inserted notes changing the offsets, or for repaint events. Only when all the ranges are calculated in memory does the code walk through and start inserting or eliding nodes.

HOWEVER, at some point I added code that inserted footnote nodes for use in the print output, and I put that before the range calculation instead of afterward, and then missed the regression because there weren't yet tests. I'll add tests for this soon. In this fix I moved it after the range calcs and also inside a block that applies only to PagedJS because it's unnecessary work in reading mode.

Also: