Re: [selection-api] Support multi range selection (#41)

Copied from my post in the thread:

I think thought should go into an API that supports non-contiguous selections without
making authors try to handle the non-contiguous case specially,
because they won't.  Exposing a list of selected nodes/parts of
CharacterData nodes is a possibility that has occurred to me -- like
returning a list of SelectedNodes, where SelectedNode has .node,
.start, and .end properties, and .start and .end are null unless it's
a partially-selected CharacterData node, and no node is in the list if
it has an ancestor in a list.  So "fo[o<b>bar<i>baz</i></b>]quuz"
would expose [{node: "foo", start: 2, end: 3}, {node: <b>, start:
null, end: null}, {node: "quuz", start: 0, end: 0}] as the selected
nodes.  Then authors would use it by iterating over the selected
nodes, and non-contiguous selections would be handled automatically.
I once thought over some use-cases and concluded that a lot of them
would Just Work for non-contiguous selections this way -- although
doubtless some cases would still break.

(Obvious disadvantages disadvantages of this approach include a)
authors will still continue using the old API, and b) calculating the
list might be somewhat expensive.  (a) might be mitigated by the fact
that it's easier to use for some applications, particularly
editing-related ones -- it saves you from having to walk through the
range yourself.)

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/selection-api/issues/41#issuecomment-70374142

Received on Saturday, 17 January 2015 16:59:30 UTC