The text selection of a document session: an anchor and a focus caret in reading order, possibly on different pages, driven by press-drag, double- and triple-click, select-all and keyboard moves, read back as quads per page for the shell to draw and as text to copy. Pointer coordinates come from TryGetPageAt(in Viewport, Double, Double, out PagePoint) (PagePoint, default user space), so the selection is independent of zoom, rotation and layout mode.
public sealed class TextSelection
ISO 32000-2 §9.4.4, §14.8.2.5 (reading order), §14.9.4 (replacement text). Spec #33 viewer capability 4. A page takes part once its selectable text is loaded (LoadPageAsync(Int32, CancellationToken)); gestures on a page not loaded yet do nothing. Begin(in PagePoint, SelectionGranularity), Extend(in PagePoint), Move(SelectionMove, Boolean) and GetQuads(Int32, Span<Quad>) allocate nothing, so a shell calls them on every pointer move. Not thread-safe: drive it from the UI thread; loading may run anywhere.
kind:method, kind:property, kind:ctor. Press Esc to clear.TextSelection(DocumentSession, IReadingOrderProvider?)Creates an empty selection over a session's pages.TextSelection(DocumentSession)Creates an empty selection over a session's pages, in the layout tree's reading order.AnchorGets where the selection started: the end that stays put while it extends.EndGets the position after the last selected glyph.FocusGets where the selection ends: the end a drag or a keyboard move changes (the caret).GranularityGets the granularity of the gesture that made the selection.IsEmptyGets whether nothing is selected.ReadingOrderGets the reading order the selection follows.SessionGets the session.StartGets the first selected position in reading order.Begin(in PagePoint, SelectionGranularity)Starts a selection at a point: a press (Character: an empty selection at the nearest caret), a double-click (the word there) or a triple-click (the line or paragraph there).Clear()Selects nothing.Extend(in PagePoint)Extends the selection to a point (a drag): the focus moves to the nearest caret, or, after a double- or triple-click, to the far edge of the word or line there while the first one stays selected.FindLink(in PagePoint)Gets the link under a point, for hover feedback (a hand cursor) and activation.GetQuads(Int32, Span<Quad>)Gets the quads to highlight on a page, in its default user space (GetPageTransform(in Viewport, Int32) maps them to the viewport).GetTextAsync(CancellationToken)Gets the selected text in reading order, for copying; loads the pages it spans that are not loaded yet.LoadPageAsync(Int32, CancellationToken)Loads (once) a page's selectable text: its display list, hit-test index and reading order.Move(SelectionMove, Boolean)Moves the caret (the focus) by a keyboard step; with extend (Shift held) the anchor stays.Select(TextPosition, TextPosition)Selects between two carets.SelectAll()Selects every page's text.TryGetPage(Int32, out SelectableText?)Gets a page's selectable text when it is loaded.ChangedRaised whenever the anchor or focus changes, so the shell redraws the selection.