fix: insert mail template at caret in replies instead of prepending #539
This commit is contained in:
@@ -1143,7 +1143,30 @@ export function EmailComposer({
|
||||
setShowBcc(true);
|
||||
}
|
||||
} else {
|
||||
setBody((prev) => bodyContent + (plainTextMode ? '\n' : '') + prev);
|
||||
// Reply/forward: insert the template at the caret so it lands after any
|
||||
// text the user has already typed, instead of always prepending it (#539).
|
||||
if (plainTextMode) {
|
||||
const textarea = bodyRef.current;
|
||||
if (textarea) {
|
||||
const start = textarea.selectionStart ?? textarea.value.length;
|
||||
const end = textarea.selectionEnd ?? start;
|
||||
setBody((prev) => prev.slice(0, start) + bodyContent + prev.slice(end));
|
||||
// Restore the caret just past the inserted text once React re-renders.
|
||||
requestAnimationFrame(() => {
|
||||
const caret = start + bodyContent.length;
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(caret, caret);
|
||||
});
|
||||
} else {
|
||||
setBody((prev) => bodyContent + '\n' + prev);
|
||||
}
|
||||
} else if (editorRef.current) {
|
||||
// insertContent lands at the editor's current selection; onUpdate
|
||||
// propagates the resulting HTML back through onChange → setBody.
|
||||
editorRef.current.chain().focus().insertContent(bodyContent).run();
|
||||
} else {
|
||||
setBody((prev) => bodyContent + prev);
|
||||
}
|
||||
}
|
||||
|
||||
if (template.identityId) {
|
||||
|
||||
Reference in New Issue
Block a user