Skip to content

Commit

Permalink
purrhaps this will build
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicoptima committed Oct 2, 2023
1 parent 2c3c45d commit 1a2c1e2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
11 changes: 11 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,10 @@ export default class LoomPlugin extends Plugin {
const cursor = editor.getCursor();

// if this note has no state, initialize it and return
// @ts-ignore `Object is possibly 'null'` only in github actions
if (!this.state[view.file.path]) {
const [current, node] = this.newNode(editor.getValue(), null);
// @ts-ignore
this.state[view.file.path] = {
current,
hoisted: [] as string[],
Expand All @@ -609,12 +611,14 @@ export default class LoomPlugin extends Plugin {
return;
}

// @ts-ignore
const current = this.state[view.file.path].current;

// `ancestors`: starts with the root node, ends with the parent of the current node
let ancestors: string[] = [];
let node: string | null = current;
while (node) {
// @ts-ignore
node = this.state[view.file.path].nodes[node].parentId;
if (node) ancestors.push(node);
}
Expand All @@ -623,11 +627,13 @@ export default class LoomPlugin extends Plugin {
// `ancestorTexts`: the text of each node in `ancestors`
const text = editor.getValue();
const ancestorTexts = ancestors.map(
// @ts-ignore
(id) => this.state[view.file.path].nodes[id].text
);

// `familyTexts`: `ancestorTexts` + the current node's text
const familyTexts = ancestorTexts.concat(
// @ts-ignore
this.state[view.file.path].nodes[current].text
);

Expand All @@ -640,12 +646,14 @@ export default class LoomPlugin extends Plugin {
let newText = text.substring(prefix.length);
newText = newText.substring(0, newText.length - suffix.length);

// @ts-ignore
this.state[view.file.path].nodes[ancestors[i]].text = newText;
};

const updateDecorations = () => {
const ancestorLengths = ancestors.map((id) => [
id,
// @ts-ignore
this.state[view.file.path].nodes[id].text.length,
]);
plugin.state = { ...plugin.state, ancestorLengths };
Expand All @@ -660,6 +668,7 @@ export default class LoomPlugin extends Plugin {
return;
}
}
// @ts-ignore
this.state[view.file.path].nodes[current].text = text.slice(
ancestorTexts.join("").length
);
Expand Down Expand Up @@ -1070,6 +1079,7 @@ export default class LoomPlugin extends Plugin {
this.app.workspace.iterateRootLeaves((leaf) => {
if (
leaf.view instanceof MarkdownView &&
// @ts-ignore
leaf.view.file.path === file.path
)
this.editor = leaf.view.editor;
Expand Down Expand Up @@ -1132,6 +1142,7 @@ export default class LoomPlugin extends Plugin {
this.app.workspace.iterateRootLeaves((leaf) => {
if (
leaf.view instanceof MarkdownView &&
// @ts-ignore
leaf.view.file.path === file.path
)
this.editor = leaf.view.editor;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "loom",
"name": "Loom",
"version": "1.16.3",
"version": "1.16.4",
"minAppVersion": "0.15.0",
"description": "Loom in Obsidian",
"author": "celeste",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-loom",
"version": "1.16.3",
"version": "1.16.4",
"description": "Loom in Obsidian",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 1a2c1e2

Please sign in to comment.