chhoumann / MetaEdit

MetaEdit for Obsidian
https://bagerbach.com
GNU General Public License v3.0
393 stars 15 forks source link

Latest release broken on Obsidian Mobile #99

Open jloh opened 11 months ago

jloh commented 11 months ago

Thanks for MetaEdit! I use it a lot in scripts and other places through QuickAdd and its fantastic.

The latest round of updates to fix the plugin with 1.4.x have unfortunately broken MetaEdit on mobile for me with an error only saying:

right side of assignment cannot be destructed

Any hints on how I can help to debug this at all?

I'm running Obsidian's TestFlight edition on iOS which is according to the about page 1.4.7 (106) API version v.1.3.7.

Reverting back to MetaEdit 1.8.0 fixes the problem for me but this means its broken on desktop.

xt0rted commented 10 months ago

I ran into this issue after setting up a number of buttons to edit my metadata more easily on mobile. For the time being I patched this in my local version. If you open .obsidian\plugins\metaedit\main.js and search for frontmatterPosition you can try to manually apply the fix in #100 which should look something like this (also has a fix to remove the trailing blank line that's showing up for me):

diff --git a/main.js b/main.js
index 45766ac..731fad5 100644
--- a/main.js
+++ b/main.js
@@ -4407,7 +4407,7 @@ class MetaEditParser {
         if (!frontmatter)
             return [];
         //@ts-ignore - this is part of the new Obsidian API as of v1.4.1
-        const { start, end } = fileCache === null || fileCache === void 0 ? void 0 : fileCache.frontmatterPosition;
+        const { start, end } = fileCache === null || fileCache === void 0 ? void 0 : fileCache.frontmatterPosition ?? fileCache.frontmatter.position;
         const filecontent = await this.app.vault.cachedRead(file);
         const yamlContent = filecontent.split("\n").slice(start.line, end.line).join("\n");
         const parsedYaml = obsidian.parseYaml(yamlContent);
@@ -4927,10 +4927,12 @@ class MetaController {
     async updatePropertyInFile(property, newValue, file) {
         // I'm aware this is hacky. Didn't want to spend a bunch of time rewriting old logic.
         // This uses the new frontmatter API to update the frontmatter. Later TODO: rewrite old logic to just do this & clean.
-        if (property.type === MetaType.YAML) {
-            const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}\n---`;
-            //@ts-ignore
-            const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition;
+        //@ts-ignore
+        const frontmatterPosition = this.app.metadataCache.getFileCache(file).frontmatterPosition;
+
+        if (property.type === MetaType.YAML && frontmatterPosition) {
+            const updatedMetaData = `---\n${this.updateYamlProperty(property, newValue, file)}---`;
+
             const fileContents = await this.app.vault.read(file);
             const deleteFrom = frontmatterPosition.start.offset;
             const deleteTo = frontmatterPosition.end.offset;