-
Notifications
You must be signed in to change notification settings - Fork 39
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
Interleaving selections within the DOM #47
Comments
@BigBlueHat You're thinking here about sections that can be described by element boundaries, but not arbitrary indexing (character-by-character) into texts, right? |
@ajs6f arbitrary indexing. |
@ajs6f mainly selections that traverse multiple element boundaries--i.e. selecting part of A and part of B. Trees don't do that so good. |
This seems pretty challenging. I did some work in a similar area years ago but it was simple and text-only, and it wasn't completely trivial. Is this really meant for text (or text-y) documents, or anything that could be addressed by the DOM (SVG, other things like that)? |
Originally posted this as a separate issue in #78 (but closing and moving here to keep @Treora sane 😉):
|
Since recently we have a simple highlighter, which wraps text nodes in Note there is a difficulty with how a Range behaves when the DOM is modified: running highlight with our current highlighter can mess up other Range objects that point at the same text nodes. So this can cause trouble:
A solution is to anchor&highlight as a single action: considering the Range a ephemeral pointer:
Our generator-based approach to anchoring should help to do this right, but still it is a pitfall that I’m not very happy with. Some ideas for avoiding this problem:
For the time being, or if we decide not to fix this, we should probably warn users in any documentation and examples that Ranges are perishable. Note that the behaviour of Range actually differs between the current jsdom and web browsers, so it is important to run relevant tests in a browser (use our On the bright side, I added tests to check if one can remove highlights in arbitrary order, and that seems to work as intended. This should give the freedom to ignore the tree structure and treat highlights as being independent from each other. Please suggest/write other scenarios that we should include in our tests. |
Finding selections within the DOM and even wrapping them in an element is easy enough, and most developers just "roll their own" highlighter/selector for things like that--hence, they don't "shop" for tools like Apache Annotator for that.
However, juggling interleaved selections in the DOM is tricky and not standardized.
The DOM is a tree. Selections point at regions all over that tree, often intermixed.
We should build tooling to handle that interleaving to manage the display, removal, eventing, etc, for such selections.
See also #45 and #22.
Example:
id
--which conceptually "relates" them as a unit, but the DOM doesn't work that way.<mark/>
elements would need shared events, display, removal, etc.Solving this (or even just exploring it) is something developers know they need, so likely it should be near the top of our list to solve. 😄
The text was updated successfully, but these errors were encountered: