Skip to content

API reference / Common / Engine types / TextSelection

Type Alias: TextSelection ​

ts
type TextSelection = 
  | {
  range: {
     story: TextStoryId;
     anchor: TextStoryOffset;
     focus: TextStoryOffset;
  };
}
  | {
  table: {
     story: TextStoryId;
     offset: TextStoryOffset;
     table: TableSelection;
  };
}
  | {
  drawing: {
     story: TextStoryId;
     offset: TextStoryOffset;
     shape: ShapeSelection;
  };
};

What is selected within one text story — the characters of the story itself, or what is picked inside a block embedded in it.

The two descents are the text model's two embedding points, TextTable (w:tbl, a block) and TextDrawing (w:drawing, a span), each named for the slot it descends through — the same name the command and operation arms at that slot take, so all four values agree about what is there. A paragraph grows no variant: its content lives in this story's own offset space, which the leaf already covers.

Leaf or descent, never both: a selection answers "what is selected", and a caret inside a cell does not also select the table's slot in the story above it. That is where this parts company with TextHit, which keeps its outer offset beside its descent because a hit is a path and the gesture picks which level of it to act on.

Every arm names the story, because every arm is a selection in that story — the leaf through the offsets it counts there, a descent through the slot the block occupies there. The nested selection names its own root (a [TableSelection] its table, a [ShapeSelection] the node it picked), so nothing below is repeated; what a descent adds beyond it is where in this story the block sits, which nothing below can say. See Selection.