Skip to content

Non-invasive way of making highlights - maybe with an overlay? #291

@csillag

Description

@csillag

Currently, we are making highlights by wrapping SPANs around text elements.
This can cause problems, if the page has some active code, which tries to work with the same text elements later.

For example, take this example:

  • There is a P element, with the following text: "This page has been seen by 10 people."
  • We create an annotation around "has been", thereby cutting the original text element into three parts, and replacing the middle one with a SPAN, containing the text.
  • Then the page would like to replace the original content with this: "This page has been seen by 11 people."
  • Since the page assumes that the P element has only one child, the text element, it will probably simply use firstChild to find the element, and overwrite in it's value. Which, in our case, will result in this: "This page has been seen by 11 people.has been seen by 10 people."

There can be many similar unintended consequences.

Ideally, it would be great to add highlights without disturbing the original DOM any more than necessary.

Here is a way we could do in, in theory:

  • Add a div, which would be positioned to cover exactly the same area as the root element
  • Use this div as a layer above the original content
  • Instead of working with the "real" content of the DOM, draw our highlights over this new layer, laid over the original content.

From the user's point of view, this would be indistinguishable from what we have now. However, we could totally (well, almost totally) abstain from touching the DOM! That also means we could stop slicing and dicing the text nodes, which has been proven to be a huge pain point, at least for me.

What do you think?

btw, I think PDF.js is doing something similar for selection: they have a canvas for actually drawing the content of the PDF, and different DIV laid over the canvas, which is only used for selection.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions