![]() |
Loci in the typesetter and the editor | ![]() |
Loci are registered when they are typeset, by build_locus (env, t, ids, col, ref, anchor) in
Typeset/Concat/concat_active.cpp
. It is called for inline loci (concater_rep::typeset_locus), for loci typeset as atomic boxes (
concater.cpp
), for block loci (bridge_locus_rep::my_typeset) and for loci in the lazy typesetter (make_lazy_locus,
Typeset/Line/lazy_typeset.cpp
). It expands the body (the last argument) and evaluates the other arguments one by one:
If the body is accessible (it comes from the document rather than from a macro definition), the locus is registered under name with insert_locus. Otherwise, if the source location of the body can be decoded, the parent of the corresponding subtree of the document is registered under &name, so that the locus can still be found (the Scheme function id-update uses both forms).
The link is completed with an attribute argument (attr … "secure" flag), which records whether the document is secure (see scripts and security), and registered with insert_link. Links are registered even when the body is not accessible.
If the body is accessible and the callback is allowed (the document is secure, or the callback is declared secure), the body is registered with a Scheme callback (insert_locus (id, t, cb)).
All of this is skipped if there is no current link repository (env->link_env is null), which happens when trees are typeset outside an editor, for instance in output widgets. build_locus also returns the identifiers in ids, the destination of a url vertex in ref and the name of an id vertex in anchor, and computes the colour col of the locus: visited-color if one of its identifiers or destinations has been visited, locus-color otherwise, subject to the rules described in the link registry. The return value tells whether the body is accessible.
Since the repository belongs to the bridge being typeset (see the link registry), the consequences are:
a locus is known only once the part of the document containing it has been typeset, so id->trees finds nothing in a buffer which has been loaded but never typeset;
when a part of the document is retypeset, its loci are unregistered and registered again;
a locus whose body is generated by a macro is only found through its & identifier, and block loci with such bodies give the warning “Ignored unaccessible loci”.
For an inline locus whose body is not accessible, typeset_locus wraps the typeset material, in pieces, in locus boxes (locus_box,
change_boxes.cpp
). A locus box remembers the identifiers, the ref and the anchor:
locus_box_rep::loci (x, y, delta, ids, rs) adds its identifiers and its outline to those of the box under the point; this is how the editor finds loci which are not visible in the tree;
locus_box_rep::post_display emits a hyperlink (ren->href) and an anchor (ren->anchor) on the renderer, which the PDF renderer turns into clickable links and destinations.
For accessible loci, links are printed by box_rep::display_links (
boxes.cpp
), which is called for non-screen renderers only: it walks up from the source of a box, looks up the identifiers of each subtree with get_ids, and emits an href for every hyperlink whose target is a url.
The editor keeps two lists of identifiers (
edit_interface.hpp
):
Computed by update_mouse_loci (
edit_mouse.cpp
) when the mouse moves: the identifiers of the locus boxes under the mouse (eb->loci) and of the subtree under the mouse and its ancestors (get_ids), filtered by the Scheme functions link-mouse-ids (which drops identifiers whose only links are of type focus) and link-active-ids (which keeps identifiers which admit a link that can be followed). The outlines of the corresponding loci and of the active ancestors (link-active-upwards) are collected in locus_new_rects and drawn by the repaint code.
Computed by update_focus_loci from the cursor position: the active identifiers of the subtree containing the cursor and its ancestors.
These lists are used as follows:
a left click (without Shift and without dragging) on an active locus calls (link-follow-ids mouse_ids "click") instead of moving the cursor (mouse_select);
moving the mouse over an active locus calls (link-follow-ids mouse_ids "mouse-over"), which the preview-ref style package uses to show reference previews (preview-reference);
after each change of the cursor, the focus, the selection or the document (apply_changes, and after each key press), (link-follow-ids focus_ids "focus") is called if the editor has the keyboard focus.
The Scheme side of these calls is described in creating and following links from Scheme.