From f1f18e5e4cabcb9459987e1e60a1382a3064dab5 Mon Sep 17 00:00:00 2001 From: celeste Date: Sun, 26 Mar 2023 01:49:52 -0700 Subject: [PATCH] . --- main.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.ts b/main.ts index 556b458..3f79318 100644 --- a/main.ts +++ b/main.ts @@ -798,6 +798,29 @@ export default class LoomPlugin extends Plugin { if (!this.state[file.path]) { this.initializeFile(file); } + + // @ts-expect-error + const editorView = this.editor.cm; + const plugin = editorView.plugin(loomEditorPlugin); + + const state = this.state[file.path]; + + let ancestors: string[] = []; + let node: string | null = state.current; + while (node) { + node = this.state[file.path].nodes[node].parentId; + if (node) ancestors.push(node); + } + ancestors = ancestors.reverse(); + + const ancestorTexts = ancestors.map((id) => state.nodes[id].text); + + const lines = ancestorTexts.join("").split("\n"); + plugin.state = { + breakLine: lines.length - 1, + breakCh: lines.length > 0 ? lines[lines.length - 1].length : 0, + }; + plugin.update(); }) );