Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion apps/roam/src/components/canvas/Tldraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,19 @@ const TldrawCanvasShared = ({
useEffect(() => {
const handleDragStart = (e: DragEvent) => {
const target = e.target as HTMLElement;
const uid = getBlockUidFromBullet(target);

const pageRef = target.closest<HTMLElement>(".rm-page-ref");
if (pageRef) {
const pageTitle = (
pageRef.getAttribute("data-tag") ||
pageRef.parentElement?.getAttribute("data-link-title")
)?.replace(/\\"/g, '"');
if (pageTitle)
e.dataTransfer?.setData("application/x-roam-page", pageTitle);
return;
}

const uid = getBlockUidFromBullet(target);
if (uid) e.dataTransfer?.setData("application/x-roam-uid", uid);
};

Expand All @@ -658,6 +669,22 @@ const TldrawCanvasShared = ({

const handleDrop = (e: React.DragEvent<HTMLDivElement>) => {
e.preventDefault();

const pageTitle = e.dataTransfer.getData("application/x-roam-page");
if (pageTitle && appRef.current && extensionAPI) {
posthog.capture("Canvas: Roam Page Dropped");
const dropPoint = appRef.current.screenToPage({
x: e.clientX,
y: e.clientY,
});
void appRef.current.putExternalContent({
type: "text",
text: `[[${pageTitle}]]`,
point: dropPoint,
});
return;
}

const uid = e.dataTransfer.getData("application/x-roam-uid");

if (!uid || !appRef.current || !extensionAPI) return;
Expand Down
10 changes: 9 additions & 1 deletion apps/roam/src/utils/initializeObserversAndListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
addPageRefObserver,
getPageRefObserversSize,
previewPageRefHandler,
makePageRefDraggable,
getOverlayHandler,
onPageRefObserverChange,
getSuggestiveOverlayHandler,
Expand Down Expand Up @@ -242,6 +243,8 @@ export const initObservers = ({
onPageRefObserverChange(overlayHandler)(true);
}

onPageRefObserverChange(makePageRefDraggable)(true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope page-ref dragging to canvas interactions

Enabling onPageRefObserverChange(makePageRefDraggable)(true) unconditionally at startup makes every .rm-page-ref in Roam draggable, not just refs involved in canvas drops. In practice this changes normal editor behavior: click-drag gestures on page refs (including in regular blocks) start HTML drag operations, which interferes with expected text selection/editing flows outside the canvas. This regression is user-facing across the app and should be gated to canvas-specific contexts or a dedicated drag handle.

Useful? React with 👍 / 👎.


if (getPageRefObserversSize()) enablePageRefObserver();

const configPageUid = getPageUidByPageTitle(DISCOURSE_CONFIG_PAGE_TITLE);
Expand Down Expand Up @@ -466,6 +469,11 @@ export const initObservers = ({
discourseNodeSearchTriggerListener,
nodeCreationPopoverListener,
},
cleanups: [unsubGlobalTrigger, unsubPersonalTrigger, unsubSearchTrigger],
cleanups: [
unsubGlobalTrigger,
unsubPersonalTrigger,
unsubSearchTrigger,
() => onPageRefObserverChange(makePageRefDraggable)(false),
],
};
};
4 changes: 4 additions & 0 deletions apps/roam/src/utils/pageRefObserverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export const previewPageRefHandler = (s: HTMLSpanElement) => {
}
};

export const makePageRefDraggable = (s: HTMLSpanElement) => {
s.draggable = true;
};

export const enablePageRefObserver = () => {
if (pageRefObserverRef.current) return pageRefObserverRef.current;

Expand Down