I use this code to set a font to the text via quilljs api:
const setFont = (font) => {
const lastRange = quill.getSelection();
quill.formatText(lastRange.index, lastRange.length, {font: font})
}
and this one to set text bold:
const setFormat = () => {
const lastRange = quill.getSelection();
if (!lastRange) return;
const currentFormats = quill.getFormat(lastRange.index, lastRange.length);
// Preserve existing font while setting bold
quill.formatText(lastRange.index, lastRange.length, {
...currentFormats, // Spread existing formats
bold: true, // Apply bold
});
};
when I bold part of the text, the previous font is gone from the start selected position to the end of the text.