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
1 change: 0 additions & 1 deletion apps/roam/src/components/canvas/Clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ const ClipboardPageSection = ({
},
};
editor.createShape<DiscourseNodeShape>(shape);
editor.setCurrentTool("select");
},
[editor, extensionAPI, showNodesOnCanvas],
);
Expand Down
26 changes: 20 additions & 6 deletions apps/roam/src/components/canvas/DiscourseNodeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const createNodeShapeTools = (
return class DiscourseNodeTool extends StateNode {
static id = n.type;
static initial = "idle";
static isLockable = true;
shapeType = n.type;

override onEnter = () => {
Expand All @@ -130,7 +131,6 @@ export const createNodeShapeTools = (
props: { fontFamily: "sans", size: "s" },
});
this.editor.setEditingShape(shapeId);
this.editor.setCurrentTool("select");
};
};
});
Expand Down Expand Up @@ -519,6 +519,19 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
this.updateProps(shape.id, shape.type, { h, w, imageUrl });
};

const wasToolLocked = this.editor.getInstanceState().isToolLocked;

const restoreToolState = () => {
if (wasToolLocked) {
this.editor.updateInstanceState({ isToolLocked: true });
this.editor.setCurrentTool(shape.type);
} else {
this.editor.setCurrentTool("select");
}
editor.setEditingShape(null);
dialogRenderedRef.current = false;
};

renderModifyNodeDialog({
mode: isCreating ? "create" : "edit",
nodeType: shape.type,
Expand Down Expand Up @@ -570,13 +583,14 @@ export class BaseDiscourseNodeUtil extends BaseBoxShapeUtil<DiscourseNodeShape>
});
}
}

editor.setEditingShape(null);
dialogRenderedRef.current = false;
},
onClose: () => {
editor.setEditingShape(null);
dialogRenderedRef.current = false;
if (isCreating) {
restoreToolState();
} else {
editor.setEditingShape(null);
dialogRenderedRef.current = false;
}
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const createAllReferencedNodeTools = (
class ReferencedNodeTool extends StateNode {
static override initial = "idle";
static override id = action;
static override isLockable = true;
static override children = (): TLStateNodeConstructor[] => [
this.Idle,
this.Pointing,
Expand Down Expand Up @@ -277,10 +278,6 @@ export const createAllReferencedNodeTools = (
this.editor.setCursor({ type: "cross" });
};

override onCancel = () => {
this.editor.setCurrentTool("select");
};

override onKeyUp: TLEventHandlers["onKeyUp"] = (info) => {
if (info.key === "Enter") {
if (this.editor.getInstanceState().isReadonly) return null;
Expand Down Expand Up @@ -315,6 +312,7 @@ export const createAllRelationShapeTools = (
class RelationShapeTool extends StateNode {
static override initial = "idle";
static override id = name;
static override isLockable = true;
static override children = (): TLStateNodeConstructor[] => [
this.Idle,
this.Pointing,
Expand Down Expand Up @@ -573,10 +571,6 @@ export const createAllRelationShapeTools = (
this.editor.setCursor({ type: "cross", rotation: 0 });
};

override onCancel = () => {
this.editor.setCurrentTool("select");
};

override onKeyUp: TLEventHandlers["onKeyUp"] = (info) => {
if (info.key === "Enter") {
if (this.editor.getInstanceState().isReadonly) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ export class BaseDiscourseRelationUtil extends ShapeUtil<DiscourseRelationShape>
static override props = arrowShapeProps;

cancelAndWarn = (title: string) => {
this.editor.setCurrentTool("select");
dispatchToastEvent({
id: `tldraw-cancel-and-warn-${title}`,
title,
Expand Down
1 change: 0 additions & 1 deletion apps/roam/src/components/canvas/DiscourseToolPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ const DiscourseGraphPanel = ({
props: { fontFamily: "sans", size: "s" },
});
editor.setEditingShape(shapeId);
editor.setCurrentTool("select");
} else {
// For relations, just activate the tool
editor.setCurrentTool(current.item.id);
Expand Down
1 change: 1 addition & 0 deletions apps/roam/src/components/canvas/Tldraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ const TldrawCanvasShared = ({
const discourseGraphTool = class DiscourseGraphTool extends StateNode {
static override id = "discourse-tool";
static override initial = "idle";
static override isLockable = true;
};
const discourseNodeTools = createNodeShapeTools(allNodes);
const discourseRelationTools = createAllRelationShapeTools(allRelationNames);
Expand Down
Loading