Skip to content

CanvasView

Unofficial

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

Import:

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

Signature:

export interface CanvasView extends TextFileView

Extends: TextFileView

Constructor

new CanvasView(leaf: WorkspaceLeaf, canvasPluginInstance: CanvasPluginInstance)

Constructor.

Properties

PropertyTypeDescription
allowNoFilebooleanWhether the view may be run without an attached file..
(Inherited from TextFileView)
canvasCanvasViewCanvasThe canvas controller instance managing nodes, edges, and rendering.
datastringIn-memory data.
(Inherited from TextFileView)
dirtybooleanWhether current file is dirty (different from saved contents).
(Inherited from TextFileView)
filenull | TFileThe file that is currently being viewed.
(Inherited from TextFileView)
fileBeingRenamednull | TFileThe file that is currently being renamed.
(Inherited from TextFileView)
hoverPopoverHoverPopover | nullHover popover associated with this view, or null if none is active.
isPlaintextbooleanWhether editor should be rendered as plaintext.
(Inherited from TextFileView)
lastSavedDatanull | stringThe data that was last saved.
(Inherited from TextFileView)
navigationbooleanWhether the file view can be navigated.
(Inherited from TextFileView)
pluginCanvasPluginInstanceReference to the canvas plugin instance.
requestSave() => voidDebounced save in 2 seconds from now
(Inherited from TextFileView)
saveAgainbooleanWhether on saving, the file should be saved again (for dirtiness checks).
(Inherited from TextFileView)
savingbooleanWhether the file is currently saving.
(Inherited from TextFileView)

Methods

MethodReturnsDescription
canAcceptExtension(extension)booleanWhether the file view can accept an extension.
(Inherited from TextFileView)
clear()voidClear 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()stringGet the display text for the file view.
(Inherited from TextFileView)
getLocalData()unknownLoads the local data of the canvas.
getState()Record<string, unknown>Get the state of the file view.
(Inherited from TextFileView)
getSyncViewState()unknownGet view state for sync plugin.
(Inherited from TextFileView)
getViewData()stringGets the data from the editor. This will be called to save the editor contents to the file.
(Inherited from TextFileView)
getViewType()typeof ViewType.CanvasGet 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()voidCalled when the file view is loaded.
(Inherited from TextFileView)
onLoadFile(file)Promise<void>On load file.
(Inherited from TextFileView)
onModify(file)voidIs 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)voidIs called when the titleEl is changed.

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

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

Event type: 'keydown'.
(Inherited from TextFileView)
onTitlePaste(titleEl, event)voidIs 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)voidReceives sync state from another file view, opening the other view's file if it differs.
(Inherited from TextFileView)
renderBreadcrumbs()voidRender the breadcrumb navigation for this file view.
(Inherited from TextFileView)
save(clear?)Promise<void>Save the file.
(Inherited from TextFileView)
saveImmediately()voidIf any changes(dirty = true) in the file forces the file to save.
(Inherited from TextFileView)
saveLocalData()voidSaves the local data of the canvas.
saveTitle(titleEl)Promise<void>Updates the file to match the updated title.
(Inherited from TextFileView)
setData(data, clear)voidSet 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)voidSet 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: