Use Case
- Professional UX - Selection doesn’t disappear when using toolbars
- Seamless editing - Apply multiple formats without reselecting
- User expectations - Matches desktop word processor behavior
Integration
Addtoolbar-button class to toolbar elements. Call restorePreservedSelection() before applying commands.
Commands
restorePreservedSelection
Restore the preserved selection
Used internally to maintain selection when interacting with toolbar
Function Command function
setLinkedStyle
Apply a linked style to the selected paragraphs
Works with custom selection preservation
The style object to apply
toggleLinkedStyle
Toggle a linked style on the current selection
Removes style if already applied, applies it if not
The linked style to apply (with id property)
Node type to restrict toggle to (e.g., ‘paragraph’)
setStyleById
Apply a linked style by its ID
Looks up the style from loaded Word styles
The style ID to apply (e.g., ‘Heading1’)
Helpers
getStyles
Get all available linked styles
Example:
Array of linked style objects
getStyleById
Get a specific style by ID
Example:
The style ID to find
The style object or undefined

