Keep text selection visible when clicking toolbar buttons.
Select text and click the toolbar: your selection stays highlighted.
Use case
- Professional UX - Selection doesnβt disappear when using toolbars
- Multi-format editing - Apply multiple formats without reselecting
- User expectations - Matches desktop word processor behavior
Integration
Add toolbar-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
Example:
// Restore selection after toolbar interaction
editor.commands.restorePreservedSelection()
import { SuperDoc } from 'superdoc';
import 'superdoc/style.css';
const superdoc = new SuperDoc({
selector: '#editor',
document: yourFile,
onReady: (superdoc) => {
const editor = superdoc.activeEditor;
// Restore selection after toolbar interaction
editor.commands.restorePreservedSelection()
},
});
Returns: Function Command function
SelectionState
Selection state
Whether editor is focused
Whether to show selection decoration
Whether to skip clearing selection on next focus
Source code