Skip to content
Merged
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
14 changes: 14 additions & 0 deletions apps/roam/src/components/canvas/Tldraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import { TLDRAW_DATA_ATTRIBUTE } from "./tldrawStyles";
import { AUTO_CANVAS_RELATIONS_KEY } from "~/data/userSettings";
import { getSetting } from "~/utils/extensionSettings";
import { isPluginTimerReady, waitForPluginTimer } from "~/utils/pluginTimer";
import { HistoryEntry } from "@tldraw/store";
import { TLRecord } from "@tldraw/tlschema";

declare global {
interface Window {
Expand All @@ -100,12 +102,14 @@ export type DiscourseContextType = {
// { [Relation.Label] => DiscourseRelation[] }
relations: Record<string, DiscourseRelation[]>;
lastAppEvent: string;
lastActions: HistoryEntry<TLRecord>[];
};

export const discourseContext: DiscourseContextType = {
nodes: {},
relations: {},
lastAppEvent: "",
lastActions: [],
};

const DEFAULT_WIDTH = 160;
Expand All @@ -121,6 +125,9 @@ const TldrawCanvas = ({ title }: { title: string }) => {
const appRef = useRef<TldrawApp | null>(null);
const lastInsertRef = useRef<VecModel>();
const containerRef = useRef<HTMLDivElement>(null);
const lastActionsRef = useRef<HistoryEntry<TLRecord>[]>(
discourseContext.lastActions,
);

const [maximized, setMaximized] = useState(false);
const [isConvertToDialogOpen, setConvertToDialogOpen] = useState(false);
Expand Down Expand Up @@ -499,6 +506,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
type: "Tldraw Error",
context: {
title: title,
lastActions: lastActionsRef.current,
},
}).catch(() => {});

Expand Down Expand Up @@ -600,6 +608,12 @@ const TldrawCanvas = ({ title }: { title: string }) => {

appRef.current = app;

app.on("change", (entry) => {
lastActionsRef.current.push(entry);
if (lastActionsRef.current.length > 10)
lastActionsRef.current.shift();
});

app.on("event", (event) => {
const e = event as TLPointerEventInfo;

Expand Down