Skip to content

Build your personal knowledge base with Trilium Notes

fix(text): let interactive embeds in include notes receive native events

Elian Doran763188de806d
diff --git a/packages/ckeditor5/src/plugins/includenote.spec.ts b/packages/ckeditor5/src/plugins/includenote.spec.ts
index 2089711d03..36c7c4fd11 100644
--- a/packages/ckeditor5/src/plugins/includenote.spec.ts
+++ b/packages/ckeditor5/src/plugins/includenote.spec.ts
@@ -306,16 +306,45 @@ describe("IncludeNote", () => {
wrapper.dispatchEvent(plainEvt);
expect(plainPrevent).toHaveBeenCalled();
- // Clicking a link must keep native behaviour, so preventDefault must NOT be called (the
- // capture-phase handler on the wrapper still sees the event via its child target).
+ // Clicking a link must keep native behaviour: the handler steps aside entirely, so neither
+ // preventDefault nor stopPropagation is called.
const innerLink = document.createElement("a");
innerLink.href = "#root/abc";
wrapper.appendChild(innerLink);
const linkEvt = new MouseEvent("mousedown", { bubbles: true, cancelable: true });
const linkPrevent = vi.spyOn(linkEvt, "preventDefault");
+ const linkStop = vi.spyOn(linkEvt, "stopPropagation");
innerLink.dispatchEvent(linkEvt);
expect(linkPrevent).not.toHaveBeenCalled();
+ expect(linkStop).not.toHaveBeenCalled();
+ });
+
+ it("leaves a mousedown inside an embedded collection untouched so the live widget keeps working", () => {
+ insertIncludeNote(editor, "noteColl", "full");
+
+ const domRoot = editor.editing.view.getDomRoot();
+ const wrapper = domRoot?.querySelector("div.include-note-wrapper");
+ expect(wrapper).not.toBeNull();
+ if (!wrapper) {
+ return;
+ }
+
+ // Simulate the embedded collection markup (e.g. a geo-map marker lives under .rendered-collection).
+ const collection = document.createElement("div");
+ collection.className = "rendered-collection";
+ const marker = document.createElement("div");
+ collection.appendChild(marker);
+ wrapper.appendChild(collection);
+
+ const evt = new MouseEvent("mousedown", { bubbles: true, cancelable: true });
+ const prevent = vi.spyOn(evt, "preventDefault");
+ const stop = vi.spyOn(evt, "stopPropagation");
+ marker.dispatchEvent(evt);
+
+ // The handler must step aside completely so Leaflet (and other live widgets) get the event.
+ expect(prevent).not.toHaveBeenCalled();
+ expect(stop).not.toHaveBeenCalled();
});
it("stops propagation on focus and keydown inside the wrapper", () => {
diff --git a/packages/ckeditor5/src/plugins/includenote.ts b/packages/ckeditor5/src/plugins/includenote.ts
index abfb0493e1..e54acf7374 100644
--- a/packages/ckeditor5/src/plugins/includenote.ts
+++ b/packages/ckeditor5/src/plugins/includenote.ts
@@ -263,20 +263,25 @@ function preventCKEditorHandling( domElement: HTMLElement, editor: Editor ) {
//domElement.addEventListener( 'click', stopEventPropagationAndHackRendererFocus, { capture: true } );
domElement.addEventListener( 'mousedown', ( evt: MouseEvent ) => {
+ // Interactive embedded content — links, form controls, and live widgets such as collections
+ // (geo map, calendar, board, table) — needs the browser's native event handling to remain
+ // usable, e.g. dragging a geo-map marker relies on the mousedown reaching Leaflet. Leave those
+ // events completely alone: don't stop propagation, suppress the default, or steal selection.
+ if ( isInteractiveTarget( evt.target, domElement ) ) {
+ return;
+ }
+
evt.stopPropagation();
+
+ // Suppress the browser's native caret on non-interactive areas. The widget's <section> is
+ // contenteditable=false inside an editable root, so the default mousedown action drops a caret
+ // next to it that visibly moves as the user clicks around.
+ evt.preventDefault();
+
// This prevents rendering changed view selection thus preventing to changing DOM selection while inside a widget.
//@ts-expect-error: We are accessing a private field.
editor.editing.view._renderer.isFocused = false;
- // Suppress the browser's native caret for clicks on non-interactive areas. The widget's
- // <section> is contenteditable=false inside an editable root, so the default mousedown action
- // drops a caret next to it that visibly moves as the user clicks around. Interactive targets
- // (links, buttons, form controls, embedded editables) keep their native behaviour — `click`
- // and focus still fire because preventing the default of `mousedown` does not cancel them.
- if ( !isInteractiveTarget( evt.target, domElement ) ) {
- evt.preventDefault();
- }
-
// Select the widget so the toolbar can appear
selectIncludeNoteWidget( domElement, editor );
}, { capture: true } );
@@ -295,9 +300,10 @@ function preventCKEditorHandling( domElement: HTMLElement, editor: Editor ) {
}
/**
- * Whether a mousedown target needs the browser's native handling (focus, caret placement, media
- * controls) to keep working. Used to decide when it is safe to `preventDefault()` on a widget click
- * in order to suppress the stray native caret without breaking interactive embedded content.
+ * Whether a mousedown target needs the browser's native handling to keep working — so the widget's
+ * event interception should step aside. Covers form controls, links and media (which need focus,
+ * caret or their own controls) and, crucially, live embedded widgets: web views and collection views
+ * (geo map, calendar, board, table) whose own drag/click handlers rely on the native event.
*
* The match is bounded to within `boundary` (the widget wrapper) so the editable editor root — an
* ancestor with `contenteditable="true"` — is never mistaken for an interactive target.
@@ -308,6 +314,7 @@ function isInteractiveTarget( target: EventTarget | null, boundary: HTMLElement
}
const match = target.closest(
+ '.rendered-collection, .note-detail-web-view, ' +
'a, button, input, textarea, select, label, audio, video, ' +
'[role="button"], [role="textbox"], [contenteditable]:not([contenteditable="false"])'
);