Bugfixes
This commit is contained in:
@@ -33,18 +33,6 @@ export default function RichTextEditor({
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleVisualChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const plainText = e.target.value;
|
||||
// Convert plain text to basic HTML paragraphs
|
||||
const htmlContent = plainText
|
||||
.split('\n\n')
|
||||
.filter(paragraph => paragraph.trim())
|
||||
.map(paragraph => `<p>${paragraph.replace(/\n/g, '<br>')}</p>`)
|
||||
.join('\n');
|
||||
|
||||
onChange(htmlContent);
|
||||
setHtmlValue(htmlContent);
|
||||
};
|
||||
|
||||
const handleVisualContentChange = () => {
|
||||
const div = visualDivRef.current;
|
||||
@@ -198,16 +186,20 @@ export default function RichTextEditor({
|
||||
|
||||
// Split plain text into paragraphs and insert as HTML
|
||||
const paragraphs = plainText.split('\n\n').filter(p => p.trim());
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
paragraphs.forEach((paragraph, index) => {
|
||||
if (index > 0) {
|
||||
// Add some spacing between paragraphs
|
||||
range.insertNode(document.createElement('br'));
|
||||
fragment.appendChild(document.createElement('br'));
|
||||
}
|
||||
const p = document.createElement('p');
|
||||
p.textContent = paragraph.replace(/\n/g, ' ');
|
||||
range.insertNode(p);
|
||||
fragment.appendChild(p);
|
||||
});
|
||||
|
||||
range.insertNode(fragment);
|
||||
|
||||
range.collapse(false);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
|
||||
Reference in New Issue
Block a user