Skip to content

API reference / Common / Engine types / TextCommand

Type Alias: TextCommand ​

ts
type TextCommand = 
  | {
  replaceText: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     fragment: TextFragment;
  };
}
  | {
  pasteText: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     fragment: TextFragment;
  };
}
  | {
  setCharacterProperties: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     properties: TextCharacterProperties;
  };
}
  | {
  clearCharacterProperties: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     keys: TextCharacterPropertyKey[];
  };
}
  | {
  setParagraphProperties: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     properties: TextParagraphProperties;
  };
}
  | {
  clearParagraphProperties: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     keys: TextParagraphPropertyKey[];
  };
}
  | {
  indentParagraphs: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     delta: number;
  };
}
  | {
  wrapBlocks: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     markup: Markup;
  };
}
  | {
  wrapSpans: {
     range: {
        start: TextStoryOffset;
        end: TextStoryOffset;
     };
     markup: Markup;
  };
}
  | {
  unwrap: {
     id: RawId;
  };
}
  | {
  editTable: {
     offset: TextStoryOffset;
     command: TableCommand;
  };
}
  | {
  editDrawing: {
     offset: TextStoryOffset;
     command: TextDrawingCommand;
  };
};

An edit intent for a text story. The embedding doc type's editor turns one into LoroText writes (via execute) over the story's container; it never touches the model directly.

Serialize/Deserialize make a command a stable wire form — externally tagged by variant name — so a host can issue an edit as JSON. Mirrors the engine facet's TextOperation, which the diff decodes these back into.