Skip to content

Commit 07bf56a

Browse files
trangdoan982claude
andauthored
ENG-1508: Open canvas as TldrawView immediately after creation (#892)
When a new canvas file is created, metadataCache.getFileCache() returns null in the file-open handler because the cache hasn't indexed the new file yet. This caused the file path to never be added to pendingCanvasSwitches, so the active-leaf-change handler never switched to TldrawView — leaving the user staring at raw JSON markdown. Fix: directly call leaf.setViewState with VIEW_TYPE_TLDRAW_DG_PREVIEW after openFile in createCanvas(), bypassing the event-based mechanism for the creation case. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8cc5189 commit 07bf56a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • apps/obsidian/src/components/canvas/utils

apps/obsidian/src/components/canvas/utils/tldraw.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
TLDATA_DELIMITER_END,
1515
TLDATA_DELIMITER_START,
1616
TLDRAW_VERSION,
17+
VIEW_TYPE_TLDRAW_DG_PREVIEW,
1718
} from "~/constants";
1819
import DiscourseGraphPlugin from "~/index";
1920
import { checkAndCreateFolder, getNewUniqueFilepath } from "~/utils/file";
@@ -178,8 +179,7 @@ export const createCanvas = async (plugin: DiscourseGraphPlugin) => {
178179
try {
179180
const filename = `Canvas-${format(new Date(), "yyyy-MM-dd-HHmm")}`;
180181
const folderpath = plugin.settings.canvasFolderPath;
181-
const attachmentsFolder =
182-
plugin.settings.canvasAttachmentsFolderPath;
182+
const attachmentsFolder = plugin.settings.canvasAttachmentsFolderPath;
183183

184184
await checkAndCreateFolder(folderpath, plugin.app.vault);
185185
await checkAndCreateFolder(attachmentsFolder, plugin.app.vault);
@@ -193,6 +193,10 @@ export const createCanvas = async (plugin: DiscourseGraphPlugin) => {
193193
const file = await plugin.app.vault.create(fname, content);
194194
const leaf = plugin.app.workspace.getLeaf(false);
195195
await leaf.openFile(file);
196+
await leaf.setViewState({
197+
type: VIEW_TYPE_TLDRAW_DG_PREVIEW,
198+
state: { file: file.path },
199+
});
196200

197201
return file;
198202
} catch (e) {

0 commit comments

Comments
 (0)