Skip to Content
CommandsCommands: Text Style

Commands: Text Style

Character-level commands for font size, color, family, casing and background. Most write attributes of the textStyle mark. Setting a value to null means “inherit from the stylesheet”.

import { setFontSize, setFontColor, setFontFamily, setBackgroundColor } from "@stesura/core/commands";

Font Size

setFontSize

Set the font size in points.

setFontSize(fontSize: number): Command

incrementFontSize

Step the font size up or down the size ladder (the picker sizes, then 80pt to 140pt in 10pt steps). Text with no explicit size starts from its stylesheet size. With a bare cursor inside a word, the whole word is resized.

incrementFontSize(direction: "up" | "down"): Command

incrementFontSizeTr from @stesura/core/commands/internal is the transaction variant.

Font Color

setFontColor

Set the text color, as "#RRGGBB" or "auto" (Word’s automatic color, which flips between black and white against the background).

setFontColor(color: string): Command // setFontColor("#FF0000")

clearFontColor

Clear the color override, back to the stylesheet’s.

clearFontColor: Command

Font Family

setFontFamily

Set the font family. An empty value or null clears the override. Refused while an equation is selected.

setFontFamily(font: string | null): Command // setFontFamily("Georgia")

The built-in font list is FONT_FAMILIES from @stesura/core/constants. Text with no family set anywhere falls back to "Arimo".

Casing

setCaps

Set the casing format: Word’s all caps or small caps. The stored text doesn’t change. Only one can be active at a time. "none" is an explicit off that beats a caps-on paragraph style, while null re-inherits it. Refused while an equation is selected.

setCaps(value: "all" | "small" | "none" | null): Command

changeCase

Rewrite the selected text: Word’s Sentence case, UPPERCASE, lowercase and Capitalize Each Word. Nothing is stored, so undo is the only way back.

changeCase(mode: "sentence" | "uppercase" | "lowercase" | "capitalize"): Command
  • Needs a ranged selection, and returns false on a caret.
  • "sentence" raises the first letter of each sentence and lowers the rest. "capitalize" raises the first letter of each word and lowers the rest, so fzr-r becomes Fzr-r and Fzr-R respectively. A sentence ends at ., !, ? or followed by whitespace, and every block starts one.
  • Only the characters that differ are replaced, so comment and proofreading anchors inside the range survive.
  • Text is cased in the block’s resolved language (Turkish i becomes İ). Inline atoms such as images and equations are skipped.
  • Every mode except UPPERCASE clears all caps, which would hide the rewrite. Small caps is kept.

cycleCase

Word’s Shift+F3, which is bound to it in the default keymap. Cycles lowercase → UPPERCASE → Capitalize Each Word, reading the current case from the selected text. Sentence case is not in the cycle.

cycleCase: Command

Background Color

setBackgroundColor

Set a background color, choosing the target so the fill covers what was selected:

  • A partial selection inside one block gets a textStyle mark.
  • A caret, a whole block or a multi-block selection sets the block’s bgColor attr.
  • Inside a table, those block-level cases color the cell rather than the paragraph.

"transparent" is stored as an explicit “no fill” that overrides the stylesheet. null clears the direct value instead. Refused inside code blocks.

setBackgroundColor(color: string | null): Command

setBackgroundColorTr from @stesura/core/commands/internal is the transaction variant.

clearBackgroundColor

Clear the direct background so the stylesheet’s applies again. It drops any textStyle background in the selection, then clears the block or cell attr by the same rules as setBackgroundColor.

clearBackgroundColor(): Command

How textStyle Works

The textStyle mark aggregates several text properties:

{ color: string | null, // "#RRGGBB", "auto", or null fontSize: number | null, // points fontFamily: string | null, caps: "all" | "small" | "none" | null, bgColor: string | null, // Marks this run turns OFF against its paragraph style. Kept in a fixed // order and never `[]`; write it with `withOff` from `@stesura/core/helpers`. off: ("strong" | "em" | "underline" | "strikethrough" | "superscript" | "subscript")[] | null, }

The setters merge into the existing mark, so setFontSize(14) keeps the run’s color and family. On a range, a merge that leaves every attr null removes the mark.

Next Steps

Last updated on