mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-01 16:12:02 +00:00
fix: keep text typed under the signature when the signature is swapped or removed
This commit is contained in:
@@ -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)}`));
|
||||
});
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user