@bobfrankston/rmfmail 1.1.151 → 1.1.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -777,30 +777,47 @@ async function createTinyMceEditor(container2, opts = {}) {
777
777
  applyZoom();
778
778
  }
779
779
  });
780
- ed.on("keypress", (e) => {
781
- if (e.ctrlKey || e.altKey || e.metaKey)
780
+ const installLinkEscape = () => {
781
+ const doc = ed.getDoc();
782
+ if (!doc || doc.__rmfLinkEscapeInstalled)
782
783
  return;
783
- const sel = ed.selection;
784
- const rng = sel.getRng();
785
- if (!rng || !rng.collapsed)
786
- return;
787
- const a = ed.dom.getParent(sel.getNode(), "a");
788
- if (!a)
789
- return;
790
- let tail;
791
- try {
792
- tail = rng.cloneRange();
793
- tail.setEndAfter(a);
794
- } catch {
795
- return;
796
- }
797
- if (tail.toString().length > 0)
798
- return;
799
- const after = ed.getDoc().createRange();
800
- after.setStartAfter(a);
801
- after.collapse(true);
802
- sel.setRng(after);
803
- });
784
+ doc.__rmfLinkEscapeInstalled = true;
785
+ doc.addEventListener("beforeinput", (e) => {
786
+ const kind = e.inputType || "";
787
+ const isInsert = kind === "insertText" || kind === "insertCompositionText" || kind === "insertFromPaste" || kind === "insertFromDrop" || kind === "insertFromComposition";
788
+ if (!isInsert)
789
+ return;
790
+ const sel = doc.getSelection();
791
+ if (!sel || sel.rangeCount === 0)
792
+ return;
793
+ const rng = sel.getRangeAt(0);
794
+ if (!rng.collapsed)
795
+ return;
796
+ const node = rng.startContainer;
797
+ const a = node.nodeType === Node.ELEMENT_NODE ? node : node.parentNode;
798
+ if (!a)
799
+ return;
800
+ const link = a.closest?.("a");
801
+ if (!link)
802
+ return;
803
+ let tail;
804
+ try {
805
+ tail = rng.cloneRange();
806
+ tail.setEndAfter(link);
807
+ } catch {
808
+ return;
809
+ }
810
+ if (tail.toString().length > 0)
811
+ return;
812
+ const after = doc.createRange();
813
+ after.setStartAfter(link);
814
+ after.collapse(true);
815
+ sel.removeAllRanges();
816
+ sel.addRange(after);
817
+ }, true);
818
+ };
819
+ ed.on("init", installLinkEscape);
820
+ ed.on("SetContent", installLinkEscape);
804
821
  ed.on("init", () => {
805
822
  try {
806
823
  const body = ed.getBody();