fix: keep text typed under the signature when the signature is swapped or removed

This commit is contained in:
Linus Rath
2026-10-15 00:02:13 +02:00
parent cce6ebd324
commit 142ef5daf4
2 changed files with 21 additions and 1 deletions
@@ -117,6 +117,17 @@ describe('switching identity swaps the signature', () => {
.toBe(dom(`<p>Hi</p>${embed(other)}<blockquote>original</blockquote>`));
});
it('keeps text typed on the line under the signature', () => {
const typedBelow = embed(identity).replace(
`<p ${SIGNATURE_RANGE_MARKER}="end"></p>`,
`<p ${SIGNATURE_RANGE_MARKER}="end">P.S. see you</p>`,
);
expect(replaceEmbeddedSignature(`<p>Hi</p>${typedBelow}`, embed(none)))
.toBe('<p>Hi</p><p>P.S. see you</p>');
expect(replaceEmbeddedSignature(`<p>Hi</p>${typedBelow}`, embed(other)))
.toBe(dom(`<p>Hi</p>${embed(other)}<p>P.S. see you</p>`));
});
it('adds a signature at the end when there is no quote', () => {
expect(replaceEmbeddedSignature('<p>Hi</p>', embed(other))).toBe(dom(`<p>Hi</p>${embed(other)}`));
});
+10 -1
View File
@@ -89,8 +89,17 @@ export function removeSignatureRange(
if (!removeUntil && isQuoteBoundary(next)) break;
cursor = next;
}
const insertBefore = toRemove[toRemove.length - 1]?.nextSibling ?? null;
let insertBefore = toRemove[toRemove.length - 1]?.nextSibling ?? null;
toRemove.forEach((node) => parent.removeChild(node));
// The end marker is the empty line under the signature, so a click below
// the signature puts the caret there. Text typed into it is the user's,
// not part of the signature: keep it as an ordinary paragraph after it.
if (removeUntil && removeUntil.textContent?.trim()) {
const kept = removeUntil.cloneNode(true) as Element;
kept.removeAttribute(SIGNATURE_RANGE_MARKER);
parent.insertBefore(kept, insertBefore);
insertBefore = kept;
}
return { parent, insertBefore };
}