-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support multi range selection #41
Comments
Copied from my post in the thread: I think thought should go into an API that supports non-contiguous selections without (Obvious disadvantages disadvantages of this approach include a) |
@ehsan @masayuki-nakano @MatsPalmgren There was a discussion about this in December on Mozilla's dev-platform list, so I'm CCing some of the involved parties to alert them to the API idea I outlined in the previous comment. Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1323681 |
An enumeration of text nodes seems a bit awkward to work with for use cases that want to do something to elements in the selection, but perhaps it works for most cases. What worries me with returning an array though is the issue of DOM mutations, let's say the user made this (multi-range) selection: A callback approach seems better in that respect, something like this perhaps: Perhaps we could also support a selector to make it easier to work with selected elements? If we invent some selector for text nodes we would get something like your proposal, except the caller doesn't have to deal with mutations (in most cases): There might be better alternatives like ES6 generators/iterables or something. Like, I think the primary requirements for a new API should be (in no particular order):
I think the last point is important to persuade web developers to use the new API instead of what they are currently doing, which is crucial for solving this problem. |
The problem is that it's impossible to create an API that adopts to DOM mutations as expected expect the simplest of the simplest of the case. For example, what if the script removed the entire text node from |
Hmm, I don't understand why you say this is impossible or not specified. It's been implemented in Gecko for decades. Here's a simple demo: It is very well specified how this should work: |
Yes, it's very well specified. The problem is that that specified behavior doesn't work as (author) expect in many cases when elements are moved around for editing purposes. Also, when one of the ranges are modified. For example, let's say we have multiple ranges like: |
Right, I'm not claiming it preserves the selection for every DOM mutation you throw at it. I'm just saying it's implemented and well defined in a spec. I think your API hands over the complexity of mutations to the web developer and I don't think this is an edge case we can ignore - if they do mutations then the |
@MatsPalmgren Sorry if I was unclear. I meant the list should contain 1) nodes, and 2) partially-selected CharacterNodes. I would also want the list to be live, as Ranges currently are, not a static array. A method that takes a callback would also work, but a list-like structure would be more flexible if we supported all array methods (like forEach but also filter, etc.). Then you don't need to have a special-cased selector argument, you can do selectedNodes.filter(n => n.matches ? n.matches("...") : false).forEach(...), and any other filtering or other operations you like. @rniwa This isn't a problem with the proposed API, it's orthogonal. If authors want to implement an editor, more APIs will be needed, such as to split up elements while preserving the selection properly. |
@ayg OK, then I misunderstood your proposal, I thought you meant a static array. |
NodeLists are live, so I'd assume this should be implementable as well. In practice it could be implemented as an iterator that secretly looks at the underlying Ranges, I would think. |
As Google Chrome, we are interested in supporting multiple range. |
I proposed new multiple range API at TPAC(discussion log). |
Somehow related, just opened these to see what happens https://bugs.webkit.org/show_bug.cgi?id=186465 |
See https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0098.html
The text was updated successfully, but these errors were encountered: