Skip to content

Commit

Permalink
support opening canvas node in main window (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdroidian authored Dec 1, 2023
1 parent d753268 commit 864c343
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/components/TldrawCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import ExtensionApiContextProvider, {
useExtensionAPI,
} from "roamjs-components/components/ExtensionApiContext";
import calcCanvasNodeSizeAndImg from "../utils/calcCanvasNodeSizeAndImg";
import getPageTitleByPageUid from "roamjs-components/queries/getPageTitleByPageUid";

declare global {
interface Window {
Expand Down Expand Up @@ -1332,25 +1333,36 @@ const TldrawCanvas = ({ title }: Props) => {
// TODO - this should move to one of DiscourseNodeTool's children classes instead
app.on("event", (e) => {
discourseContext.lastAppEvent = e.name;
if (
e.shiftKey &&
e.shape &&
e.shape.props?.uid &&
e.name === "pointer_up"
) {
if (!isLiveBlock(e.shape.props.uid)) {
// TODO - it shouldn't be possible to shift click a discourse node that isn't a live block - turn into a warning instead
if (!e.shape.props.title) {
return;
}
createDiscourseNode({
newPageUid: e.shape.props.uid,
text: e.shape.props.title,
configPageUid: e.shape.type,
discourseNodes: Object.values(discourseContext.nodes),

const validModifier = e.shiftKey || e.ctrlKey;
if (!(e.name === "pointer_up" && e.shape && validModifier)) return;
if (app.selectedIds.length) return; // User is positioning selected shape

const shapeUid = e.shape?.props.uid;
if (!isLiveBlock(shapeUid)) {
if (!e.shape.props.title) return;
renderToast({
id: "tldraw-warning",
intent: "warning",
content: `Not a valid UID. Cannot Open.`,
});
}

if (e.shiftKey) {
// TODO - do not openBlockInSidebar if user is using shift to select
openBlockInSidebar(e.shape.props.uid);
}
if (e.ctrlKey) {
const isPage = !!getPageTitleByPageUid(shapeUid);
if (isPage) {
window.roamAlphaAPI.ui.mainWindow.openPage({
page: { uid: shapeUid },
});
} else {
window.roamAlphaAPI.ui.mainWindow.openBlock({
block: { uid: shapeUid },
});
}
openBlockInSidebar(e.shape.props.uid);
}
});
const oldOnBeforeDelete = app.store.onBeforeDelete;
Expand Down

0 comments on commit 864c343

Please sign in to comment.