mirror of
https://github.com/cosmicoptima/loom.git
synced 2026-07-22 07:40:25 +00:00
add root node upon switching files
This commit is contained in:
parent
30021893fc
commit
52de4c6482
1 changed files with 27 additions and 0 deletions
27
main.ts
27
main.ts
|
|
@ -7,6 +7,7 @@ import {
|
|||
Plugin,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
TFile,
|
||||
WorkspaceLeaf,
|
||||
setIcon,
|
||||
} from "obsidian";
|
||||
|
|
@ -507,6 +508,10 @@ export default class LoomPlugin extends Plugin {
|
|||
)
|
||||
this.editor = leaf.view.editor;
|
||||
});
|
||||
|
||||
if (!this.state[file.path]) {
|
||||
this.initializeFile(file);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -546,6 +551,28 @@ export default class LoomPlugin extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
initializeFile(file: TFile) {
|
||||
// coerce to NoteState because `current` will be defined
|
||||
this.state[file.path] = {
|
||||
hoisted: [] as string[],
|
||||
nodes: {},
|
||||
} as NoteState;
|
||||
|
||||
const text = this.editor.getValue();
|
||||
|
||||
const id = uuidv4();
|
||||
this.state[file.path].nodes[id] = {
|
||||
text,
|
||||
parentId: null,
|
||||
unread: false,
|
||||
collapsed: false,
|
||||
};
|
||||
this.state[file.path].current = id;
|
||||
|
||||
this.save();
|
||||
this.view.render();
|
||||
}
|
||||
|
||||
async complete(model: string, maxTokens: number, n: number) {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!file) return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue