Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function setAlignment(editor: Editor, alignment: Alignment) {
let command = DocumentCommand.JustifyLeft;
let align = 'left';
if (alignment == Alignment.Center) {
command = DocumentCommand.JustifyCenter;
align = 'center';
} else if (alignment == Alignment.Right) {
command = DocumentCommand.JustifyRight;
align = 'right';
}
editor.addUndoSnapshot(() => {
execCommand(editor, command);
editor.queryElements(
'[align]',
QueryScope.OnSelection,
node => (node.style.textAlign = align)
);
}, ChangeSource.Format);
}
handleChange: (editor) => setAlignment(editor, Alignment.Center)
},
onClick: editor => setAlignment(editor, Alignment.Center),
},
onClick: editor => setAlignment(editor, Alignment.Center),
};
document.getElementById('alignCenterButton').addEventListener('click', function() {
setAlignment(getCurrentEditor(), Alignment.Center);
});