Anchored passages
An extension that needs to attach something to a passage of the text of a part (the Conlang Translator keeps the English source of a translated speech; a glossary plugin could keep a hint) does not have to follow the text itself. The core already does that for the annotations of the author, and since 1.7.0 it does it for any kind of passage: the offsets move through the author's edits, the passage is found again by its quote when the part is generated again, goes with a merge, is copied to a branch, goes to the trash and to backups.
A passage of an extension is a row of AnchoredPassage (the table of the annotations, see the model) with a
passageKind, the id of your kind, and your data in getAttributes():
PassageService passages; // @Autowired
AnchoredPassage passage = passages.createFromQuote(book, part, "my-plugin.gloss", quote, before, after);
passage.getAttributes().addProperty("source", "Hello there"); // your data, under your own keys
passages.save(passage);
-
create(book, part, kind, start, end)(offsets of the stored text, white space at the edges is left out) orcreateFromQuote(a quote that is not found makes a passage of the whole part withisNotLocated());listForPart/listForManuscript(a kind, ornullfor all the kinds of the extensions);reattach,remove. -
The range is
getStart()/getEnd()of the stored text of the part, which is also what the author edits; the text a model reads may be another one, see The text a model reads (ModelTextmaps the ranges). -
listForParts(partIds, kind)reads the passages of many parts with one query and no manuscript, for code that holds the parts already (the text a model reads: a story of hundreds of parts must not cost a query per part). -
A passage whose text is gone is
isOrphaned()with no range; it is found again if the text comes back. -
Passages are not annotations: the badge of the part, the annotations tab and the margin list only the editorial notes, and the commands of the annotations see only those. Nothing to resolve or dismiss.
The kind
Register a PassageKind in PassageKinds when the extension loads and unregister it when it unloads. The passages of a kind that is not
registered stay in the data and are not shown.
StoryAnnotations (the annotations a story tab keeps) loads the passages of the registered kinds once for the book, only while some kind is registered,
and puts their marks into the text together with the marks of the annotations.
Tests: PassageServiceTest, StoryAnnotationsTest, FlywayMigrationTest.upgradesV25AnnotationsThroughTheV26TableRebuild.