Merge pull request 'fix: edit-report' (#84) from hotfix/edit-report into main

Reviewed-on: #84
This commit is contained in:
M-Gabrielly 2025-12-04 15:45:25 +00:00
commit 5c97c62a72

View File

@ -236,7 +236,20 @@ export default function EditarLaudoPage() {
useEffect(() => { useEffect(() => {
if (content && editorRef.current && !loading) { if (content && editorRef.current && !loading) {
console.log('[EditarLaudoPage] Injecting content into editor, length:', content.length); console.log('[EditarLaudoPage] Injecting content into editor, length:', content.length);
editorRef.current.innerHTML = content; // Só injetar se o conteúdo do editor estiver vazio ou muito diferente
const currentContent = editorRef.current.innerHTML;
if (!currentContent || currentContent.length === 0) {
editorRef.current.innerHTML = content;
// Mover cursor para o final
const range = document.createRange();
const sel = window.getSelection();
if (editorRef.current.childNodes.length > 0) {
range.selectNodeContents(editorRef.current);
range.collapse(false); // false = colapsar no final
sel?.removeAllRanges();
sel?.addRange(range);
}
}
} }
}, [content, loading]); }, [content, loading]);
@ -584,7 +597,10 @@ export default function EditarLaudoPage() {
<div <div
ref={editorRef} ref={editorRef}
contentEditable contentEditable
onInput={(e) => setContent(e.currentTarget.innerHTML)} onInput={(e) => {
// Capturar conteúdo sem perder posição do cursor
setContent(e.currentTarget.innerHTML);
}}
onPaste={(e) => { onPaste={(e) => {
e.preventDefault(); e.preventDefault();
const text = e.clipboardData.getData('text/plain'); const text = e.clipboardData.getData('text/plain');