Skip to content

CanvasView

Unofficial

View for displaying and editing canvas files, extending obsidian#TextFileView.

Import:

import type { CanvasView } from '@obsidian-typings/obsidian-catalyst-latest';

Signature:

export interface CanvasView extends TextFileView

Extends: TextFileView

Constructor

new CanvasView(leaf: WorkspaceLeaf, canvasPluginInstance: CanvasPluginInstance)

Constructor.

Properties

Property Type Description
allowNoFile boolean Whether the view may be run without an attached file..
(Inherited from TextFileView)
canvas CanvasViewCanvas The canvas controller instance managing nodes, edges, and rendering.
data string In-memory data.
(Inherited from TextFileView)
dirty boolean Whether current file is dirty (different from saved contents).
(Inherited from TextFileView)
file null | TFile The file that is currently being viewed.
(Inherited from TextFileView)
fileBeingRenamed null | TFile The file that is currently being renamed.
(Inherited from TextFileView)
hoverPopover HoverPopover | null Hover popover associated with this view, or null if none is active.
isPlaintext boolean Whether editor should be rendered as plaintext.
(Inherited from TextFileView)
lastSavedData null | string The data that was last saved.
(Inherited from TextFileView)
navigation boolean Whether the file view can be navigated.
(Inherited from TextFileView)
plugin CanvasPluginInstance Reference to the canvas plugin instance.
requestSave () => void Debounced save in 2 seconds from now
(Inherited from TextFileView)
saveAgain boolean Whether on saving, the file should be saved again (for dirtiness checks).
(Inherited from TextFileView)
saving boolean Whether the file is currently saving.
(Inherited from TextFileView)

Methods

Method Returns Description
canAcceptExtension(extension) boolean Whether the file view can accept an extension.
(Inherited from TextFileView)
clear() void Clear the editor. This is usually called when we're about to open a completely different file, so it's best to clear any editor states like undo-redo history, and any caches/indexes associated with the previous file contents.
(Inherited from TextFileView)
getDisplayText() string Get the display text for the file view.
(Inherited from TextFileView)
getLocalData() unknown Loads the local data of the canvas.
getState() Record<string, unknown> Get the state of the file view.
(Inherited from TextFileView)
getSyncViewState() unknown Get view state for sync plugin.
(Inherited from TextFileView)
getViewData() string Gets the data from the editor. This will be called to save the editor contents to the file.
(Inherited from TextFileView)
getViewType() typeof ViewType.Canvas Get the current view type.
loadFile(file) Promise<unknown> Loads the file with the onLoadFile function.
(Inherited from TextFileView)
loadFileInternal(file, clear) Promise<unknown> Load a file into the editor, optionally clearing existing content.
(Inherited from TextFileView)
onDelete(file) Promise<void> Updates the view if it contains the deleted file.
(Inherited from TextFileView)
onload() void Called when the file view is loaded.
(Inherited from TextFileView)
onLoadFile(file) Promise<void> On load file.
(Inherited from TextFileView)
onModify(file) void Is called when the vault has a 'modify' event. Reloads the file if the view is currently not saving the file and the modified file is the file in this view.
(Inherited from TextFileView)
onRename(file) Promise<void> Called when the file is renamed.
(Inherited from TextFileView)
onTitleBlur() Promise<void> Is called when the titleEl looses focus.

Event type: 'blur'.
(Inherited from TextFileView)
onTitleChange(titleEl) void Is called when the titleEl is changed.

Event type: 'input'.
(Inherited from TextFileView)
onTitleFocus() void Is called when the titleEl gains focus.

Event type: 'focus'.
(Inherited from TextFileView)
onTitleKeydown(event) void Is called when the titleEl is focused and a keydown is triggered.

Event type: 'keydown'.
(Inherited from TextFileView)
onTitlePaste(titleEl, event) void Is called when the titleEl is focused and a paste event is triggered.

Event type: 'paste'.
(Inherited from TextFileView)
onUnloadFile(file) Promise<void> On unload file.
(Inherited from TextFileView)
receiveSyncState(view) void Receives sync state from another file view, opening the other view's file if it differs.
(Inherited from TextFileView)
renderBreadcrumbs() void Render the breadcrumb navigation for this file view.
(Inherited from TextFileView)
save(clear?) Promise<void> Save the file.
(Inherited from TextFileView)
saveImmediately() void If any changes(dirty = true) in the file forces the file to save.
(Inherited from TextFileView)
saveLocalData() void Saves the local data of the canvas.
saveTitle(titleEl) Promise<void> Updates the file to match the updated title.
(Inherited from TextFileView)
setData(data, clear) void Set the data to the editor. This is used to load the file contents.
(Inherited from TextFileView)
setState(state, result) Promise<void> Set the state of the file view.
(Inherited from TextFileView)
setViewData(data, clear) void Set the data to the editor. This is used to load the file contents.

If clear is set, then it means we're opening a completely different file. In that case, you should call TextFileView.clear(), or implement a slightly more efficient clearing mechanism given the new data to be set.
(Inherited from TextFileView)
syncState(e) Promise<unknown> Synchronize the view state with the sync plugin.
(Inherited from TextFileView)

Links to this page: