alibadparva
alibadparva

Reputation: 11

Quilljs textFromat api doesn't preserve previous font format

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.

before set bold

after set bold

Upvotes: 0

Views: 24

Answers (0)

Related Questions