On 2014-04-22 13:54, Nick Stenning wrote:
> Hmm. I'm not inclined to move the text selection back into Annotator
> core, as I rather like the fact that the adder provides one
> interpretation of how a selection translates to an annotation, and
> others might have other interpretations (for example, limiting the
> granularity of a selection to a sentence or paragraph). Others might
> have entirely different interfaces, and might be annotating different
> media types (audio, imagery, video).

Here is what we have in our fork:

 * When some UI code detects (for example, checkForEndSelection
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/textanchors.coffee#L109>,
called by mouse up) that there is a new selection, it does the bare
minimum to capture that selection somehow (without creating an
annotation out of it),tosses it inside the event
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/textanchors.coffee#L133>
(in a field randomly named segments), adds a "type" field to it ("text
range" in the default case), and then calls core's
onSuccessfulSelection() method.
 * This onSuccessfulSelection
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/enhancedanchoring.coffee#L763>
method then tries to build targets from the segments passed inside the
events, by asking the registered selector creators, which try to
describe the segments with some kind of serializable data structure.
(For example, by serializing the range
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/textrange.coffee#L56>,
if we are talking about text selections, but there are many other
possibilities, too.)
 * When all the promises returned by selector creators have finished
(and so we have a target, described by selectors), we store the target
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/enhancedanchoring.coffee#L780>,
and then show the adder button
<https://github.com/hypothesis/annotator/blob/shoot-packaging-1/src/plugin/enhancedanchoring.coffee#L790>.

This process is generic; it is applicable for different media types, for
different selection UI interactions, for different kinds of segments,
for different selectors, etc.